存储过程临时笔记

use master
go

if exists (select * from sysdatabases where name='guotao')
drop database test
go

create database test

go

use teste
go

create table test
([id] int identity(1000,1) primary key,
username varchar (30) unique,
userpassword varchar(30)
)
go

insert into test(username,userpassword)
values('test','678678679867')
insert into test(username,userpassword)
values('test','865876876')
go

--查询所有信息
create proc SelectAll_Proc
as
begin
   select * from test
end
go


exec SelectAll_Proc
go

--添加数据
create proc InsertUser_Proc
(
@username varchar (30),
@userpassword varchar (30)
)
as
begin
   insert into test values (@username,@userpassword)
end
go


exec InsertUser_Proc '滔滔','78657545878'
go


--修改数据
create proc UpdateUser_proc
(
@id int,
@username varchar (30),
@userpassword varchar (30)
)
as
begin
    update test set username=@username,userpassword=@userpassword    where [id]=@id
end
go

exec UpdateUser_proc '1001','test','875687975'
go

--删除数据

create proc DeleteUser_proc
(
@id int
)
as
begin
    delete from test   where [id]=@id
end
go

exec DeleteUser_proc '1000'
go