Create an account

Very important

  • To access the important data of the forums, you must be active in each forum and especially in the leaks and database leaks section, send data and after sending the data and activity, data and important content will be opened and visible for you.
  • You will only see chat messages from people who are at or below your level.
  • More than 500,000 database leaks and millions of account leaks are waiting for you, so access and view with more activity.
  • Many important data are inactive and inaccessible for you, so open them with activity. (This will be done automatically)


Thread Rating:
  • 514 Vote(s) - 3.5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How do I move a table into a schema in T-SQL

#1
I want to move a table into a specific Schema using T-SQL? I am using SQL Server 2008.
Reply

#2
Short answer:

ALTER SCHEMA new_schema TRANSFER old_schema.table_name

I can confirm that the data in the table remains intact, which is probably quite important :)

Long answer as per [MSDN docs][1],

ALTER SCHEMA schema_name
TRANSFER [ Object | Type | XML Schema Collection ] securable_name [;]

If it's a table (or anything besides a Type or XML Schema collection), you can leave out the word Object since that's the default.


[1]:

[To see links please register here]



Reply

#3
ALTER SCHEMA TargetSchema
TRANSFER SourceSchema.TableName;

If you want to move *all* tables into a new schema, you can use the undocumented (and to be deprecated at some point, but unlikely!) `sp_MSforeachtable` stored procedure:

exec sp_MSforeachtable "ALTER SCHEMA TargetSchema TRANSFER ?"


Ref.: [`ALTER SCHEMA`][2]

[SQL 2008: How do I change db schema to dbo][1]

[1]:

[To see links please register here]

[2]:

[To see links please register here]

Reply



Forum Jump:


Users browsing this thread:
1 Guest(s)

©0Day  2016 - 2023 | All Rights Reserved.  Made with    for the community. Connected through