图书管理系统的sqlserver数据库设计示例
作者:honeysyt_ 时间:2024-01-18 08:50:50
首先,在写数据库时需要遵循以下几个原则:
数据库的命名规范:
方便代码的交流和维护
不影响代码的效率,不与大众习惯冲突
使代码更美观,阅读更方便
使代码的逻辑更清晰,更易于理解
术语的定义:
Pascal方法:将标识符的首字母和后面连接的每个单词的首字母都大写 ,可以对三字母或更多的字符的标识符使用。例如:BackColor
Camel方法:标识符的首字母小写,而后面连接的单词首字母都大写。例如:backColor
基本原则:
以大小写敏感编写SQL语句
尽量使用Unicode数据类型
优先使用参数化SQL查询代替拼接SQL查询
禁止使用拼音+英语的方式来命名SQL对象或变量
尽量使用存储过程代替SQL语句
大写t-sql语言的所有关键字,谓词和系统函数
其次:
对数据库进行分析
1.分析数据库,根据图书管理系统的需求分析,列出表
图书类别:主要包括图书的编号,类别名称等
图书基本信息:主要包括图书编号,图书名称,类别编号等
读者类别:主要包括类别编号,类别名称,借书最大量等
读者基本信息:主要包括读者编号,读者姓名,性别,住址,读者类别
借阅表:主要包括记录编号,读者编号,图书编号,借出日期,还入日期。
2。根据分析的数据库画出实体图
图书类别:
图书基本信息:
读者类别:
读者基本信息:
借阅表:
3.画出数据库E-R图
4.数据表关系图:
5.根据需求,给出数据字典
6.对数据库进行增、删、改、查相关操作,编写sql脚本实现。
CREATE DATABASE BMS
IF OBJECT_ID(N't_booktype',N'U') IS NOT NULL
DROP TABLE t_booktype
CREATE TABLE t_booktype(
typeno int primary key not null,
typename varchar(30) not null
)
IF OBJECT_ID(N't_books',N'U') IS NOT NULL
DROP TABLE t_books
CREATE TABLE t_books(
bookno int primary key not null,
bookname varchar(30) not null,
typeno int not null
)
IF OBJECT_ID(N't_readertype',N'U') IS NOT NULL
DROP TABLE t_readertype
CREATE TABLE t_readertype(
readertypeno int primary key not null,
readername varchar(30) not null,
lendnumber int not null
)
IF OBJECT_ID(N't_readerinfo',N'U') IS NOT NULL
DROP TABLE t_readerinfo
CREATE TABLE t_readerinfo(
readerno int primary key not null,
readername varchar(30) not null,
readeraddress varchar(30) not null,
readertypeno int not null
)
IF OBJECT_ID(N't_lendbook',N'U') IS NOT NULL
DROP TABLE t_lendbook
CREATE TABLE t_lendbook(
recordno int primary key not null,
readerno int not null,
bookno int not null,
lendtime datetime ,
returntime datetime
)
INSERT INTO t_booktype
VALUES('1005','悬疑类')
INSERT INTO t_books
VALUES('1025','盗墓笔记','1005')
INSERT INTO t_readertype
VALUES('0005','黄秋萍',20)
INSERT INTO t_readerinfo
VALUES('0005','黄秋萍','南昌市','0005')
INSERT INTO t_lendbook
VALUES('0005','0002','1013','2004-07-28','2004-11-16')
SELECT *
FROM t_books
UPDATE t_books
SET bookname='深入理解计算机系统'
WHERE bookno='1001'
UPDATE t_readertype
SET readername='吴娇'
WHERE readertypeno='0001'
SELECT *
FROM t_readerinfo
--查询图书名字
SELECT bookname
FROM t_books
--查询图书类别
SELECT typename
FROM t_booktype
--查询名字叫吴娇的借书记录
SELECT t_readerinfo.readername,t_lendbook.lendtime,t_lendbook.returntime
FROM t_readerinfo join t_lendbook on t_readerinfo.readerno=t_lendbook.readerno
WHERE t_readerinfo.readername='吴娇'
这里仅进行了部分代码的实现。
如有哪里不正确望指出!
来源:https://blog.csdn.net/qq_37647529/article/details/78439260
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
Python中扩展包的安装方法详解
![](https://img.aspxhome.com/file/2023/8/83848_0s.png)
vue-element如何实现动态换肤存储
![](https://img.aspxhome.com/file/2023/1/133081_0s.png)
腾讯网QQ首页诞生的艰辛历程
![](https://img.aspxhome.com/file/UploadPic/200811/6/01-77s.jpg)
Javascript Math对象
![](https://img.aspxhome.com/file/2023/6/129076_0s.jpg)
pyqt5 设置窗体透明控件不透明的操作
![](https://img.aspxhome.com/file/2023/9/118569_0s.jpg)
django Serializer序列化使用方法详解
python3调用windows dos命令的例子
Python利用3D引擎写一个Pong游戏
![](https://img.aspxhome.com/file/2023/4/131704_0s.png)
Python中常用的内置函数
![](https://img.aspxhome.com/file/2023/8/79748_0s.png)
基于Django实现日志记录报错信息
vue实现简单全选和反选功能
![](https://img.aspxhome.com/file/2023/2/128872_0s.gif)
解决缩小图标变样问题
![](https://img.aspxhome.com/file/UploadPic/200710/8/2007108191659246s.png)
利用Java正则表达式校验邮箱与手机号
mysql存储过程中使用游标的实例
Python3实现打格点算法的GPU加速实例详解
![](https://img.aspxhome.com/file/2023/0/97710_0s.png)
django之跨表查询及添加记录的示例代码
关于Golang中for-loop与goroutine的问题详解
停止事件冒泡和阻止浏览器默认行为的脚本
Python3 json模块之编码解码方法讲解
python游戏实战项目之俄罗斯方块的魅力
![](https://img.aspxhome.com/file/2023/3/100833_0s.jpg)