ºþ ÄÏ ÎÄ Àí ѧ Ôº ʵ Ñé ±¨ ¸æ ¿Î³ÌÃû³Æ Êý¾Ý¿âÔÀíÓëÓ¦Óà ʵÑéÃû³Æ ´´½¨Êý¾Ý¿âºÍÊý¾Ý±í ³É¼¨ ѧÉúÐÕÃû µËÓ¡ רҵ Èí¼þ¹¤³Ì °à¼¶ 17102ѧºÅ 201717040203 ͬ×éÕßÐÕÃû ÎÞ ÊµÑéÈÕÆÚ 2019Äê4ÔÂ18ÈÕ Ò»¡¢ÊµÑéÄ¿µÄ ÊìϤSQL Server Management Studio½çÃ棻ÕÆÎÕͨ¹ýͼÐλ¯Ïòµ¼ºÍÖ´ÐÐTransact-SQLÓï¾ä´´½¨Êý¾Ý¿âµÄ·½·¨¡£ ¶þ¡¢ÊµÑé»·¾³
Windows7²Ù×÷ϵͳ£¬SQL ServerÈí¼þ¡£ Èý¡¢ÊµÑéÄÚÈÝ
ÔÚSQL ServerÖд´½¨Êý¾Ý¿âµÄ·½·¨Ö÷ÒªÓÐÁ½ÖÖ£ºÒ»ÊÇÔÚSQL Server Management Studio´°¿ÚÖÐʹÓÿÉÊÓ»¯½çÃ棬ͨ¹ý·½±ãµÄͼÐλ¯Ïòµ¼´´½¨£¬¶þÊÇͨ¹ýÖ´ÐÐTransact-SQLÓï¾ä´´½¨¡£
±í1£ºSTUDENT±í ³¤¶È 10 8 2 10 11 Ô¼Êø NULL N N N N PK Y FK CHECK ¡®ÄС¯ or ¡®Å®¡¯ ÁÐÃû sno sname sex DOB dept telno
ÀàÐÍ char varchar Char datetime varchar char ±í2£ºCOURSE±í Ô¼Êø ÁÐÃû cno cname Cpno teacher credit ÀàÐÍ char varchar char varchar smallint ³¤¶È NULL 5 10 5 8 N N N PK Y Ô¼Êø ÁÐÃû ÀàÐÍ ³¤¶È NULL PK FK CHECK FK CHECK ±í3£ºSC±í ¹² 3 Ò³£¨µÚ 1 Ò³£© ÆÀÔĽÌʦ ʱ¼ä
sno cno score char char decimal(6,2) 10 5 N Y N References s(sno) References c(cno) 0-100 ÒªÇ󣺵±Ö÷±íSTUDENTÖеÄÖ÷ÂëSNOºÍCOURSEÖеÄÖ÷ÂëCNO·¢ÉúÐ޸Ļòɾ³ýʱ£¬SC±íÖеÄÏàÓ¦ÍâÂë×öCASCADE²Ù×÷¡£
ËÄ¡¢ÊµÑé²½Öè
´´½¨Êý¾Ý¿â
CREATE DATABASE teacher ´´½¨Êý¾Ý±í
sno char(10) not null primary key, sex char(2) check(sex in('ÄÐ','Å®')) not null, canme varchar(8) not null , DOB datetime, dept varchar(10), telno char(11) not null, )
create table COURSE(
con char(5) not null primary key, cname varchar(10) not null, Cpno char(5),
teacher varchar(8) not null, credit smallint, )
create table SC(
son char(10) not null primary key, con char(5) not null primary key,
score decimal(6,2) check(score in(score<'100'||score>'0')), )
¹² 3 Ò³£¨µÚ 2 Ò³£© ÆÀÔĽÌʦ ʱ¼ä
Î塢ʵÑéÐĵÃ
ÔÚÕâ´ÎÊý¾Ý¿âʵÑéÖУ¬ÎÒ³õ²½µÄÁ˽⵽ÁËSQLµÄһЩ»ù±¾µÄ²Ù×÷£¬ÀýÈç²éѯ·ÖÎöÆ÷µÄ½çÃæÓ÷¨£¬Ò²Ã÷°×ÁË´óдСд²¢²»Ó°ÏìÊý¾Ý²éѯ£¬Ò²ÖªµÀÁËÈçºÎÈ¥´´½¨Êý¾Ý¿âºÍÊý¾Ý±í¡£ËäÈ»ÔÚʵÑéÖгöÏÖÁËbug£¬²»¹ýͨ¹ýÊé±¾¶¼ÕÒ½â¾öÁË¡£
¹² 3 Ò³£¨µÚ 3 Ò³£© ÆÀÔĽÌʦ ʱ¼ä