This may be a stupid question, but I'm not a DBA and just wanna make sure of what I'm doing before I make a mistake.
Here is my question: When dropping Constraints, are their indexes dropped as well?
Basically, I'm asking because I want to modify an existing constraint. I want to change the foreign key to another column.
Here was the original query to create them:
-- Creating foreign key on [Industry_Id] in table 'Courses'
ALTER TABLE [dbo].[Courses]
ADD CONSTRAINT [FK_CourseIndustry]
FOREIGN KEY ([Industry_Id])
REFERENCES [dbo].[Industries]
([Id])
ON DELETE NO ACTION ON UPDATE NO ACTION;
-- Creating non-clustered index for FOREIGN KEY 'FK_CourseIndustry'
CREATE INDEX [IX_FK_CourseIndustry]
ON [dbo].[Courses]
([Industry_Id]);
GO
Here is what I'm thinking of doing:
IF OBJECT_ID(N'[dbo].[FK_CourseIndustry]', 'F') IS NOT NULL
ALTER TABLE [dbo].[Courses] DROP CONSTRAINT [FK_CourseIndustry];
GO
-- Creating foreign key on [IndustryId] in table 'Courses'
ALTER TABLE [dbo].[Courses]
ADD CONSTRAINT [FK_CourseIndustry]
FOREIGN KEY ([IndustryId])
REFERENCES [dbo].[Industries]
([Id])
ON DELETE NO ACTION ON UPDATE NO ACTION;
-- Creating non-clustered index for FOREIGN KEY 'FK_CourseIndustry'
CREATE INDEX [IX_FK_CourseIndustry]
ON [dbo].[Courses]
([IndustryId]);
GO
Is that enough and will it work? Honestly, I don't mind if it's not an elegant solution just so long as it works.
Any piece of advise or information would be highly appreciated. Thanks!