http://www.tzwhx.com/newOperate/html/3/31/311/21117.html
create database SPM;
drop login web_login;
create login web_login with password='wel123!', default_database = SPM;
EXEC sp_addsrvrolemember 'web_login', 'sysadmin' --添加登錄名到服務器角色
exec sp_srvrolepermission;--查看服務器角色的權限
--sp_helplogins 會返回兩個結果集,第一個結果集包含登錄名的基本數據
--第二個結果集包含登錄名與用戶的映射關係。
exec sp_helplogins;--查看每一個登錄名的設置
EXEC sp_helpsrvrolemember ;--查看每一個服務器角色的成員
EXEC sp_addsrvrolemember 'web_login', 'sysadmin' --添加登錄名到服務器角色
EXEC sp_dropsrvrolemember 'web_login', 'sysadmin'--從服務器角色刪除登錄名
存儲過程定義
use [SPM]
Drop schema Wesley
go
Create Schema Wesley
go
if OBJECT_ID('Wesley.sp_GetVersionType') is not null
Drop procedure Wesley.sp_GetVersionType
go
create procedure Wesley.sp_GetVersionType
with encryption
as
select * from VersionTypeBase;
go
--drop procedure sp_GetVersionType;
if OBJECT_ID('Wesley.sp_GetVersionTypeById') is not null
Drop procedure Wesley.sp_GetVersionTypeById
go
create procedure Wesley.sp_GetVersionTypeById
@VersionId uniqueidentifier
with encryption
as
select * from VersionTypeBase where VersionTypeId = @VersionId;
go
if OBJECT_ID('Wesley.sp_GetCodeBaseByType') is not null
Drop procedure Wesley.sp_GetCodeBaseByType
go
create procedure Wesley.sp_GetCodeBaseByType
@Result varchar(20) output,@Type varchar(30) = 'TestStatusCode'
as
select * from CodeBase where Type = @Type
set @Result = 'success'
go
if OBJECT_ID('Wesley.sp_PrintSoftwareInfo') is not null
Drop procedure Wesley.sp_PrintSoftwareInfo
go
create procedure Wesley.sp_PrintSoftwareInfo
@Mycursor cursor varying output ,@TopInt int = 20
as
set @Mycursor = CURSOR
FOR
select top (@TopInt) name from softwarebase order by name
open @Mycursor
go
調用存儲過程
use [SPM];
go
select * from sys.sql_modules ;
--無參數的存儲過程,調用
exec Wesley.sp_GetVersionType;
--帶參數的存儲過程,調用
declare @VersionId uniqueidentifier
set @VersionId = '51479AE5-97A4-4AD5-AF85-C0E95AD837D2'
exec Wesley.sp_GetVersionTypeById @VersionId;
--帶out參數的存儲過程,調用
declare @RESULT varchar(20)
exec Wesley.sp_GetCodeBaseByType @RESULT out
print @RESULT
go
--用於遍歷遊標輸出結果
declare @Scursor cursor
declare @name varchar(50)
exec Wesley.sp_PrintSoftwareInfo @Scursor out,8
fetch next from @Scursor into @name
while(@@FETCH_STATUS = 0)
begin
begin
print @name
end
fetch next from @Scursor into @name
end
Close @Scursor
Deallocate @Scursor
go