Author Topic: Change table's schema with just one statement.  (Read 2342 times)

BhushanShah

  • Global Moderator
  • Jr. Member
  • *****
  • Posts: 73
  • BhushanShah21
    • View Profile
Change table's schema with just one statement.
« on: September 15, 2012, 04:11:21 PM »
To change table's schema use following statement:

Code: [Select]
ALTER SCHEMA [NewSchema] TRANSFER [OldSchema].[Table1]

You can try it with following example :

Code: [Select]

CREATE TABLE [OldSchema].[Table1]
(
Column1 INT IDENTITY(1,1) NOT NULL,
Column2 VARCHAR(25)
)

ALTER SCHEMA [NewSchema] TRANSFER [OldSchema].[Table1]


Note : It will drop constraints,indexes etc. if any exists.
Regards,
Bhushan Shah

Ritesh Shah

  • Administrator
  • Jr. Member
  • *****
  • Posts: 57
  • Ritesh Shah
    • View Profile
    • IT Technology Blog
Re: Change table's schema with just one statement.
« Reply #1 on: September 15, 2012, 09:24:13 PM »
this is a subject of Article. :) you should give more details along with detailed example...
Ritesh Shah
Administrator
Extreme-Advice.com
SQLHub.com

BhushanShah

  • Global Moderator
  • Jr. Member
  • *****
  • Posts: 73
  • BhushanShah21
    • View Profile
Re: Change table's schema with just one statement.
« Reply #2 on: September 15, 2012, 10:11:05 PM »
Sure.I will give detailed example. :)
Regards,
Bhushan Shah