日期:2014-05-18 浏览次数:20519 次
--DROP TABLE Student; CREATE TABLE Student ( ID INT IDENTITY(1, 1) PRIMARY KEY, StuNo INT UNIQUE, Name VARCHAR(128), Grade INT, Class VARCHAR(10) ); --DROP TABLE Score; CREATE TABLE Score ( StuNo INT FOREIGN KEY REFERENCES Student(StuNo), Mark INT ); INSERT INTO Student VALUES (800001, '陈明', 1, 'A'); INSERT INTO Student VALUES (800002, '张华', 2, 'A'); INSERT INTO Student VALUES (800003, '李月', 3, 'A'); INSERT INTO Student VALUES (800004, '黎顺', 1, 'B'); INSERT INTO Student VALUES (800005, '许肖基', 2, 'B'); INSERT INTO Student VALUES (800006, '肖晨咕', 3, 'B'); INSERT INTO Student VALUES (800007, '杨晨明', 1, 'A'); INSERT INTO Student VALUES (800008, '戴三', 2, 'A'); INSERT INTO Student VALUES (800009, '黄英', 3, 'A'); INSERT INTO Student VALUES (800010, '张三', 4, 'A'); INSERT INTO Student VALUES (800011, '李四', 5, 'A'); INSERT INTO Student VALUES (800012, '黄五', 4, 'A'); INSERT INTO Student VALUES (800013, '陈七', 5, 'A'); /* BEGIN DECLARE StuCur CURSOR FOR SELECT StuNo FROM Student; DECLARE @StrBuffer AS VARCHAR(1024); OPEN StuCur; FETCH NEXT FROM StuCur INTO @StrBuffer; WHILE @@FETCH_STATUS = 0 BEGIN PRINT 'INSERT INTO Score VALUES(' + @StrBuffer + ', ' + CAST(CAST(RAND() * 100 AS INT) AS VARCHAR) + ')' FETCH NEXT FROM StuCur INTO @StrBuffer; END DEALLOCATE StuCur END */ INSERT INTO Score VALUES(800001, 53) INSERT INTO Score VALUES(800002, 77) INSERT INTO Score VALUES(800003, 92) INSERT INTO Score VALUES(800004, 47) INSERT INTO Score VALUES(800005, 82) INSERT INTO Score VALUES(800006, 24) INSERT INTO Score VALUES(800007, 73) INSERT INTO Score VALUES(800008, 94) INSERT INTO Score VALUES(800009, 72) INSERT INTO Score VALUES(800010, 73) INSERT INTO Score VALUES(800011, 63) INSERT INTO Score VALUES(800012, 78) INSERT INTO Score VALUES(800013, 96)
CREATE TABLE Student ( ID INT IDENTITY(1, 1) PRIMARY KEY, StuNo INT UNIQUE, Name VARCHAR(128), Grade INT, Class VARCHAR(10) ) go --DROP TABLE Score; CREATE TABLE Score ( StuNo INT FOREIGN KEY REFERENCES Student(StuNo), Mark INT ) INSERT INTO Student VALUES (800001, '陈明', 1, 'A'); INSERT INTO Student VALUES (800002, '张华', 2, 'A'); INSERT INTO Student VALUES (800003, '李月', 3, 'A'); INSERT INTO Student VALUES (800004, '黎顺', 1, 'B'); INSERT INTO Student VALUES (800005, '许肖基', 2, 'B'); INSERT INTO Student VALUES (800006, '肖晨咕', 3, 'B'); INSERT INTO Student VALUES (800007, '杨晨明', 1, 'A'); INSERT INTO Student VALUES (800008, '戴三', 2, 'A