>>ALTER TABLE [dbo].[MyTable] ADD CONSTRAINT [IX_CATEGORY_UNIQUE] UNIQUE NONCLUSTERED >>( >> [CATEGORY] ASC >>)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, IGNORE_DUP_KEY = OFF, ONLINE = >>OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY] >>GO >>>>
>TEXT TO lcSQL NOSHOW > ALTER TABLE [dbo].[MyTable] DROP CONSTRAINT [IX_CATEGORY_UNIQUE] >ENTEXT >IF SQLEXECT(sqlHandler, lcSQL) < 0 > AERROR(laError) > MessageBox(laError[1,2]) > RETURN >ENDIF > >TEXT TO lcSQL NOSHOW >ALTER TABLE [dbo].[MyTable] ADD CONSTRAINT [IX_CATEGORY_UNIQUE] UNIQUE NONCLUSTERED >( > [SITE_NO],[CATEGORY] >)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, IGNORE_DUP_KEY = OFF, ONLINE = >OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY] >ENDTEXT >IF SQLEXECT(sqlHandler, lcSQL) < 0 > AERROR(laError) > MessageBox(laError[1,2]) >ENDIF >Thank you very much for your code. I usually run this code on program update (which is done not often but still somewhat a repeat procedure). And I want to avoid having to run this code every time. So I would probably name the second constraint (on SITE_NO, CATEGORY) a little different. For example, IX_TABLE_CATEGORY_UNIQUE. But in this case, what happens when I run this code the 2nd time and the constraint IX_CATEGORY_UNIQUE does not exist and still the code tries to drop it. Then, there will be an error.