T-Sql for changing the Owner of the table objects in a database

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • ArijitChaterjee
    New Member
    • Jan 2007
    • 1

    T-Sql for changing the Owner of the table objects in a database

    I have a MS SQL Server Database which consists of several Tables, amongh some has owner as "dbo" and some has another owner like "xyz".
    Is there any T-SQL that can change the owner [xyz] of the tables to "dbo".

    And plz clarify the fact how a owner can be determined at the time of table creation.
  • iburyak
    Recognized Expert Top Contributor
    • Nov 2006
    • 1016

    #2
    To change owner

    EXEC sp_changeobject owner 'table_name', 'dbo'


    To create table or any database object with dbo owner you have to mention it in create statement otherwise it is your UID.

    [PHP]Create table dbo.table_name ( column1 datatype1, .... )[/PHP]

    I think it depends on Server settings in some cases dbo is a default owner.

    Comment

    • almaz
      Recognized Expert New Member
      • Dec 2006
      • 168

      #3
      Originally posted by iburyak
      I think it depends on Server settings in some cases dbo is a default owner.
      It depends on current user, so if user that executes the create statement is dbo in the database, then objects by default would be created under dbo

      Comment

      • BinaryStar
        New Member
        • Feb 2007
        • 1

        #4
        Hi,

        You can change object owner in a streatch with the following command if you are having more no of tables to change object owner.

        select 'execute sp_changeobject owner '+ '''' + 'xyz.'+name+''' '+','+'''dbo''' from sysobjects where xtype = 'U' and uid=5 order by name

        Comment

        Working...