I am working on SQL Server 2008 R2, where I generated a schema-only database script using SQL Server Management Studio. The generated script is as follows:
ALTER TABLE [dbo].[ConsoleServer] WITH CHECK ADD CONSTRAINT [FK_ConsoleServer_RackUnits] FOREIGN KEY([RackUnitID]) REFERENCES [dbo].[RackUnits] ([UnitID]) GO ALTER TABLE [dbo].[ConsoleServer] CHECK CONSTRAINT [FK_ConsoleServer_RackUnits]
I have these 2 questions:-
I know that the first line is responsible to create a FK between two DB tables. but what is the purpose of the following :
ALTER TABLE [dbo].[ConsoleServer] CHECK CONSTRAINT [FK_ConsoleServer_RackUnits]
I mean since I have specified to add the constraint with check, why do i need to enable the constraint using check constraint ?
Second question: In general, why does the DB script has the word GO. Now if I remove it the script will be executed well on the destination DB, so why it is included in the script prior to any statement?