September 24, 2007 at 10:33 am
Hi Friends,
I want to change my USER NAME of the USER.
CHANGE THE OWNER SHIP Of the user 'shiv' - 'kumar'
what is command of that one OR GUI how can i change plz explain me
Thx
September 24, 2007 at 11:28 am
Which is it? You've asked two things here. Are you changing the user name or the ownership of something.
September 24, 2007 at 11:43 am
here's the answer to both questions: change a login name:
--Usage: EXEC pr_RenameLogin 'webdev', 'WebDeveloper'
--modified from from http://www.planet-source-code.com/vb/scripts/ShowCode.asp?txtCodeId=408&lngWId=5
---Code should be put in master database ---
CREATE PROCEDURE pr_RenameLogin (@CurrentLogin sysname, @NewLogin sysname)
AS
BEGIN
DECLARE @SQLState AS VARCHAR(200)
--here's the bad thing: allowing adhoc updates!!!!
IF EXISTS(SELECT [name] FROM master.dbo.sysxlogins WHERE [name] = @CurrentLogin)
BEGIN
EXEC master.dbo.sp_configure 'allow updates', '1'
RECONFIGURE WITH OVERRIDE
--Update user login name in master db
SET @SQLState = 'UPDATE master.dbo.sysxlogins SET [name] = ''' + @NewLogin + ''' WHERE [name] = ''' + @CurrentLogin + ''''
EXEC (@SQLState)
--Update user login name in each db where has access as in in sysusers table
SET @SQLState = 'EXEC master.dbo.sp_MSForEachDB ''UPDATE ?.dbo.sysusers SET [name] = ''''' + @NewLogin + ''''' where [name] = ''''' + @CurrentLogin + ''''''''
EXEC (@SQLState)
--Put the configuration back to normal
EXEC master.dbo.sp_configure 'allow updates', '0'
RECONFIGURE WITH OVERRIDE
PRINT 'User ' + @CurrentLogin + ' Renamed Successfully to ' + @NewLogin
END
ELSE
BEGIN
PRINT 'User ' + @CurrentLogin + ' Not found in the master database. Check your spelling and confirm this is the correct server.'
END
END
GO
change object owner from one user to another:
select 'EXEC sp_changeobjectowner "' + u.name + '.' + o.name + '","kumar"' from sysobjects o, sysusers u
where type = 'u'
and u.uid = o.uid and u.uid <> 1
and u.name='shiv'
Lowell
Viewing 3 posts - 1 through 3 (of 3 total)
You must be logged in to reply to this topic. Login to reply