2011-03-22 19:15
by
spring yang,
3313
visits,
网摘,
收藏,
编辑
要开发用户管理系统,我们首先要了解需求,现在就举一个简单需求,用户表,假设有两种角色用一个字段departID来判断,管理员和员工,
我们要先建一个用户表custom和一个部门表department:
CREATE TABLE [dbo].[custom]( |
[id] [ int ] IDENTITY(1,1) NOT NULL, |
[cname] [nvarchar](50) COLLATE Chinese_PRC_CI_AS NOT NULL, |
[departID] [ int ] NOT NULL, |
[ename] [nvarchar](50) COLLATE Chinese_PRC_CI_AS NOT NULL, |
[password] [nvarchar](50) COLLATE Chinese_PRC_CI_AS NOT NULL, |
CONSTRAINT [PK_custom] PRIMARY KEY CLUSTERED |
)WITH
(PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF,
ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY] |
CREATE TABLE [dbo].[department]( |
[id] [ int ] IDENTITY(1,1) NOT NULL, |
[departname] [nvarchar](50) COLLATE Chinese_PRC_CI_AS NOT NULL, |
[description] [nchar](10) COLLATE Chinese_PRC_CI_AS NOT NULL, |
CONSTRAINT [PK_department] PRIMARY KEY CLUSTERED |
)WITH
(PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF,
ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY] |
建完数据库表后,开始写存储过程,插入一条数据:
CREATE PROCEDURE [dbo].[spInsertCustom] |
insert into custom(cname,departID,age,ename,password) values (@cname,@departID,@age,@ename,@password) |
create PROCEDURE [dbo].[spInsertDepartment] |
@departname nvarchar(50), |
@description nvarchar(50) |
insert into department(departname,description)values(@departname,@description) |
现建两个更新一条数据的存储过程:
CREATE PROCEDURE [dbo].[spupdatecustom] |
create procedure spupdatedepart |
@departname nvarchar(50), |
UPDATE [dbo].[department] |
SET [departname] = @departname |
,[description] = @departname |
再新建两个取出所有用户的存储过程:
CREATE PROCEDURE [dbo].[spGetcustom] |
select * from custom order by id desc |
create PROCEDURE [dbo].[spGetAlldepartment] |
再新建一个根据ID取出一条数据的存储过程:
CREATE PROCEDURE [dbo].[spGetcustomer] |
select * from custom where id = @id |
现建一个根据部门名取部门ID的存储过程:
create PROCEDURE [dbo].[spGetdepartmenter] |
select * from department where departname = @departname |
再建两个根据ID删除数据的存储过程:
create PROCEDURE [dbo].[spDeletecustom] |
delete custom where id = @id |
CREATE PROCEDURE spdeletedepart |
delete department where id = @id |
数据库设计就建好了,这只是一个简单的示例.欢迎拍砖.
下次讲解SQLHelper的设计.
|