alter table
create table BankCard
(
cardId char(10),
UserName Varchar(20) not null,
Password char(6) not null,
Balance money
)
先创建一个表
再修改表
alter table BankCard
不为空
alter column cardId char(10) not null
添加主键
add constraint pk_card primary key(cardId)
check约束
add constraint Balance_ck check(balance >=0)
unique约束
add constraint un_card unique(username,password)
create table Trade
(
tradeId Bigint identity,
CardId char(10),
tradedate datetime not null,
trademoney money check(trademoney>0),
tradetype char(2)
)
添加外键
alter table trade
add constraint fk_card foreign key (cardid) references BankCard(cardId)
(
cardId char(10),
UserName Varchar(20) not null,
Password char(6) not null,
Balance money
)
先创建一个表
再修改表
alter table BankCard
不为空
alter column cardId char(10) not null
添加主键
add constraint pk_card primary key(cardId)
check约束
add constraint Balance_ck check(balance >=0)
unique约束
add constraint un_card unique(username,password)
create table Trade
(
tradeId Bigint identity,
CardId char(10),
tradedate datetime not null,
trademoney money check(trademoney>0),
tradetype char(2)
)
添加外键
alter table trade
add constraint fk_card foreign key (cardid) references BankCard(cardId)