Sqlserver 存储过程大集合
=================分页==========================
/*分页查找数据*/
CREATE PROCEDURE [dbo].[GetRecordSet]
@strSql varchar(8000),--查询sql,如select * from [user]
@PageIndex int,--查询当页号
@PageSize int--每页显示记录
AS
set nocount on
declare @p1 int
declare @currentPage int
set @currentPage = 0
declare @RowCount int
set @RowCount = 0
declare @PageCount int
set @PageCount = 0
exec sp_cursoropen @p1 output,@strSql,@scrollopt=1,@ccopt=1,@rowcount=@rowCount output --得到总记录数
select @PageCount=ceiling(1.0*@rowCount/@pagesize) --得到总页数
,@currentPage=(@PageIndex-1)*@PageSize+1
select @RowCount,@PageCount
exec sp_cursorfetch @p1,16,@currentPage,@PageSize
exec sp_cursorclose @p1
set nocount off
GO
=========================用户注册============================
/*
用户注册,也算是添加吧
*/
Create proc [dbo].[UserAdd]
(
@loginID nvarchar(50), --登录帐号
@password nvarchar(50), --密码
@email nvarchar(200) --电子信箱
)
as
declare @userID int --用户编号
--登录账号已经被注册
if exists(select loginID from tableName where loginID = @loginID)
begin
return -1;
end
--邮箱已经被注册
else if exists(select email from tableName where email = @email)
begin
return -2;
end
--注册成功
else
begin
select @userID = isnull(max(userID),100000)+1 from tableName
insert into tableName
(userID,loginID,[password],userName,linkNum,address,email,createTime,status)
values
(@userID,@loginID,@password,'','','',@email,getdate(),1)
return @userID
end
==========================sql server系统存储过程===================
–1.给表中字段添加描述信息
Create table T2 (id int , name char (20))
GO
EXEC sp_addextendedproperty 'MS_Description', 'Employee ID', 'user', dbo, 'table', T2, 'column', id
EXEC sp_updateextendedproperty 'MS_Description', 'this is a test', 'user', dbo, 'table', T2, 'column', id
–2.修改数据库名称
EXEC sp_renamedb 'old_db_nam
相关文档:
sqlserver2005远程连接 mysql
2种方法
一是通过建立link的方法
sp_addlinkedserver 'ntest-link名', 'MySQL', 'MSDASQL--支持的链接方式', 'mytest-dsn名'
GO
sp_addlinkedsrvlogin 'ntest-link名','false', 'sa-sqlserver用户','mythzz-sqlserver密码' ......
SQLserver中用convert函数转换日期格式
2008-01-23 15:47
SQLserver中用convert函数转换日期格式2008-01-15 15:51SQLserver中用convert函数转换日期格式
SQL Server中文版的默认的日期字段datetime格式是yyyy-mm-dd Thh:mm:ss.mmm
例如:
select getdate()
2004-09-12 11:06:08.177
整理了一下SQL Server里面可能经 ......
一。SqlServer自动作业备份
1、打开SQL Server Management Studio
2、启动SQL Server代理
3、点击作业->新建作业
4、"常规"中输入作业的名称
5、新建步骤,类型选T-SQL,在下面的命令中输入下面语句
DECLARE @strPath NVARCHAR(200)
set @strPath = convert(NVARCHAR(19),getdate(),120)
set @strPath=replace(@ ......
Oracle笔记
l 关于TRUNC函数
SELECT
RELATED_ID ,
DOC_ID ,
CAT_ID ,
CAT_CODE ,
RELEASE_DATE ,
&n ......
--TOP n 实现的通用分页存储过程(转自邹建)
CREATE PROC sp_PageView
@tbname sysname, --要分页显示的表名
@FieldKey nvarchar(1000), --用于定位记录的主键(惟一键)字段,可以是逗号分隔的多个字段
@PageCurrent int=1, --要显示的页码
@PageSize int=10, - ......