user表
userid 主键 not null
username not nullschhool 表
schoolid 主键 not null
schhoolname not nullclass表
calssid 主键 not null
classname not nullmessage表
messageid 主键
userid 外键 not null
schoolid 外键 not null
classid 外键 not null
connect not null
date not null
我想在message表中插入记录,我只知道username,schoolname,classname,不知道他们的id,我该怎么插入???
userid 主键 not null
username not nullschhool 表
schoolid 主键 not null
schhoolname not nullclass表
calssid 主键 not null
classname not nullmessage表
messageid 主键
userid 外键 not null
schoolid 外键 not null
classid 外键 not null
connect not null
date not null
我想在message表中插入记录,我只知道username,schoolname,classname,不知道他们的id,我该怎么插入???
然后 再向 message表中插入数据
先select ,然后在insert??
还是在insert……values(select)?这种好像不行
select
a.userid,b.schoolid,c.classid,
connect的值,
date的值
from [user] a
join [schhool] b on b.[schhoolname]=schhoolname的值
join [class] c on c.[classname]=classname的值
where a.[username]=username的值
insert dbo.Photos(SchoolID,ClassID,connect,date)
select SchhoolID=(select SchoolID from dbo.School where SchoolName=''),
ClassID=(select ClassID from dbo.Class where ClassName=''),
connect='',date=''