建表(createtable),查看school数据库的系统视图schemaidnameobject_jidprincipalid sys.tables121575115NULLStuderntNULL185575343CourseNULL1Teacher1495755711213575799NULLSCTobject jdcolumn_idsystem_type_idname716744014957.Tprofsys.columns441810614957.Tpay5644221357..ID443216721357.Sno44421357.Cno3167Tno44521357.416744610621357.Grade44719930.148status24484819930.priorityindexidobject_idnamesys.indexes8385575.PK_Course_C1FE637307020F2118414957....PKTeacher_C450026D0AD2A0058521357.PKSCT3214EC270EA330E98619930.queue_clusteredindex
建表(create table) 查看school数据库的系统视图 sys.tables sys.columns sys.indexes
建表(createtable),查看school数据库的系统视图objectidname sys.key_constraintsPK_Student_CA1FE46403317E3D69575286133575514PK_Course_C1FE637307020F21PKTeacherC450026D0AD2A005197575742PK_SCT_3214EC270EA330E9261575970obiect idcolumn idnameID213575799sys.identity_columns1993058136queuing_order20250582503queuing_order2057058364queuing_orderobject_idname49PKCourseC1FE637307020F2113357...sys.objects5014957....Teacher51PK_TeacherC450026D0AD2A0.19757..5221357...SCT53PK_SCT_3214EC270EA330E926157..5419770....QueryNotificationEmorsQueue
建表(create table) 查看school数据库的系统视图 sys.key_constraints sys.identity_columns sys.objects
添加约束(add constraint),为表SCT的属性列Sno,Cno,Tno分别添加外键约束sql语句:use school;alter table SCTadd constraint sno_foreignkeyforeign key (Sno) references Student(Sno);altertableSCTadd constraint cno_foreignkeyforeign key (Cno) references Course(Cno);altertableSCTaddconstrainttno_foreignkeyforeign key (Tno)references Teacher(Tno)
添加约束(add constraint) 为表SCT的属性列Sno,Cno,Tno分别添加外键约束 sql语句: use school; alter table SCT add constraint sno_foreignkey foreign key (Sno) references Student(Sno); alter table SCT add constraint cno_foreignkey foreign key (Cno) references Course(Cno); alter table SCT add constraint tno_foreignkey foreign key (Tno) references Teacher(Tno);