Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
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,

Hi,

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.

Thanks.

Total article views: 1135 | Views in the last 30 days: 7
 
Related Articles
ARTICLE

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

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

FORUM

Create SCHEMA error

Error when running script to create schema

FORUM

Generating Scripts for Database Objects

Creating Seperate Scripts Per Object

SCRIPT

Copy Multiple objects from One Schema to Another Schema

Copy Multiple objects from One Schema to Another Schema

SCRIPT

Compress All Objects

Creates compression scripts for all objects in all databases in the instance.

Tags
schema    
t-sql    
 
Contribute

Join the most active online SQL Server Community

SQL knowledge, delivered daily, free:

Email address:  

You make SSC a better place

As a member of SQLServerCentral, you get free access to loads of fresh content: thousands of articles and SQL scripts, a library of free eBooks, a weekly database news roundup, a great Q & A platform… And it’s our huge, buzzing community of SQL Server Professionals that makes it such a success.

Join us!

Steve Jones
Editor, SQLServerCentral.com

Already a member? Jump in:

Email address:   Password:   Remember me: Forgotten your password?
Steve Jones