Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Author |
Topic |
lhariharan
Starting Member
1 Post |
Posted - 2011-11-21 : 00:35:26
|
Hi, I am new to Sql server. I am using sql server 2008 R2. I want to copy all the objects of one schema and put it in another schema. I want to do that from command prompt. In oracle we can export the objects of one user and import to another user using exp and imp. I want similar type. Can anyone suggest me a way to do this?Thanks,Hariharan |
|
vikki.seth
Yak Posting Veteran
66 Posts |
Posted - 2011-11-21 : 14:12:04
|
Create the new schema first and run the below query in SQLCMD or query analyzer ,Copy the output and run it again. DECLARE @sourceschema VARCHAR(100)DECLARE @destinationschema VARCHAR(100)SET @sourceschema = 'sourceschema'SET @destinationschema = 'destinationschema'SELECT 'ALTER SCHEMA ' + @destinationschema + ' TRANSFER ' + b.name + '.' + a.name FROM sys.objects a JOIN sys.schemas bON a.schema_id=b.schema_id WHERE a.type IN ('U','P','FN','V') AND b.name=@sourceschema |
|
|
|
|
|