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