Home Microsoft SQL Server DigiMailing iRN Contact
    Keyword



sys.sp_dropalias

  No additional text.


Syntax
create procedure sys.sp_dropalias
    @loginame   sysname     -- login who is currently aliased
as
    -- SETUP RUNTIME OPTIONS / DECLARE VARIABLES 
	set nocount on
	declare @sid        varbinary(85),
			@aliasname	sysname

    -- CHECK PERMISSIONS 
    if (not is_member('db_owner') = 1)
	begin
		raiserror(15247,-1,-1)
		return (1)
	end

    -- DISALLOW USER TRANSACTION 
	set implicit_transactions off
	if (@@trancount > 0)
	begin
		raiserror(15002,-1,-1,'sys.sp_dropalias')
		return (1)
	end

	BEGIN TRANSACTION

	-- LOCK ALIAS 
	select @aliasname = '\'+@loginame
	EXEC %%Alias(Name = @aliasname).Lock(Exclusive = 1) -- may fail, sid will be null

	-- VALIDATE LOGIN NAME (OBTAIN SID) 
	IF @@ERROR = 0
		select @sid = sid from sys.sysusers where name = @aliasname and isaliased = 1
	if @sid is null
	begin
		ROLLBACK TRANSACTION
		raiserror(15134,-1,-1)
		return (1)
	end

    -- DELETE THE ALIAS (IF ANY) 
	EXEC %%Alias(Name = @aliasname).Remove()	-- already locked

	COMMIT TRANSACTION

    -- RETURN SUCCESS 
	return (0) -- sp_dropalias

 
Last revision 2008RTM
News

  Query a named instance
Sybase+ASE+silent+install
SQL 2008 R2
Deprecated procedures in SQL2008
Reporting Services item-level role definitions
Create all your missing indexes
Converting datetime field
Start MSSQL Server Profiler at time
Replicating MSSQL Server views
Exploring Microsoft Sharepoint
The OLE DB provider "SQLNCLI10" for linked server indicates.
Mobile solar charger
Oracle to SQL Server replication
Cannot insert the value NULL into column
Undocumented Microsoft SQL Server 2008
VMware
Zoekmachine optimalisatie
SQL Servers hidden objects
FckEditor
Flash in Ajax
De hype die AJAX heet
Barcode scannen
MySQL; Gratis, makkelijk en snel!
PHP
sIFR; de combinatie tussen HTML en Flash