--创建表空间
create tablespace lsq
datafile 'C:\Users\Administrator\Desktop\数据库项目\data.dbf'
size 100M
autoextend on;
--创建用户
create user xxx
identified by lsq
default tablespace lsq;
--用户授权
grant dba to xxx;
--用户信息表
create table userInfo (
customerID NUMBER(30) not null,
customerName VARCHAR2(30) not null unique,
Pid varchar(18) unique,
telephone varchar(11) not null,
address VARCHAR2(50),
constraint PK_t_user primary key (customerID)
);
--银行卡信息表
create table cardInfo (
cardID CHAR(30),
savingID NUMBER(29) not null ,
customerID NUMBER(30) not null,
pass CHAR(6) not null , --密码
curID VARCHAR2(10) not null, --币种
openDate DATE not null, --开户日期
openMoney NUMBER not null, --卡户金额
balance NUMBER(8,2) not null , --余额
IsReportLoss SMALLINT not null,--是否挂失
constraint PK_t_card primary key (cardID),
constraint cardInfo_savingID_fk foreign key(savingID) references deposit(savingID),
constraint cardInfo_customerID_fk foreign key(customerID) references Userinfo(customerID)
);
--交易信息表
create table tradeInfo(
cardID CHAR(30) not null,
tradeDate DATE not null,
tradeMoney NUMBER not null,
tradeType CHAR(4) not null,
remark CLOB,
constraint tradeInfo_cardID_fk foreign key(cardID) references Cardinfo(cardID)
);
--存款类型表
create table deposit (
savingID NUMBER(29) not null,
savingName VARCHAR2(20) not null,
descrip VARCHAR2(50) not null,
constraint PK_DEPOSIT primary key (savingID)
);
/*$$$$$$$$$$$$$加约束$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$*/
/* userInfo表的约束
customerID 顾客编号 主键
customerName 开户名 必填
PID 身份证号 必填,只能是18位或15位,身份证号唯一约束
telephone 联系电话 必填,格式为xxxx-xxxxxxxx或手机号11位
address 居住地址 可选输入
*/
alter table userInfo add constraint userInfo_Pid_ck check((length(Pid)=15 or length(Pid)=18));
alter table userInfo add constraint userInfo_telephone_ck check(regexp_like(telephone,'(^\d{3,4}-\d{8}$)|([0-9]{11})'));
--ALTER TABLE userInfo
--drop CONSTRAINT CK_telephone
/*cardInfo表的约束
cardID 卡号 必填,主健 , 银行的卡号规则和电话号码一样,一般前8位代表特殊含义,
如某总行某支行等。假定该行要求其营业厅的卡号格式为:1010 3576 xxxx xxx开始
curType 货币 必填,默认为RMB
savingType 存款种类 活期/定活两便/定期
openDate 开户日期 必填,默认为系统当前日期
openMoney 开户金额 必填,不低于1元
balance 余额 必填,不低于1元,否则将销户
pass 密码 必填,6位数字,默认为6个8
IsReportLoss 是否挂失 必填,0/1值,默认为0未挂失
customerID 顾客编号 必填,表示该卡对应的顾客编号,一位顾客可以办理多张卡
*/
alter table cardInfo modify(curID default 'RMB'); -- 默认为RMB
alter table cardInfo modify(openDate default sysdate);-- 开户日期为系统时间
alter table cardInfo add constraint cardInfo_openMoney_ck check(openMoney>1); --开户金额大于一
alter table cardInfo add constraint cardInfo_balance_ck check(balance>1); -- 余额大于一
alter table cardInfo add constraint cardInfo_cardID_ck check(regexp_like(cardID,'1010 3576 \d{4} \d{4}')); -- 卡号格式为:1010 3576 xxxx xxx开始
alter table cardInfo add constraint cardInfo_pass_ck check(regexp_like(pass,'^[0-9]{6}$')); --6位数字,默认为6个8
alter table cardInfo modify (pass default '888888');
/* tradeInfo表的约束
tradeType 必填,只能是存入/支取
cardID 卡号 必填,外健,可重复索引
tradeMoney 交易金额 必填,大于0
tradeDate 交易日期 必填,默认为系统当前日期
remark 备注 可选输入,其他说明
*/
alter table tradeInfo add constraint tradeInfo_tradeType_ck check(tradeType in ('存入','支取'));
alter table tradeInfo add
模拟银行ATM取钱存钱开户挂失等
最新推荐文章于 2021-03-23 08:22:08 发布