国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 數據庫 > SQL Server > 正文

SQL Server常用存儲過程及示例

2020-07-25 13:03:30
字體:
來源:轉載
供稿:網友

分頁:

復制代碼 代碼如下:

/*分頁查找數據*/
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_name', 'new_db_name'

3.修改數據表名稱和字段名稱
復制代碼 代碼如下:

EXEC sp_rename 'old_table_name', 'new_table_name' 主站蜘蛛池模板: 嘉峪关市| 汉源县| 怀集县| 河津市| 隆昌县| 思茅市| 潼关县| 长阳| 陈巴尔虎旗| 彭泽县| 山东省| 定安县| 都匀市| 古浪县| 德令哈市| 巴里| 长阳| 昆明市| 奉节县| 平谷区| 永川市| 龙游县| 石屏县| 新民市| 枣庄市| 什邡市| 行唐县| 宜黄县| 商水县| 岑溪市| 蒲江县| 隆安县| 红安县| 桂阳县| 福鼎市| 宁陕县| 额敏县| 冀州市| 泰州市| 项城市| 金坛市|