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 946941
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T23:00:09+00:00 2026-05-15T23:00:09+00:00

Using SQL Server and T-SQL, how can I update ALL tables tables with a

  • 0

Using SQL Server and T-SQL, how can I update ALL tables tables with a specific name but different schemas under the same database?

:Update:

The updates include adding/deleting/modifying columns as well as changing specific values of rows.

I want to be able to deploy changes to a table across all schemas. Using the SQL Server Management Studio table designer, when I do a change and save, it allows me to save a script that can be used to deploy those changes to a different table. I want to be able to use that script on all tables with that specific name across all schemas.

:Update 2:

There reason for this request is that I want to ensure that updating a specific table across multiple schemas is easy to do. In the future, my application will undoubtedly change and if I see that it is difficult or inefficient to update schemas then I will opt to use something else.

Below is what I tried:

DECLARE @update_sql NVARCHAR(max)
DECLARE @table_name VARCHAR(45)

DECLARE c_tables CURSOR FOR
  SELECT t.table_name
    FROM INFORMATION_SCHEMA.TABLES t
   WHERE t.table_name = 'TestTable'
     AND t.table_catalog = 'MyDataBase'

OPEN c_tables
FETCH c_tables INTO @table_name

WHILE @@Fetch_Status = 0
BEGIN

  SET @update_sql = N'ALTER TABLE '+@table_name+' ADD ColumnThree nvarchar(50) NULL'
  EXEC sp_executesql @update_sql

END

CLOSE c_tables
DEALLOCATE c_tables

Running this generates the following error:

Cannot find the object “TestTable” because it does not exist or you do not have permissions.

The table exists and I’am running under dbo which is the schema owner.

I also noticed the query takes sometime to run even with only 7 tables in the database and 3 schemas used on those tables. Would it be more efficient to just login with each schema’s owner and run a generic script? Each schema owner would only have access to their respective schema and tables.

  • 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-05-15T23:00:10+00:00Added an answer on May 15, 2026 at 11:00 pm

    On SQL Server 2005+, you can use INFORMATION_SCHEMA.TABLES to get a list of tables within a database:

    SELECT t.table_name,
           t.table_schema
      FROM INFORMATION_SCHEMA.TABLES t
     WHERE t.table_name = 'Table_1'
       AND t.table_catalog = 'your_database'
    

    But you didn’t specify what updating you need – DML or DDL…

    Update

    DECLARE @update_sql NVARCHAR(max)
    DECLARE @table_name VARCHAR(45)
    
    DECLARE c_tables CURSOR FOR
      SELECT t.table_name
        FROM INFORMATION_SCHEMA.TABLES t
       WHERE t.table_name = 'Table_1'
         AND t.table_catalog = 'your_database'
    
    OPEN c_tables
    FETCH c_tables INTO @table_name
    
    WHILE @@Fetch_Status = 0
    BEGIN
    
      SET @update_sql = N'UPDATE @table_name SET ...'
      EXEC sp_executesql @update_sql
    
      SET @update_sql = N'ALTER TABLE @table_name ...'
      EXEC sp_executesql @update_sql
    
    END
    
    CLOSE c_tables
    DEALLOCATE c_tables
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using MS SQL Server 2008R2, but I believe this is database agnostic. I'm
i am using sql server 2000 can i use full text search on the
Using SQL Server 2005, how can I authenticate a username/password pair against a non-AD
I am using the SQL Server PHP Driver, I think this question can be
How can I retrieve data from a SQL Server using LINQ and display each
How can i sync sql server 2008-R2 (remopte server and local) using Microsoft Sync
I'm trying to configure replication on SQL Server 2005. I can do it using
Can anyone tell me, How to insert one record in SQL Server by using
I am using SQL Server 2008 R2. I have imported 2 tables from excel
I need to update my contacts database in SQL Server with changes made in

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.