我想 插入 一条语句.但是 有外键(大类的id),我现在只知道 大类的名称。想问问 insert怎么写?
上学时 没好好学 SQL导致就会个 select 哎~

解决方案 »

  1.   

    insert ta (id)select id from tb where name='...'
    ???
      

  2.   

    insert tableName(classID)
    select classid
    from tableClass
    where classname='类名称'
      

  3.   

    declare @id  nvarchar(20)
    select @id=id from table where name='名称'
    insert into table(id) values(@id)这是sql的,代码里也可以做类似操作
      

  4.   

    insert into 插入表名 (列名1,列名2,外健字段名)
    select 值1,值2,id from 大类表名 where name='大类名称'
      

  5.   

    insert into info (cName ,cCreateTime,cAuthor, hits,cCreateContent, tID) values ('ss','ss', 'ss', 23, 'ss',(select tID from BigClass where tName='经典讲座')) 我是这样写的 他说 在此上下文中不允许使用子查询。只允许使用标量表达式。
      

  6.   

    insert into info (cName ,cCreateTime,cAuthor, hits,cCreateContent, tID)  select 'ss','ss', 'ss', 23, 'ss',tID 
    from BigClass where tName='经典讲座' 
      

  7.   

      这个 我这么用过 insert into 表明 () values () insert语句不是这样写吗?'ss','ss', 'ss', 23, 'ss', 这些信息 不是从BigClass里差出来的
      

  8.   

    insert into info (cName ,cCreateTime,cAuthor, hits,cCreateContent, tID)
    select 'ss','ss', 'ss', 23, 'ss', tID from BigClass where tName='经典讲座' 有values 就不要用select 
    用select 就不要values 
      

  9.   

    剪嫂到处发大水,水淹net版块