SQL语句

--创建数据库

create database ShoppingManage
on
(

--数据库文件名称
name = 'ShoppingManage.mdf',

--数据库路径(包含数据库文件名称)
filename = 'E:\资料\Data\ShoppingManage.mdf'
)

--删除数据库

drop database 数据库名称

--例如drop database ShoppingManage

--创建一个用户表
create table [User]
(
UserId int primary key identity(1,1), --用户ID
UserName nvarchar(50) not null, --用户账号
UserPwd nvarchar(30) , --用户密码
UserCreateTime datetime default(getdate()),--用户创建时间
UserLastLoginTime datetime, --最后登录时间
UserLoginCount int default(0) --登录次数
)

--添加数据
insert into [User](UserName,UserPwd) values('王亦欣','123456')

--删除表不会留下痕迹
truncate table 表名 --例如truncate table [User]

--删除表会留下痕迹 

drop table 表名 --例如drop table [User]

--创建一个可以实现分页的存储过程

create proc SP_Pager

--从第几条数据开始查询
@startIndex int,

--从第几条数据结束查询
@endIndex int
as
select * from (select *,ROW_NUMBER() over(order by Id) as rid from Products ) temp where rid>=@startIndex and rid<=@endIndex ;

--执行存储过程

exec SP_Pager startIndex ,endIndex 例如exec SP_Pager 1,20是查询Products表中按ID排序之后的第一条数据到第20条的数据

--执行有参有返回值的存储过程

declare @number nvarchar(4000);
exec 存储过程名称 输入参数,输入参数,@number(输出参数);

select @number

 

posted @ 2017-02-07 11:25  凤山朱德  阅读(331)  评论(0编辑  收藏  举报