CREATE new schema and ALTER table schema

To create a new Database Schema:
CREATE SCHEMA NewSchema
GO

To create a new Database Schema only if it does not exist:
IF NOT EXISTS (SELECT * FROM sys.schemas
WHERE name ='NewSchema')

EXEC dbo.sp_executesql @statement=N'
CREATE SCHEMA NewSchema'
;
GO


To change a table's Schema:
ALTER SCHEMA NewSchema TRANSFER OldSchema.TableName;
--default schema is dbo then:
ALTER SCHEMA NewSchema TRANSFER dbo.TableName;

2 comments:

Ace Van OJ said...

Sup dude, i noticed you have those ad alerts on ur page- do you actualy get any mony outa it ? I've also got a blog page and was thinking of adding it.

Thnx for the help with schema's :)

oyen said...

I have several other blogs in one account. This one doesn't earn much because I don't update it as much. It's more of a personal reminder on how to do things so I don't have to rummage on Google search results every time.

One of my blogs is 2.5 years old and has 300+ posts in total. It meets the Google Adsense quota monthly.