当前位置:首页 » 操作系统 » 小型系统数据库设计

小型系统数据库设计

发布时间: 2022-07-20 13:17:51

❶ SQL小型数据库系统设计

--------------创建数据库--------------------------
create database bankDB
on primary
(
name = 'bankDB',
filename = 'e:\bank\bankDB.mdf',
size = 3MB,
maxsize = 100MB,
filegrowth = 15%
)
log on
(
name = 'bankDB_log',
filename = 'e:\bank\bankDB_log.ldf',
size = 2MB,
filegrowth = 1MB
)
go
--------------------创建数据表---------------------
use bankDB
gocreate table userInfo
(
customerID int identity(1,1) not null,
customerName varchar(10) not null,
PID char(18) not null,
telphone char(13) not null,
adress varchar(100)
)alter table userInfo
add constraint PK_customerID primary key(customerID)
alter table userInfo
add constraint CK_PID check(PID like '[1-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]' or
PID like '[1-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]X' or
PID like '[1-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]')
alter table userInfo
add constraint CK_telphone check(telphone like '13[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]' or telphone like '[0-9][0-9][0-9][0-9]-[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]')
alter table userInfo
add constraint DF_telphone default('地址不详') for adress
alter table userInfo
add constraint UQ_PID unique(PID)create table cardInfo
(
cardID char(19) not null,
curType varchar(5) not null,
savingType varchar(6) not null,
openDate datetime not null,
openMoney money not null,
balance money not null,
pass char(6) not null,
IsReportLoss char(2) not null,
customerID int not null
)alter table cardInfo
add constraint FK_customerID foreign key(customerID) references userInfo(customerID)
alter table cardInfo
add constraint PK_cardID primary key(cardID)
alter table cardInfo
add constraint DF_openDate default(getdate()) for openDate
alter table cardInfo
add constraint DF_pass default('888888') for pass
alter table cardInfo
add constraint DF_curType default('RMB') for curType
alter table cardInfo
add constraint CK_openMoney check(openMoney > 1)
alter table cardInfo
add constraint CK_balance check(balance > 1)
alter table cardInfo
add constraint CK_pass check(pass like '[0-9][0-9][0-9][0-9][0-9][0-9]')
alter table cardInfo
add constraint DF_cardID default('1010 3576 ' + convert(varchar(4),convert(int,rand()*10000)) + ' ' +convert(varchar(4),convert(int,rand()*10000))) for cardID
alter table cardInfo
add constraint DF_IsReportLoss default('否') for IsReportLoss
alter table cardInfo
add constraint CK_IsReportLoss check(IsReportLoss like '是' or IsReportLoss like '否')
alter table cardInfo
add constraint CK_savingType check(savingType like '定期' or savingType like '活期' or savingType like '定活期')create table transInfo
(
transDate datetime not null,
cardID char(19) not null,
transType char(4) not null,
transMoney money not null,
remark varchar(100)
)alter table transInfo
add constraint DF_transDate default(getdate()) for transDate
alter table transInfo
add constraint FK_cardID foreign key(cardID) references cardInfo(cardID)
alter table transInfo
add constraint CK_stransType check(transType like '存入' or transType like '支取')
alter table transInfo
add constraint CK_transMoney check(transMoney > 0)go
--------------------创建开户用户卡信息视图---------
create view v_cus
as
select customerName, cardID,curType,savingType,telphone,adress
from cardInfo inner join userInfo on cardInfo.customerID = userInfo.customerID
where datediff(wk,openDate,getdate()) = 0-----------------------修改密码--------------------
create proc changePWD
@cardID char(19),
@newpwd char(6),
@oldpwd char(6) = '888888'
as
declare @temppwd int
if((select count(*) from cardInfo where cardID = @cardID) = 0)
begin
print '您输入的卡号不存在!'
return
end
select @temppwd = pass from cardInfo where cardID = @cardID
if(@temppwd = @oldpwd)
begin
update cardInfo set pass = @newpwd where cardID = @cardID
if(@@error = 0)
print '密码修改成功!'
else
print '密码修改失败!'
end
else
print '您输入的原始密码不对,不能修改密码!'----------------------银行卡挂失-------------------
create proc ReportLoss
@cardID char(19),
@PID char(18)
as
if((select count(*) from cardInfo where cardID = @cardID) = 0)
begin
print '您输入的卡号不存在!'
return
end
if((select IsReportLoss from cardInfo where cardID = @cardID) = '是')
begin
print '该卡已挂失!'
return
end
if((select PID from userInfo where customerID = (select customerID from cardInfo where cardID = @cardID)) = @PID)
begin
update cardInfo set IsReportLoss = '是' where cardID = @cardID
if(@@error = 0)
print '挂失成功!'
else
print '挂失失败!'
end
else
begin
print '您输入的身份证错误!不能挂失!'
return
end----------------------取消银行卡挂失-------------------
create proc CancelReportLoss
@cardID char(19),
@PID char(18)
as
if((select count(*) from cardInfo where cardID = @cardID) = 0)
begin
print '您输入的卡号不存在!'
return
end
if((select IsReportLoss from cardInfo where cardID = @cardID) = '否')
begin
print '该卡没有挂失!不能进行此项操作!'
return
end
if((select PID from userInfo where customerID = (select customerID from cardInfo where cardID = @cardID)) = @PID)
begin
update cardInfo set IsReportLoss = '否' where cardID = @cardID
if(@@error = 0)
print '取消挂失成功!'
else
print '取消挂失失败!'
end
else
begin
print '您输入的身份证错误!不能取消挂失!'
return
end----------------------统计银行的资金流通余额和盈利结算--------------------create proc StatMoney
as
select ((select sum(transMoney) as 资金流通余额 from transInfo where transType like '存入') - (select sum(transMoney) as 资金流通余额 from transInfo where transType like '支取'))
as 资金流通余额 select ((select sum(transMoney) as 资金流通余额 from transInfo where transType like '存入')*0.008
- (select sum(transMoney) as 资金流通余额 from transInfo where transType like '支取')*0.003)
as 盈利结算 ---------------------查询本周开户的卡号,显示该卡的信息-------------------
create proc SearchNewCus
as
print '本周开户卡号信息'
select * from v_cus -----------------------查询本月交易金额最高的卡号-------------------------
create proc SearchHigh
as
select top 1 cardID, sum(transMoney) as 交易金额 from transInfo
group by cardID------------------------------查询挂失帐号的客户信息----------------------
create proc SearchLossCus
as
print '挂失帐号客户信息'
select * from userInfo where customerID = (select customerID from cardInfo where IsReportLoss = '是')--------------------------催款提醒业务------------------------------------
create proc Awoke
as
select telphone, balance, customerName, cardID
from cardInfo inner join userInfo on cardInfo.customerID = userInfo.customerID
where balance < 200-------------------------银行开户-----------------------------------------
create proc OpenUser
@curType varchar(5),
@savingType varchar(6),
@openMoney money,
@PID char(18),
@telphone char(13),
@customerName varchar(10)
as
begin tran OpenU
declare @tag int
declare @tempID varchar(10)
set @tag = 0 insert into userInfo (customerName,PID,telphone) values (@customerName, @PID, @telphone)
set @tag = @tag + @@error
if(@tag = 0)
set @tempID = (select customerID from userInfo where PID = @PID)
insert into cardInfo (curType, savingType, openMoney, balance, customerID) values (@curType, @savingType, @openMoney, @openMoney, @tempID)
set @tag = @tag + @@error
if(@tag = 0)
begin
print '开户成功!'
commit tran
end
else
begin
print '开户失败!'
rollback tran
end-----------------------------客户存款-------------------------------------
create proc SaveMoney
@cardID char(19),
@transMoney money,
@transType char(4) = '存入'
as
if((select IsReportLoss from cardInfo where cardID = @cardID) = '是')
begin
print '该卡已挂失!无法对其进行操作!'
return
end
begin tran Saving
declare @tag int
set @tag = 0 insert into transInfo (cardID, transType, transMoney) values (@cardID, @transType, @transMoney)
set @tag = @tag + @@error
update cardInfo set balance = balance + @transMoney where cardID = @cardID
set @tag = @tag + @@error
if(@tag = 0)
begin
print '存款成功!'
commit tran
end
else
begin
print '存款失败!'
rollback tran
end ------------------------------客户取款------------------------------------
create proc DrawMoney
@cardID char(19),
@transMoney money,
@transType char(4) = '支取'
as
if((select IsReportLoss from cardInfo where cardID = @cardID) = '是')
begin
print '该卡已挂失!无法对其进行操作!'
return
end
begin tran Drawing
declare @tag int
set @tag = 0 insert into transInfo (cardID, transType, transMoney) values (@cardID, @transType, @transMoney)
set @tag = @tag + @@error
update cardInfo set balance = balance - @transMoney where cardID = @cardID
set @tag = @tag + @@error
if(@tag = 0)
begin
print '取款成功!'
commit tran
end
else
begin
print '取款失败!'
rollback tran
end----------------------------转帐------------------------------------------
create proc Transfer
@cardID_out char(19),
@cardID_in char(19),
@tranMoney money
as
if((select count(*) from cardInfo where cardID = @cardID_out or cardID = @cardID_in) <> 2)
begin
print '请确认两张卡是否都存在!'
return
end
if((select IsReportLoss from cardInfo where cardID = @cardID_out) = '是')
begin
print @cardID_out + '该卡已挂失!无法对其进行操作!'
return
end
if((select IsReportLoss from cardInfo where cardID = @cardID_in) = '是')
begin
print @cardID_in + '该卡已挂失!无法对其进行操作!'
return
end
begin tran TransMoney
declare @tag int
set @tag = 0 update cardInfo set balance = balance - @tranMoney where cardID = @cardID_out
set @tag = @tag + @@error
update cardInfo set balance = balance + @tranMoney where cardID = @cardID_in
set @tag = @tag + @@error
if(@tag = 0)
begin
print '转帐成功!'
commit tran
end
else
begin
print '转帐失败!'
rollback tran
end

❷ 求高人设计一个小型的数据库管理系统

卧槽。老师是叫你自己写的吧。

❸ 小型数据库管理系统设计

系统演示视频

❹ 小型数据库系统设计

#include<stdio.h>
#include<stdlib.h>

char* month_str[]={"January","February","March","April","May","June","July","August","September","October","November","December"};
char* week[]={"Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"};

int IsLeapYear(int year) /*find out the year is leap year or not*/
{
if((year%4==0&&year%100!=0)||(year%400==0))
return 1;
else
return 0;

}
int month_day(int year,int month)
{
int mon_day[]={31,28,31,30,31,30,31,31,30,31,30,31};
if(IsLeapYear(year)&&month==2)
return 29;
else
return(mon_day[month-1]);

}
int DaySearch(int year,int month,int day) /*search what day this day is*/
{
int c=0;
float s;
int m;
for(m=1;m<month;m++)
c=c+month_day(year,m);
c=c+day;
s=year-1+(float)(year-1)/4+(float)(year-1)/100+(float)(year-1)/400-40+c;
return ((int)s%7);
}

int PrintAllYear(int year)/*print the all year*/
{
int temp;
int i,j;
printf("\n\n%d Calander\n",year);
for(i=1;i<=12;i++)
{
printf("\n\n%s(%d)\n",month_str[i-1],i);
printf("0 1 2 3 4 5 6 \n");
printf("S M T W T F S \n\n");
temp=DaySearch(year,i,1);
for(j=1;j<=month_day(year,i)+temp;j++)
{
if(j-temp<=0)
printf(" ");
else if(j-temp<10)
printf("%d ",j-temp);
else
printf("%d ",j-temp);

if(j%7==0)
printf("\n");
}
}
return 0;
}

int main()
{
int option,da;
char ch;
int year,month,day;
printf("Copyright @ 2005 TianQian All rights reserved!:):):)");
printf("\n\nWelcome to use the WanNianLi system!\n");

while(1)
{
printf("\nPlease select the service you need:\n");
printf("\n1 Search what day the day is");
printf("\n2 Search whether the year is leap year or not");
printf("\n3 Print the calander of the whole year");
printf("\n4 Exit\n");
scanf("%d",&option);

switch(option)
{
case 1:
while(1)
{
printf("\nPlease input the year,month and day(XXXX,XX,XX):");
scanf("%d,%d,%d,%c",&year,&month,&day);
da=DaySearch(year,month,day);
printf("\n%d-%d-%d is %s,do you want to continue?(Y/N)",year,month,day,week[da]);
fflush(stdin);
scanf("%c",&ch);
if(ch=='N'||ch=='n')
break;
}
break;
case 2:
while(1)
{
printf("\nPlease input the year which needs searched?(XXXX)");
scanf("%d",&year);
if(IsLeapYear(year))
printf("\n%d is Leap year,do you want to continue?(Y/N)",year);
else
printf("\n%d is not Leap year,do you want to continue(Y/N)?",year);
fflush(stdin);
scanf("%c",&ch);
if(ch=='N'||ch=='n')
break;
}
break;
case 3:
while(1)
{
printf("\nPlease input the year which needs printed(XXXX)");
scanf("%d",&year);
PrintAllYear(year);
printf("\nDo you want to continue to print(Y/N)?");
fflush(stdin);
scanf("%c",&ch);
if(ch=='N'||ch=='n')
break;
}
break;
case 4:
fflush(stdin);
printf("Are you sure?(Y/N)");
scanf("%c",&ch);
if(ch=='Y'||ch=='y')
exit(0);
break;
default:
printf("\nError:Sorry,there is no this service now!\n");
break;
}

}

return 0;
}

❺ 用数据库做一个小型设备管理系统

课题1. 《设备管理信息系统》包括的实体类型有:n 固定资产(资产编号,资产名称,型号规格,计量单位,价值,制造厂,出厂日期)n 部门(部门编号,部门名称,负责人)n 折旧单(折旧单编号,年折旧率,年折旧额,开始使用日期,全部使用年限,已使用年数,尚可使用年限)n 大修理单(修理单编号,修理日期,修理时限,修理费用,经手人)n 内部转移单(转移单编号,转移日期,转出部门,转入部门),即该设备从一个部门调拨到另一个部门n 报废单(报废单编号,报废日期,经手人),指该设备已经到了使用年限,扔到废品仓库里n 清理单(清理单编号,资产原值,累计折旧金额,清理金额),从废品仓库里清理掉。n 《设备管理信息系统》包括的具体操作:n 自行补充实体之间的联系n 输入数据,每个表不少于10行数据,数据必须是有意义的n 实现设备报废过程n 实现设备的内部转移n 统计固定资产的已进行的大修费用n 列出两个基本表的插入、更新和删除记录的操作(各举1例)n 自行补充8至10个SQL操作,如信息分院的固定资产价值,列出所有的“计算机”设备清单等等

❻ 设计一个数据库系统要怎么设计

数据库系统只有一种语言,这种语言叫SQL.
你可以使用PowerDesigner来进行数据库PDM和CDM设计,支持当前各种主流的数据库数据格式.

❼ 小型数据库管理系统的设计

小规模的数据库关系系统

❽ 如何用prontpage和SQL设计一个小型的数据库系统(学生综合测评排名系统)

首先在SQL中利用企业管理器或向导建立一个数据库,命名为学生管理系统, 启动SQL Sever服务,运行企业管理器,单击要创建数据库的服务器左边的加号图标,展开树形目录,在“数据库”节点上右击鼠标,在弹出的快捷菜单中选则“新建数据库”命令,然后按照提示一步步建立数据库,不再详细叙述。 假设学生管理系统下有三个表,分别为学生表、课程表、修课表,表的结构

热点内容
openwrt编译零基础 发布:2025-01-21 01:53:30 浏览:19
视频聊天室源码php 发布:2025-01-21 01:39:29 浏览:938
游戏脚本xp 发布:2025-01-21 01:25:48 浏览:209
cfa建模需要什么电脑配置 发布:2025-01-21 01:16:41 浏览:96
配置获取异常怎么办 发布:2025-01-21 01:16:29 浏览:641
植发都加密吗 发布:2025-01-21 01:16:28 浏览:735
工商保障卡原始密码是什么 发布:2025-01-21 01:09:33 浏览:786
sqlserver2012sp 发布:2025-01-21 01:06:23 浏览:888
惊变在线看ftp 发布:2025-01-21 01:06:20 浏览:233
用近似归算法 发布:2025-01-21 00:51:56 浏览:517