--记录表
create table RecordInfo
(
recordId int primary key identity(1,1),
recordType int references DictionaryInfo(dictionaryId),
userId int references UserInfo(userId),
status bit,
recordTime datetime
)
go--集合表
create table ListInfo
(
listId int primary key identity(1,1),
recordId int references RecordInfo(recordId),
bookId int references BookInfo(bookId) ,
)上面是两张表recordId是两张表的连接条件,及外键关系,我是想用ListInfo中的listId来修改RecordInfo中的status值,不知道怎么实现,希望大家帮忙,把sql语句写一下,谢谢。

解决方案 »

  1.   

    --如果你的listId只有0和1,可以如下:
    update RecordInfo
    set status = n.listId
    from RecordInfo m , ListInfo n
    where m.recordId = n.recordId
      

  2.   

    因为你的status 其类型是bit,故要求listId只能为0和1。
      

  3.   

    update RecordInfo set status=1 where recordId in (select recordId from  ListInfo where listId=1)
      

  4.   

    不要用in,其效率不高。改用表连接。update RecordInfo set status=1 
    from RecordInfo m, ListInfo n
    where m.recordId = n.recordId and n.listId=1