Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8086259
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T18:23:36+00:00 2026-06-05T18:23:36+00:00

In SQL Server, I have a database abc . In this database I have

  • 0

In SQL Server, I have a database abc. In this database I have hundreds of tables. Each of these tables is called xyz.table

I want to change all the tables to be called abc.table.

Do we have a way by which I can change all the names from xyz.table to abc.table in database abc?

I am able to manually change the name by changing the schema for each table to abc

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T18:23:38+00:00Added an answer on June 5, 2026 at 6:23 pm

    You can use Alter Schema with an undocumented Stored Procedure exec sp_MSforeachtable which basically iterates through all the tables .

      exec sp_MSforeachtable "ALTER SCHEMA new_schema TRANSFER ? PRINT '? modified' " 
    

    change the new_schema keyword with your new Schema .

    For details please go through the link

    sp_MSforeachtable

    Alter Schema for all the tables

    As others have pointed out that the SP is deprecated so There is another way to do this by getting the names of the table from sys.tables

    Declare @value int
    Set @value=1
    declare @sql varchar(max), @table varchar(50), @old varchar(50), @new varchar(50)
    
    set @old = 'dbo'
    set @new = 'abc'
    
    while exists(select * from sys.tables where schema_name(schema_id) = @old)
    
    begin
    ;With CTE as
     (
      Select *,row_number() over(order by object_id) rowNumber from sys.tables 
      where schema_name(schema_id) = @old
     )
     select @table= name from CTE where @value=rowNumber
     Set @value=@value+1
    
     set @sql = 'alter schema ' + @new + ' transfer ' + @old + '.' + @table
    
     exec(@sql)
     end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We have a database called AVL in SQL Server 2008 R2 SE. This database
In my SQL Server 2008 R2 database, I have an existing table [dbo].[abc].[MyTable] .
I have a Database (SQL Server) with table named 'ProcessData' and columns named 'Process_Name'
I have a database on a SQL Server 2000 server. This database has a
Programs used: SQL Server 2000, Excel 2003 We have a table in our database
I have Database table and I am using SQL Server 2008. The table contins
In sql server database, I have column name Image which has urls like http://www.xyz.com/1009/image1.jpg
I have SQL Server database and I just realized that I can change the
(Note: This is for MySQL's SQL, not SQL Server.) I have a database column
Possible Duplicate: Select n random rows from SQL Server table I have database and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.