日期:2014-05-17 浏览次数:20495 次
--给个例子参考
CREATE TABLE StudentGrade(
stuId CHAR(4), --学号
subId INT, --课程号
grade INT, --成绩
PRIMARY KEY (stuId,subId)
)
GO
--表中数据如下
INSERT INTO StudentGrade(stuId,subId,grade) VALUES( '001 ',1,97);
INSERT INTO StudentGrade(stuId,subId,grade) VALUES( '001 ',2,50);
INSERT INTO StudentGrade(stuId,subId,grade) VALUES( '001 ',3,70);
INSERT INTO StudentGrade(stuId,subId,grade) VALUES( '002 ',1,92);
INSERT INTO StudentGrade(stuId,subId,grade) VALUES( '002 ',2,80);
INSERT INTO StudentGrade(stuId,subId,grade) VALUES( '002 ',3,30);
INSERT INTO StudentGrade(stuId,subId,grade) VALUES( '003 ',1,93);
INSERT INTO StudentGrade(stuId,subId,grade) VALUES( '003 ',2,95);
INSERT INTO StudentGrade(stuId,subId,grade) VALUES( '003 ',3,85);
INSERT INTO StudentGrade(stuId,subId,grade) VALUES( '004 ',1,73);
INSERT INTO StudentGrade(stuId,subId,grade) VALUES( '004 ',2,78);
INSERT INTO StudentGrade(stuId,subId,grade) VALUES( '004 ',3,87);
GO
stuId subId grade
001 1 97
001 2 50
001 3 70
002 1 92
002 2 80
002 3 30
003 1 93
003 2 95
003 3 85
004 1 73
004 2 78
004 3 87
stuId subId grade
001 0 217
002 1 92
002 2 80
002 3 30
003 1 93
003 2 95
003 3 85
004 1 73
004 2 78
004 3 87