数据库开发是什么意思数据库不就是简单的做表格吗哪里用到开发了能开发出什么用什么开发

数据库开发是什么意思数据库不就是简单的做表格吗哪里用到开发了能开发出什么用什么开发,第1张

数据库开发不是简单地做表格,它是将大量的数据进行分类,按照一定规则进行表格设计,表与表之间有一定结构或关系,大量的数据都放在这些表(库)中,表与表之间可以计算、筛选、组合新表提供数据查询,还可以设计成报表提供数据服务。开发软件很多,常用的有ACCESS、SQL等。

一.数据表和字段的设计

表设计原则

标准化和规范化

数据的标准化有助于消除数据库中的数据冗余 标准化有好几种形式 我们在这里采用Third Normal Form( NF) 因为 NF在性能 扩展性和数据完整性方面达到了最好平衡 遵守 NF 标准的数据库某个表只包括其本身基本的属性 当不是它们本身所具有的属性时需进行分解 表之间的关系通过外键相连接 它具有以下特点 有一组表专门存放通过键连接起来的关联数据

考虑各种变化

在设计数据库的时候考虑到哪些数据字段将来可能会发生变更

字段设计原则 ) 每个表中都应该添加的 个有用的字段 即要求每张数据表中字段不得少于 个 ) 选择数字类型和文本类型尽量充足 在字段类型为数字或文本时 其长度最好比实际所需的大一些 ) 增加自动增长的 *** 作ID字段(czid) ) 增加记录创建的日期字段(CreateDate) ) 增加删除标记字段(isvoid) 在表中包含一个 删除标记 字段 这样就可以把行标记为删除 在关系数据库里不单独删除某一行 一般采用清除数据程序而且要仔细维护索引整体性

二.键和索引的设计

键选择原则

)为关联字段创建外键 )所有的键都必须唯一 )避免使用复合键 )外键总是关联唯一的键字段

使用系统生成的主键设计数据库的时候采用系统生成的键作为主键 那么实际控制了数据库的索引完整性 这样 数据库和非人工机制就有效地控制了对存储数据中每一行的访问 采用系统生成键作为主键还有一个优点 当拥有一致的键结构时 找到逻辑缺陷很容易 不要用用户的键(不让主键具有可更新性)在确定采用什么字段作为表的键的时候 小心用户将要编辑的字段 通常的情况下不要选择用户可编辑的字段作为键

可选键有时可做主键把可选键进一步用做主键 可以拥有建立强大索引的能力

索引使用原则

索引是从数据库中获取数据的最高效方式之一 %的数据库性能问题都可以采用索引技术得到解决

索引外键大多数数据库都索引自动创建的主键字段 但是可别忘了索引外键 它们也是经常使用的键 比如运行查询显示主表和所有关联表的某条记录就用得上 不要索引大型字段(有很多字符) 这样作会让索引占用太多的存储空间

不要索引常用的小型表不要为小型数据表设置任何键 假如它们经常有插入和删除 *** 作就更别这样作了 对这些插入和删除 *** 作的索引维护可能比扫描表空间消耗更多的时间

三 数据完整性设计

完整性实现机制 实体完整性 主键

参照完整性 父表中删除数据 级联删除 受限删除 置空值父表中插入数据 受限插入 递归插入父表中更新数据 级联更新 受限更新 置空值

DBMS对参照完整性可以有两种方法实现 外键实现机制(约束规则)和触发器实现机制

用户定义完整性 NOT NULL CHECK 触发器

用约束而非商务规则强制数据完整性采用数据库系统实现数据的完整性 这不但包括通过标准化实现的完整性而且还包括数据的功能性 在写数据的时候还可以增加触发器来保证数据的正确性 不要依赖于商务层保证数据完整性 它不能保证表之间(外键)的完整性所以不能强加于其他完整性规则之上

强制指示完整性在有害数据进入数据库之前将其剔除 激活数据库系统的指示完整性特性 这样可以保持数据的清洁而能迫使开发人员投入更多的时间处理错误条件

使用查找控制数据完整性控制数据完整性的最佳方式就是限制用户的选择 只要有可能都应该提供给用户一个清晰的价值列表供其选择 这样将减少键入代码的错误和误解同时提供数据的一致性

采用视图为了在数据库和应用程序代码之间提供另一层抽象 可以为应用程序建立专门的视图而不必非要应用程序直接访问数据表 这样做还等于在处理数据库变更时给你提供了更多的自由

lishixinzhi/Article/program/SQL/201311/16258

--部门信息表

create table Departments

(

d_id int not null primary key,

d_name varchar(20) not null,

)

use POS

--员工信息表

create table employee

(

e_id int not null primary key,

ename varchar(10) not null,

esex char(2) not null,

constraint CK_yg check ( esex in('男','女')),

eduties varchar(10) not null,

epassword int not null,

eleve char(4) not null,

eshengfen int not null,

d_id int not null,

constraint FK_ano foreign key(d_id) references Departments(d_id)

)

--供应商信息表

create table offer

(

o_id int not null primary key,

oname varchar(10) not null,

oaddress varchar(20) not null,

post int not null,

phonenumber int not null,

tax int not null,

obanknumber int not null,

obank varchar(20) not null,

ocontact varchar(10) not null,

onote varchar(20)

)

--会员信息表

create table Member

(

Mno int not null primary key,

Mname varchar(10) not null,

Msex char(2) not null,

constraint CK_ya check ( Msex in('男','女')),

Mid int not null,

Mamount money not null,

Mintegral int not null

)

--商品信息表

create table product

(

p_id int not null primary key,

pclass varchar(20) not null,

pquantity int not null,

pprice money not null,

pname varchar(10) not null

)

--入库信息表

create table import

(

i_id int identity(0 ,1) not null primary key ,

idate datetime ,

p_id int ,

constraint FK_an foreign key(p_id) references product(p_id),

Punit int ,

iprice money,

Sales_price money ,

iquantity int,

Total_amount money,

o_id int ,

constraint FK_cn foreign key(o_id) references offer(o_id),

Salesman_No int ,

constraint FK_on foreign key(Salesman_No) references employee(e_id)

)

--销售出货单主信息表

create table xiaoshouzhu

(

xdate datetime not null,

xtotal_amount money not null,

xsfxj char(2) not null,

xsfmember char(2) not null,

Mno int not null,

constraint FK_ak foreign key(Mno) references Member(Mno),

MRsyybh int not null,

constraint FK_ek foreign key(MRsyybh) references employee(e_id)

)

--销售出货单子信息(

create table xiaoshouzi

(

xzRno int not null,

quantity int not null,

price money not null,

zkbl float not null,

amount money not null

)

--1当在商品信息表中添加一条商品信息时,同时将该商品信息记录在入库信息表中(触发器)

create trigger triger_1

on product

after insert

as

begin

declare @a int, @b varchar(20),@c int,@d money, @e varchar(20)

select @a = p_id ,@b = pclass,@c = pquantity , @d = pprice ,@e = pname from inserted

insert into import(idate,p_id,Punit,iprice,Sales_price,iquantity,Total_amount,p_id,Salesman_No)

values (null ,@a , null , null,@d, @c ,null , null,null)

end

--2销售一件商品时,将该销售信息记录在销售出货单子信息表中,并从入库信息表中将对应产品的数量减一(触发器)

create trigger triger_2

on xiaoshouzi

after insert

as

begin

update import

set iquantity = (iquantity -1)

where p_id =(select p_id from inserted)

end

--3撤消某部门时,将该部门记录从部门表中删除,并将员工表中对应该部门的员工记录删除(触发器)

create trigger triger_3

on Departments

after delete

as

begin

delete employee

where d_id = (SELECT d_id from deleted)

end

--4当更新商品信息表中商品单价时,同时更改入库信息表中对应商品的销售价格(触发器)

create trigger triger_4

on product

after update

as

begin

update import

set Sales_price = (select pprice from inserted)

where p_id = (select p_id from deleted )

end

--5向销售出货单子信息表中添加一条信息,并输出表中商品总金额。(存储过程)

create procedure productpricing_1

@total_amount money output,

@a int,

@b int,

@c money,

@d float,

@e money

as

begin

insert into xiaoshouzi

values (@a , @b ,@c ,@d ,@e);

select @total_amount = (price quantity) from xiaoshouzi

end

--6输出副食类商品的入库平均价格。(存储过程)

create procedure productpricing_2

@avg_price money output

as

begin

select @avg_price = avg(pprice)

from product

where pname = '副食类'

end

--7输出收银员“刘明”在2010年3月6号销售的商品总金额(存储过程)

create procedure productpricing_3

@total_amount money output

as

begin

select @total_amount = DRtotal_amount

from xiashouzhu , employee

where xiaoshouzhuMRsyybh = employeee_id and employeeename = '刘明' and xiaoshouzhuxdate = '2010年3月6号'

end

以上就是关于数据库开发是什么意思数据库不就是简单的做表格吗哪里用到开发了能开发出什么用什么开发全部的内容,包括:数据库开发是什么意思数据库不就是简单的做表格吗哪里用到开发了能开发出什么用什么开发、数据库开发规范详细介绍[1]、数据库开发等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/sjk/10199078.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-06
下一篇 2023-05-06

发表评论

登录后才能评论

评论列表(0条)

保存