问题描述:
创建银行数据库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
代码:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151if exists (select *from sysdatabases where name='bankDB') drop database bankDB create database bankDB on primary--主数据库文件 ( name = 'bankDB-张晴晴', filename ='D:projectbankDB.mdf', size=5mb, maxsize=100mb, filegrowth=2mb ),--次要数据库文件 ( name = 'bankDB01', filename ='c:project01bankDB01.ndf', size=5mb, maxsize=100mb, filegrowth=2mb ), ( name = 'bankDB02', filename ='c:project02bankDB02.ndf', size=5mb, maxsize=100mb, filegrowth=2mb )--日志文件 log on ( name = 'bankDB_log1', filename ='C:log1bankDB_log1.ldf', size=5mb, maxsize=100mb, filegrowth=2mb ), ( name = 'bankDB_log2', filename ='C:log2bankDB_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)
最后
以上就是微笑花卷最近收集整理的关于创建银行数据库bankDB创建银行数据库bankDB的全部内容,更多相关创建银行数据库bankDB创建银行数据库bankDB内容请搜索靠谱客的其他文章。
发表评论 取消回复