Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Author |
Topic |
wsilage
Yak Posting Veteran
82 Posts |
Posted - 2015-02-16 : 20:57:11
|
I have this table that I thought I could just do a normal update to because I need to add a state and ID. It isn't that simple. How do I add a state to a table that is already created?Here is the behind the scenes. I have never had to deal with something like this.This is what it looks likeSET ANSI_NULLS ONGOSET QUOTED_IDENTIFIER ONGOSET ANSI_PADDING ONGOCREATE TABLE [dbo].[RegionStates]( [RegionID] [smallint] NOT NULL, [State] [char](2) NOT NULL, CONSTRAINT [PK_RegionStates] PRIMARY KEY CLUSTERED ( [RegionID] ASC, [State] ASC)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]) ON [PRIMARY]GOSET ANSI_PADDING OFFGOALTER TABLE [dbo].[RegionStates] WITH CHECK ADD CONSTRAINT [FK_RegionStates_Regions] FOREIGN KEY([RegionID])REFERENCES [dbo].[Regions] ([ID])GOALTER TABLE [dbo].[RegionStates] CHECK CONSTRAINT [FK_RegionStates_Regions]GOALTER TABLE [dbo].[RegionStates] WITH CHECK ADD CONSTRAINT [FK_RegionStates_USStates] FOREIGN KEY([State])REFERENCES [dbo].[USStates] ([StateCode])GOALTER TABLE [dbo].[RegionStates] CHECK CONSTRAINT [FK_RegionStates_USStates]GO |
|
tkizer
Almighty SQL Goddess
38200 Posts |
Posted - 2015-02-16 : 21:00:46
|
Here's an example: ALTER TABLE Table1 ADD Column12 varchar(50) NULLTara KizerSQL Server MVP since 2007http://weblogs.sqlteam.com/tarad/ |
|
|
|
|
|