设为首页 加入收藏

TOP

SQL语句
2019-09-03 01:13:30 】 浏览:13
Tags: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

 

】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇.NET 发布网站步骤 下一篇Visual Studio 2017 RC 初探安装

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目