Re: Table OWNER
From: Saradhi (upadrasta_at_inooga.com)
Date: 12/24/04
- Next message: Rob Nicholson: "Firewall ports to open"
- Previous message: Derrick Leggett: "Re: Developer has SA registration details"
- In reply to: John Bell: "Re: Table OWNER"
- Next in thread: John Bell: "Re: Table OWNER"
- Reply: John Bell: "Re: Table OWNER"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ] [ attachment ]
Date: Fri, 24 Dec 2004 19:03:10 +0530
Hi,
Thanks For your quick Reply.
Now I wanted to change the owner of all my tables to 'bdyck'.
So I used the following Cursor to do this.
DECLARE ChangeTableOwner_cursor CURSOR FOR
SELECT '''' + TABLE_SCHEMA + '.' + TABLE_NAME + ''', bdyck'
FROM INFORMATION_SCHEMA.TABLES
WHERE
OBJECTPROPERTY(OBJECT_ID(QUOTENAME(TABLE_SCHEMA) + '.' + QUOTENAME(TABLE_NAME)), 'IsMSShipped') = 0
AND TABLE_TYPE = 'BASE TABLE' /*Check the TABLE_TYPE against 'VIEW' to work with views*/
AND TABLE_SCHEMA = 'dbo' /*To change the owner of tables owned by 'dbo' only*/
AND TABLE_NAME LIKE 'PES%' /*To change the owner of tables starting with a particular pattern*/
GO
DECLARE @sql1 varchar(500)
OPEN ChangeTableOwner_cursor
-- Perform the first fetch.
FETCH NEXT FROM ChangeTableOwner_cursor INTO @sql1
-- Check @@FETCH_STATUS to see if there are any more rows to fetch.
WHILE @@FETCH_STATUS = 0
BEGIN
PRINT 'SQL: ' + 'EXEC ( sp_changeobjectowner + @sql1 )' + @sql1
-- This is executed as long as the previous fetch succeeds.
EXEC ( 'sp_changeobjectowner' + @sql1 )
FETCH NEXT FROM ChangeTableOwner_cursor INTO @sql1
END
CLOSE ChangeTableOwner_cursor
DEALLOCATE ChangeTableOwner_cursor
GO
But interestingly when I go and access one of my table, it says the object doesnt exists in the DB.
Is there anything I need to change the owner of all the tables to some user and still use the data in the tables?
-SARADHI
"John Bell" <jbellnewsposts@hotmail.com> wrote in message news:uu$EMsD6EHA.208@TK2MSFTNGP12.phx.gbl...
Hi
"Saradhi" <upadrasta@inooga.com> wrote in message
news:OfVRfVD6EHA.3504@TK2MSFTNGP12.phx.gbl...
1) Wts the query to know the Owner of a table?
Select * FROM INFORMATION_SCHEMA.TABLES
WHERE TABLE_NAME = '<Table Name>'
2) I logged in as a user pardha whose server role is a system administrator.
I created a table in the SQL Enterprise Manager and SQL Query Analyser, but
the EM shows the owner of the Table as dbo. it should show as pardha as I
created it. Is there anything wrong in my thinking?
As you are (probably) a member of the sysadmin fixed server role you will be
mapped onto dbo.
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/adminsql/ad_security_9qyh.asp
John
-SARADHI
- Next message: Rob Nicholson: "Firewall ports to open"
- Previous message: Derrick Leggett: "Re: Developer has SA registration details"
- In reply to: John Bell: "Re: Table OWNER"
- Next in thread: John Bell: "Re: Table OWNER"
- Reply: John Bell: "Re: Table OWNER"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ] [ attachment ]
Relevant Pages
|
|