请人帮忙解决下:有三个关系:S(s#,sname,age,sex) SC(s# ,c#,gread...
发布网友
发布时间:2024-10-13 03:05
我来回答
共2个回答
热心网友
时间:2024-10-13 03:38
1、
ALTER TABLE [dbo].[SC] ADD CONSTRAINT [PK_SC] PRIMARY KEY CLUSTERED
(
[S#] ASC,
[C#] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, IGNORE_DUP_KEY = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
2、insert into C(c#,cname,teacher) values (’C8’,’DB’,’YXZ’);
3、update S set age=age+1
4、select c.cname,c.teacher from
s inner join sc on s.s#=sc.s#
inner join c on sc.c#=c.c#
where s.s#='S3'
5、
select distinct c.cname,c.teacher from
s inner join sc on s.s#=sc.s#
inner join c on sc.c#=c.c#
where c.teacher='LIU' and s.sex='女'
6、select c.c# from c
where c.c# not in
(select sc.c# from sc
inner join s on sc.s#=s.s# where s.sname='wang')
热心网友
时间:2024-10-13 03:39
楼主,你最好说下你的数据库是什么?不同的数据库,语法有点不同的哦
sqlserver 2005的,不一定对,手打的,没有经过测试
1. create table SC(s# varchar(30) not null ,c# varchar(30) not null ,gread varchar(30)CONSTRAINT [SC]PRIMARY KEY CLUSTERED( [s#] ASC, [c#] ASC))
2. insert into C values (’C8’,’DB’,’YXZ’)
3.update S set age = age+1
4. select c.cname,c.teacher from C c,S s,SC sc where s.s# =sc.s# and sc.c# =c.c# and s.s# ='S3'
5. select s.sname from S s,C c where s.sex ='女' and c.teacher='LIU'
6 select c.c# from cwhere c.c# not in(select sc.c# from scinner join s on sc.s#=s.s# where s.sname='wang')