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

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

SQL Server常用存儲過程及示例

2024-08-31 00:45:08
字體:
來源:轉載
供稿:網友

分頁:

復制代碼 代碼如下:


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

主站蜘蛛池模板: 淮南市| 留坝县| 东源县| 镇安县| 湖口县| 尚义县| 钟祥市| 庄浪县| 苏尼特右旗| 金沙县| 集安市| 察隅县| 马公市| 洪泽县| 蒲城县| 民丰县| 剑河县| 梅州市| 九寨沟县| 桑日县| 龙胜| 韩城市| 威海市| 五大连池市| 马鞍山市| 高碑店市| 清河县| 昌乐县| 古浪县| 安徽省| 阳东县| 河源市| 英德市| 旬阳县| 松潘县| 宁陵县| 塘沽区| 信丰县| 华亭县| 内黄县| 微博|