自考人的网上家园

当前位置:首页  > 复习指导  > 历年试题  > 正文

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

2007/07/18  来源:    字体:  打印

  答案:

  /*建表*/

  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)

自考整专业 自考整专业高端班