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

Ask A Question

Stats

  • Questions 535k
  • Answers 535k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer I am guessing you are using the SQL timestamp type… May 17, 2026 at 1:12 am
  • Editorial Team
    Editorial Team added an answer You need to call the features you use not available… May 17, 2026 at 1:12 am
  • Editorial Team
    Editorial Team added an answer Here’s another solution: $prev = null; $missing = array(); foreach… May 17, 2026 at 1:12 am

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

I am using DataSets for access to Sql Server 200x in a C# project.
I'm using the SQL Server Driver for PHP to connect to an SQL Server
I don't have a specific question here but I'm more looking for some guidance
I am trying to update data while I am reading them from database, see
I'm running into an issue where granting EXECUTE permissions on a specific Stored Procedure
As I have seen, SQL 2008 no longer offers replication over internet in very
I am new to designing my own database. My project is orders/products/inventory type data,
I know this is subjective, but I'd like to know peoples opinions and hopefully
When using the Entity Framework there are basically two ways to create your model.
Does anyone have any tricks for quickly laying out the asp.net html markup for

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.