Showing posts with label sql. Show all posts
Showing posts with label sql. Show all posts

Friday, July 24, 2009

How to Add a Foriegn Key Relationship to a table

ALTER TABLE [dbo].[FactLocateOrdersSKUAggYear] WITH CHECK ADD CONSTRAINT [FK_FactLocateOrdersSKUAggYear_DimBrand] FOREIGN KEY([dw_brand_id])
REFERENCES [dbo].[DimBrand] ([brand_id])
GO

ALTER TABLE [dbo].[FactLocateOrdersSKUAggYear] CHECK CONSTRAINT [FK_FactLocateOrdersSKUAggYear_DimBrand]
GO

Note: Datatypes must be the same for columns in the relationship or a data type error will occur.

How to change the datatype of a column on a table already populated with data

ALTER TABLE [dbo].[tablename] ALTER COLUMN column_name smallint