您的位置:自考365 > 复习指导 > 历年试题 > 北大“数据库原理”上机实践题目总结(10)

北大“数据库原理”上机实践题目总结(10)

2007-07-18 14:46   【 】【我要纠错

  答案:

  /*建表*/

  create table Numbers

  (

  NID char(5),

  NName char(6) not null,

  NAdd char(100) not null,

  NCash int

  primary key(NID),

  check(NCash > 0)

  )

  create table Horses

  (

  HID char(5),

  HCol char(4) not null,

  HAdd char(100) not null,

  primary key(HID)

  )

  create table RRecord

  (

  SerNum int,

  HID char(5),

  primary key(SerNum),

  foreign key(HID) references Horses(HID)

  )

  create table CRecord

  (

  NID char(5) not null,

  HID char(5) not null,

  SerNum int not null,

  foreign key(NID) references Numbers(NID),

  foreign key(HID) references Horses(HID),

  foreign key(SerNum) references RRecord(SerNum),

  primary key(NID,SerNum)

  )

  /*插入数据*/

  insert into Numbers

  VALUES ('U001','Num1', 'address1',10)

  insert into Numbers

  VALUES ('U002','Num2', 'address2',20)

  insert into Numbers

  VALUES ('U003','Num3', 'address3',30)

  insert into Horses

  VALUES ('H001','R', 'address3')

  insert into Horses

  VALUES ('H002','G', 'address2')

  insert into Horses

  VALUES ('H003','B', 'address1')

  insert into RRecord

  VALUES (1,'H003')

  insert into RRecord

  VALUES (2,'H001')

  insert into RRecord

  VALUES (3,'H002')

  insert into CRecord

  VALUES ('U001','H003',1)

  insert into CRecord

  VALUES ('U001','H003',2)

  insert into CRecord

  VALUES ('U002','H003',1)

  insert into CRecord

  VALUES ('U003','H003',2)

本文转载链接:北大“数据库原理”上机实践题目总结(10)

分享到:
  • 站内搜索
  • 课程搜索
  • 试题搜索

热门搜索:教材 报名 查分 免考 考试计划