-- add column IF NOT EXISTS (SELECT * FROM sys.columns WHERE name='WOAServedStatus' AND object_id=OBJECT_ID('WOA')) BEGIN ALTER table [WOA] add WOAServedStatus INT NULL END
--增加一个约束 IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[DF_WOA_WOAServedStatus]') AND type = 'D') BEGIN ALTER TABLE [dbo].[WOA] ADD CONSTRAINT [DF_WOA_WOAServedStatus] DEFAULT ((0)) FOR [WOAServedStatus] END --add foreign key IF NOT EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_WOA_WOAServedStatus]') AND parent_object_id = OBJECT_ID(N'[dbo].[WOA]')) BEGIN ALTER TABLE [dbo].[WOA] WITH CHECK ADD CONSTRAINT [FK_WOA_WOAServedStatus] FOREIGN KEY([WOAServedStatus]) REFERENCES [dbo].[WOAServedStatus] ([WSSIntNo]) ALTER TABLE [dbo].[WOA] CHECK CONSTRAINT [FK_WOA_WOAServedStatus] END --add index IF NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_ID(N'[dbo].[WOA]') AND name = N'IX_WOA_WOAServedStatus') BEGIN CREATE NONCLUSTERED INDEX [IX_WOA_WOAServedStatus] ON [dbo].[WOA] ( [WOAServedStatus] ASC )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, IGNORE_DUP_KEY = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 90) ON [PRIMARY] END