日期:2014-05-17 浏览次数:20485 次
CREATE TABLE FLIGHTS
(
flightNum varchar(100) not null primary key,
price int not null,
numSeats int not null,
numAvail int not null,
FromCity varchar(100),
ArivCity varchar(100)
)
go
CREATE TABLE RESERVATIONS
(
custName varchar(100),
flightNum varchar(100)
)
--增加外键
alter table RESERVATIONS
add constraint flightNum_FK1 foreign key (flightNum) references FLIGHTS (flightNum)
--在修改字段值
update RESERVATIONS
set flightNum = FLIGHTS.numSeats-FLIGHTS.numAvail
from FLIGHTS where RESERVATIONS.flightNum = FLIGHTS.flightNum