多外键关联的TSQ语句怎么写,给点思路

lyk831216 2007-01-17 11:05:37
create table A
(
Aid int not null primary key,
ABid int not null
)
create table B
(
Bid int not null primary key,
Bname varchar(8) not null
)
insert into A values(1,1)
insert into A values(2,2)
insert into B values(1,网求)
insert into B values(2,晚秋)
alter table A add Constraint A_B_FK
foreign key (ABid) references B(Bid)
insert into A values(3,(select Bid from B where Bname='晚秋'))
...全文
186 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
marco08 2007-01-17
  • 打赏
  • 举报
回复
--A的結果

select * from A
--result
Aid ABid
----------- -----------
1 1
2 2
3 2

(3 row(s) affected)
marco08 2007-01-17
  • 打赏
  • 举报
回复
create table A
(
Aid int not null primary key,
ABid int not null
)
go
create table B
(
Bid int not null primary key,
Bname varchar(8) not null
)
go
insert into A values(1,1)
go
insert into A values(2,2)
go
insert into B values(1,'网求')
go
insert into B values(2,'晚秋')
go
alter table A add Constraint A_B_FK
foreign key (ABid) references B(Bid)
go
insert into A
select 3, Bid from B where Bname='晚秋'
go

34,588

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server相关内容讨论专区
社区管理员
  • 基础类社区
  • 二月十六
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧