SQL Clone
SQLServerCentral is supported by Redgate
Log in  ::  Register  ::  Not logged in

Get your favorite SSC scripts directly in SSMS with the free SQL Scripts addin. Search for scripts directly from SSMS, and instantly access any saved scripts in your SSC briefcase from the favorites tab.
Download now (direct download link)

Copy One Schema to Another Schema

By Vinay Kumar,


Currently, I am working on a project where we have more than 10 clients. We manage all clients through different schema. Every schema object is accessing only its own schema objects and not other schema objects.

Sometimes I need to update some stored procedures which are the same in all schema. In this case, I have manually opened and udpated the stored procedure for every schema. I googled for this, but didn't find anything. So, I created this script.

Here I am creating a testing scenario. In this, I create a table: "SchemaTable" in every schema (Marketing, Sales ,Accounts ,Economics, Employee, Manager, Employee). Then I create a stored procedure only in Employee schema. This schema is accessing only same schema table.

Now I want to create this store procedure in all schema, then execute the main script.

Note :- Before executing the script, please check the parameters and follow these steps:

1. Create an object for Testing. Execute "CREATE OBJECTS SCRIPT" from script section.

2. Change the pameter value:

  @CopyFromSchema = Enter the schema name, where you want to pick the definition.

  @CopyToSchema = Enter the schema name in which you want to create or update the object.

  @ObjectName = Enter the object that you want to copy.

3. Drop object, Execute "DROP OBJECTS SCRIPT" from script section.

I feel that maybe someone is suffering like me, so I am sharing this.

Feel free to comment if you have any suggestions for this.


Total article views: 1261 | Views in the last 30 days: 3
Related Articles

Schema-Owned Tables and Generated DROP Scripts (SQL Spackle)

Not all SQL-generated scripts are created equal (or correctly) for alternative schema-owned objects....


Create SCHEMA error

Error when running script to create schema


Name the schema when you create an object (or else)

This is one of those frequently ignored best practices. When you create an object, specify the sc...


Generating Scripts for Database Objects

Creating Seperate Scripts Per Object


Copy Multiple objects from One Schema to Another Schema

Copy Multiple objects from One Schema to Another Schema