日期:2014-05-18  浏览次数:20742 次

怎么使内容不重复
SQL code
CREATE TABLE Employee (
irdNumber char(11),
lastName varchar(30),
firstName varchar(30),
primary key (irdNumber)
)

CREATE TABLE Customer (
accountId int,
lastName varchar(30),
firstName varchar(30),
street varchar(100), 
city varchar(32),
postcode char(4),
balance real,
primary key (accountId)
)

CREATE TABLE Store (
storeId int,
street varchar(100), 
city varchar(32),
postcode char(4),
manager char(11),
primary key (storeId),
foreign key (manager) references Employee(irdNumber)
)

CREATE TABLE TimeSheet (
irdNumber char(11),
date datetime,
startTime time,
endTime time,
storeId int,
primary key (irdNumber, date, startTime),
foreign key (storeId) references Store(storeId)
)

CREATE TABLE Movie (
movieId varchar(10),
title varchar(100),
genre varchar(32),
rating varchar(10),
primary key (movieId),
)

CREATE TABLE Dvd (
dvdId int,
dateAcquired datetime,
movieId varchar(10),
storeId int,
primary key (dvdId),
foreign key (movieId) references Movie,
foreign key (storeId) references Store
)

CREATE TABLE Rental (
accountId int,
dvdId int,
dateRented datetime,
dateDue datetime,
cost real,
primary key (accountId, dvdId),
foreign key (accountId) references Customer (accountId),
foreign key (dvdId) references Dvd (dvdId),
)

insert into Employee values ('111-222-333', 'Smith', 'Linda')
insert into Employee values ('111-222-444', 'Brown', 'Mark')
insert into Employee values ('111-222-555', 'Jones', 'Julia')
insert into Employee values ('111-222-666', 'Green', 'Peter')
insert into Employee values ('111-222-777', 'Ash', 'Marian')

insert into Customer values (101, 'McCaw', 'Roberta', '34 Vine St.', 'Christchurch', '1234', 0.0)
insert into Customer values (102, 'Woodcock', 'Luke', '342 Hall St.', 'Auckland', '1278', 3.0)
insert into Customer values (103, 'Umaga', 'Wilma', '12 Kowhai Av.', 'Hamilton', '9876', 31.0)
insert into Customer values (104, 'Carter', 'David', '56 Vinegar St.', 'Christchurch', '1338', 35.0)
insert into Customer values (105, 'Cowan', 'Tina', '78 Poplar Rd.', 'Dunedin', '1235', 0.0)
insert into Customer values (106, 'Nonu', 'Brad', '49 Pine Close.', 'Wellington', '1123', 0.0)
insert into Customer values (107, 'Kahui', 'Julie', '60 Kina St.', 'Hamilton', '1222', 0.0)
insert into Customer values (108, 'Toeava', 'Robert', '124 Holly St.', 'Auckland', '1334', 10.55)

insert into Store values (1, 'Buggy St.', 'Christchurch', '3456', '111-222-777')
insert into Store values (2, 'Bee Lane', 'Auckland', '3377', '111-222-666')
insert into Store values (3, 'Carmen St.', 'Hamilton', '3443', '111-222-666')
insert into Store values (4, 'Freezing St.', 'Dunedin', '6556', '111-222-777')

insert into TimeSheet values ('111-222-333', '2011-01-01 00:00:00' , '2011-01-01 08:15:00' , '2011-01-01 12:00:00' , 3)
insert into TimeSheet values ('111-222-444', '2011-01-01 00:00:00' , '2011-01-01 08:15:00' , '2011-01-01 12:00:00' , 3)
insert into TimeSheet values ('111-222-555', '2011-02-02 00:00:00' , '2011-02-02 14:00:00' , '2011-02-02 22:00:00' , 4)
insert into TimeSheet values ('111-222-333', '2011-03-03 00:00:00' , '2011-03-03 08:15:00' , '2011-01-01 12:00:00' , 3)
insert into TimeSheet values ('111-222-555', '2011-04-04 00:00:00' , '2011-04-04 10:00:00' , '2011-04-04 14:00:00' , 4)
insert into TimeSheet values ('111-222-555', '2011-04-04 00:00:00' , '2011-04-04 15:00:00' , '2011-04-04 19:00:00' , 4)

insert into Movie values ('1001', 'The Three Amigos', 'mystery', 'R')
insert into Movie values ('1231', 'Annie Hall', 'romantic comedy', 'R')
insert into Movie values ('1451', 'Lady and the Tramp', 'animation', 'PG')
insert into Movie values ('1891', 'Animal House', 'comedy', 'PG-13')
insert into Movie values ('4501', 'Elizabeth', 'costume drama', 'PG-13')
insert into Movie values ('5531', 'True Grit', 'western', 'R')
insert into Movie values ('9871', 'RV', 'comedy', 'PG-13')

insert into Dvd valu