首先,在写数据库时需要遵循以下几个原则:
数据库的命名规范:
方便代码的交流和维护
不影响代码的效率,不与大众习惯冲突
使代码更美观,阅读更方便
使代码的逻辑更清晰,更易于理解
术语的定义:
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='吴娇'
这里仅进行了部分代码的实现。
如有哪里不正确望指出!
到此这篇关于图书管理系统的sqlserver数据库设计示例的文章就介绍到这了,更多相关图书管理系统 sqlserver数据库设计内容请搜索www.887551.com以前的文章或继续浏览下面的相关文章希望大家以后多多支持www.887551.com!