Wednesday, October 22, 2008

Moving a Table to Another Schema

ALTER SCHEMA CompCredSurvey --this is new schema
TRANSFER MinEducationValuesLookup --this is the table you're changing to the new schema
GO

Tuesday, October 21, 2008

ADD a Column, Integer with a NOT NULL and a DEFAULT value

ALTER TABLE [CompCredSurvey].[2004Survey] ADD SurveyYear int not null default (2004)

I tried this without the brackets like the examples I found on the web, but SQL wouldn't accept it. Once I bracketed it worked fine. You might have to bracket the column name a well [SurveyYear].

Wednesday, October 8, 2008

Change a Column to the Primary Key

ALTER TABLE tablename ADD PRIMARY KEY (columnname)

*the new primary key column cannot be set to accept nulls