在課程表中為課程號創建主鍵約束pk
『壹』 設在學生資料庫中有三張表,表結構如下所示: Student(學生表): Student表的主鍵:sno(學號) Course(課程
(1) create table S_C
(sno char(10) not null
,cno char(8) not null
,score int null
,constraint PK_SC primary key (sno,cno)
)
(2)insert into Student (sno,sname,ssex)
values('1010','李小麗','女')
(3)create index IND_CName on Course (cname)
(4)update student set sage=23 where sno='1005'
(5)delete from course where cname='管理信息系統'
(6)select cno,cname,ctime
from course
where teacher='李元'
order by cno ASC
(7)select sno,sum(score) as score
from S_C
group by sno
(8)create view V_Student
as
select *
from student
where ssex='男' and sage>=18 and sage<=24
(9)select sno,sname
from student
where sno in (select sno from S_C where cno='001')
(10)select A.sno,A.sname
from student A
left join S_C B on A.sno=B.sno
left join Course C on B.cno=C.cno
where C.cname='關系資料庫'
(11)select sno,sname from
(select A.sno,A.sname,count(1) as count_
from student A
left join S_C B on A.sno=B.sno
group by A.sno,A.sname) A
where count_>3
(12)select C.sname
from
(select * from S_C where cno='002') A
inner join
(select * from S_C where cno='004' on) B on A.sno=B.sno
left join student C on A.sno=C.sno
『貳』 主鍵和外鍵約束的問題。有三個表,成績表,課程表和成績表。外鍵是某個表的主鍵嗎。
你這里的課程編號就是課程號吧。
學號是學生表的主鍵、課程編號是課程表的主鍵回、學號答和課程號是成績表的主鍵,學號是成績表的外鍵,課程號是成績表的外鍵。
學號是成績表的外鍵,成績表的學號的有效取值是學生表裡的學號決定的,而外鍵通常是另外一個表的主鍵,課程號以此類推即可。
『叄』 SQL創建學生表(Student)、課程表(Course)、班級表(Class)、選課表(XK),寫對的我可以獎勵QB
一個student表student表包含復三個欄位的學制生的ID(stu_id)學生姓名(stu_name),當然ID(les_id)
「CREATE TABLE [dbo的]。學生(/ stu_id。的uniqueidentifier] NOT NULL,
stu_name [數據類型為nvarchar](425)NOT NULL,
les_id [為uniqueidentifier] NOT NULL
)
第二個表中的課程課,有兩個欄位,當然的ID(les_id)的和課程名稱(les_name)
CREATE TABLE [dbo的課(
les_id的uniqueidentifier] NOT NULL,
les_name [數據類型為nvarchar](425)NOT NULL
)< /第三個表,學生表的分數,三場場ID(les_id)的學生證(stu_id)和課程成績(les_score)
創建表[DBO]。分數(
les_id的uniqueidentifier] NULL,
stu_id的唯一標識符NOT NULL,
les_score [INT] NOT NULL
)