+ Reply to Thread
Results 1 to 3 of 3

Thread: MSSQL Server - Error: invalid object name

  1. MSSQL Server - Error: invalid object name

    When performing a query of a MS SQL Server database you receive the following error "invalid object name". This error is generated when a table is pre-fixed with the schema other than dbo (example: myuser.table).

    Querying "select * from myuser.table" would allow you to query the table but is not convenient.

    Instead the table should be pre-fixed with 'dbo'. to do this you will need to ALTER each of the tables with this statement:

    Code:
    ALTER SCHEMA dbo TRANSFER myuser.table
    To generate all the needed SQL to change ALL tables:

    Code:
    SELECT 'ALTER SCHEMA dbo TRANSFER ' + s.Name + '.' + p.Name  
    FROM sys.tables p INNER JOIN  
    sys.Schemas s on p.schema_id = s.schema_id  
    WHERE s.Name = 'EXISTING_OWNER_USERNAME'
    Jon C.

  2. Join Date
    Nov 2009
    Posts
    43

    If you need to update SQL Server Objects like stored procedures, please change 'sys.tables' in the above query to 'sys.objects'.

  3. For SQL 2000 change the owner on a table:
    1. Change MyDB to your database name.
    2. Change MyUser to the current owner username.
    3. Change MyTableName to the table needing modified.

    Code:
    use MyDB
    
    EXEC sp_changeobjectowner 'MyUser.MyTableName', 'dbo'
    Last edited by JonC; March 8th, 2010 at 09:06 AM.
    Jon C.

+ Reply to Thread

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts