创建银行数据库bankDB

问题描述:

创建银行数据库bankDB

1、创建数据库1  2   2


1-1 创建文件夹用以存放数据库


1-2 创建建库bankDB


2、创建数据库


2-1、创建用户信息表userInfo


字段名称

数据类型

说明

customerID

int

客户编号,主键

customerName

CHAR(8)

客户姓名

PID

CHAR(18)

身份证号

telephone

CHAR(13)

电话

address

VARCHAR(50)

地址


 


 


2-2、创建银行卡信息表 cardInfo


字段名称

数据类型

说明

cardID 

CHAR(19)

卡号

curType

CHAR(5)

类型

savingType 

CHAR(18)

存款类型(存或取)

openDate 

DATETIME

开户时间

openMoney 

MONEY

开户金额

balance 

MONEY

帐户余额

pass

CHAR(6)

密码

IsReportLoss

BIT

是否挂失

customerID

Int

客户帐号


 


 


2-3、创建交易信息表 transInfo


字段名称

数据类型

说明

transDate 

DATETIME

交易日期

transType 

CHAR(4)

交易类型

cardID

CHAR(19)

卡号

transMoney 

MONEY

交易金额

remark 

TEXT  

备注


 


 


3、加约束


3-1 userInfo表的约束


customerID  顾客编号  自动编号(标识列),从1开始,主键


customerName 开户名 必填


PID   身份证号  必填,只能是18位,身份证号唯一约束


telephone 联系电话  必填,手机号位


address  居住地址  可选输入


 


3-2 cardInfo表的约束


cardID 卡号  必填,主健,银行的卡号规则和电话号码一样,一般前位代表特殊含义,如某总行某支行等。假定该行要求其营业厅的卡号格式为:3576 xxxx xxx开始


curType  货币  必填,默认为1RMB


savingType  存款种类  活期/定活两便/定期


openDate 开户日期  必填,默认为系统当前日期


openMoney 开户金额  必填,不低于1


balance  余额  必填,不低于1元,否则将销户


pass  密码  必填,6位数字,默认为6


IsReportLoss 是否挂失 必填,是/否值,默认为”否”


customerID  顾客编号  必填,表示该卡对应的顾客编号,一位顾客可以办理多张卡


 


3-3 transInfo表的约束


transType       必填,只能是存入/支取


cardID 卡号  必填,外健,可重复索引


transMoney  交易金额  必填,大于1


transDate 交易日期  必填,默认为系统当前日期


remark 备注  可选输入,其他说明


 


4、 插入测试数据


张三开户,身份证:,电话:-67898978,地址:北京海淀


   开户金额:活期 卡号:3576 1234 5678


李四开户,身份证:,电话:-44443333,


   开户金额:1 定期卡号:3576 1212 1134





代码:

 

if exists (select *from sysdatabases where name='bankDB')
drop database bankDB
create database bankDB
on primary--主数据库文件
(
 name = 'bankDB-张晴晴',
 filename ='D:\project\bankDB.mdf',
 size=5mb,
 maxsize=100mb,
 filegrowth=2mb  
),--次要数据库文件
(
 name = 'bankDB01',
 filename ='c:\project01\bankDB01.ndf',
 size=5mb,
 maxsize=100mb,
 filegrowth=2mb 
),
(
 name = 'bankDB02',
 filename ='c:\project02\bankDB02.ndf',
 size=5mb,
 maxsize=100mb,
 filegrowth=2mb 

)--日志文件
log on
(
 name = 'bankDB_log1',
 filename ='C:\log1\bankDB_log1.ldf',
 size=5mb,
 maxsize=100mb,
 filegrowth=2mb 
  
),
(
 name = 'bankDB_log2',
 filename ='C:\log2\bankDB_log2.ldf',
 size=5mb,
 maxsize=100mb,
 filegrowth=2mb  
)
----------------------用户表----------------------------------------------------
if exists (select *from sysobjects where name='userInfo')
drop table userInfo
create table userInfo
(
customerID	int identity (1,1),--客户编号,主键
customerName CHAR(8) not null,	--客户姓名
PID	CHAR(18),--身份证号
telephone	CHAR(11)not null,--	电话
address	VARCHAR(50)--地址
)
alter table userInfo--主键必填
add constraint PK_customerID primary key(customerID)

alter table userInfo--唯一约束
add constraint UK_customerName unique(customerName)



----------------------卡号表----------------------------------------------------
if exists (select *from sysobjects where name='cardInfo')
drop table cardInfo
create table cardInfo--创建银行卡信息表 
(
cardID CHAR(19)not null,--卡号
curType	CHAR(5)not null,--类型
savingType CHAR(18)not null,--	存款类型(存或取)
openDate DATETIME not null,-- 	开户时间
openMoney MONEY not null,--	开户金额
balance MONEY not null,--	帐户余额
pass CHAR(6) not null,--	密码
IsReportLoss BIT not null,--	是否挂失
customerID Int not null,--	客户帐号
)
---------------------------------cardInfo表的约束-----------------------------------
alter table cardInfo
add constraint PK_cardID primary key(cardID)
--savingType	存款种类	活期/定活两便/定期
alter table cardInfo
add constraint CK_savingType check(savingType='活期' or savingType='定活两便' or savingType='定期')
--cardID	卡号	必填,主健, 卡号格式为:3576 xxxx xxx开始
alter table cardInfo
add constraint CK_cardID check(cardID like '3576%')
--openDate	开户日期	必填,默认为系统当前日期
alter table cardInfo
add constraint DF_openDate default(getdate())for openDate
--货币	必填,默认为1RMB 
alter table cardInfo
add constraint DF_curType default('RMB')for curType
--openMoney	开户金额	必填,不低于1元
alter table cardInfo
add constraint CK_openMoney check(openMoney>=1)
--balance	余额	必填,不低于1元,否则将销户
alter table cardInfo
add constraint CK_balance check(balance>=1)
--pass	密码必填,6位数字,默认为6个
alter table cardInfo
add constraint CK_pass check(len(pass)=6)
--IsReportLoss	是否挂失 必填,是/否值,默认为”否”
alter table cardInfo
add constraint DF_IsReportLoss default(0)for IsReportLoss
/*
customerID	顾客编号 必填,表示该卡对应的顾客编号,一位顾客可以办理多张卡
*/
--------------------交易表-------------------------------------------------
if exists (select *from sysobjects where name='transInfo')
drop table transInfo
create table transInfo--创建交易信息表 transInfo
(
transDate  DATETIME,--	交易日期
transType  CHAR(4),--	交易类型
cardID	CHAR(19),--	卡号
transMoney  MONEY,--	交易金额
remark TEXT-- 备注
)
----------------transInfo表的约束---------------------------------------------------
--transType       必填,只能是存入/支取
alter table transInfo
add constraint CK_transType check(transType='存入' or transType='支取')

--transMoney	交易金额	必填,大于1元
alter table transInfo
add constraint CK_transMoney check(transMoney>=1)

--transDate	交易日期	必填,默认为系统当前日期
alter table transInfo
add constraint DF_transDate default(getdate())for transDate

--cardID	卡号	必填,外健,可重复索引
alter table transInfo
add constraint FK_cardID  foreign key (cardID )references cardInfo(cardID )
/*
remark	备注	可选输入,其他说明
*/
----------------------------插入测试数据-------------------------------------
insert into userInfo
(customerName,PID,telephone,address)
values('张三','370786999952147896','67898978','北京海淀')
insert into cardInfo
(customerID,openMoney,savingType,cardID,curType,openDate,balance,pass,IsReportLoss)
values('123456','2','活期','357612345678',default,default,'5','564789',default)
insert into userInfo
(customerName,PID,telephone)
values('李四','370786999952147896','44443333')
insert into cardInfo
(customerID,openMoney,savingType,cardID,curType,openDate,balance,pass,IsReportLoss)
values('589647','4','定期','357612121134',default,default,'5','564789',default)




评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

早日退休过上不劳而获生活

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值