Step by step to resolve Second, the database is designed three-tier architecture camp .NET

To develop user management system, we must first understand the needs, now we need to give a simple, user table, assuming that there are two roles with a field departID judge, administrators and staff,
We must first build a user table and a department table 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,
	[age] [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 
(
	[id] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) 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 
(
	[id] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]
After construction of the database table and began to write stored procedures, insert a piece of data:
CREATE PROCEDURE [dbo].[spInsertCustom]
@cname nvarchar(50),
@ename nvarchar(50),
@age int,
@departID int,
@password nvarchar(50)
AS
BEGIN
insert into custom(cname,departID,age,ename,password) values (@cname,@departID,@age,@ename,@password)
END

RETURN @@Identity
create PROCEDURE [dbo].[spInsertDepartment]
@departname nvarchar(50),
@description nvarchar(50)
AS
BEGIN
	insert into department(departname,description)values(@departname,@description)
END

RETURN @@Identity
It is now building two updates a data storage process:
CREATE PROCEDURE [dbo].[spupdatecustom] 
@id int,
@cname nvarchar(50),
@departID int,
@age int,
@ename nvarchar(50),
@password nvarchar(50)
AS
BEGIN
	update 
       custom 
    set
    cname = @cname,
    departID = @departID,
    age = @age,
    ename = @ename,
    password = @password
    where id = @id
END
COMMIT TRAN
create procedure spupdatedepart
(
@departname nvarchar(50),
@description nchar(10),
@id int
)
as
UPDATE [dbo].[department]
   SET [departname] = @departname
      ,[description] = @departname
 WHERE id=@id

Remove all users then create two stored procedures:

CREATE PROCEDURE [dbo].[spGetcustom]
	
AS
BEGIN
	select * from custom order by id desc
END
create PROCEDURE [dbo].[spGetAlldepartment]

AS
BEGIN
	select * from department 
END

Create a stored procedure and then remove the data according to an ID:

CREATE PROCEDURE [dbo].[spGetcustomer]
@id int
AS
BEGIN
 select * from custom where id = @id
END

A stored procedure is built according to the department Natori department ID:

create PROCEDURE [dbo].[spGetdepartmenter]
@departname nvarchar(50)
AS
BEGIN
	select * from department where departname = @departname
END

To build two deleting data according to the ID stored procedure:

create PROCEDURE [dbo].[spDeletecustom]
@id int
AS
BEGIN
	 delete custom where id = @id
END
CREATE PROCEDURE spdeletedepart
@id int
AS
BEGIN
	delete department where id = @id
END
GO

Database design is completed, this is just a simple example. Paizhuan welcome.

SQLHelper designed to explain the next time.

Reproduced in: https: //www.cnblogs.com/springyangwc/archive/2011/03/22/1991773.html

Guess you like

Origin blog.csdn.net/weixin_34284188/article/details/93340865