Note: This question is not related to Visual Paradigm. Anyone that knows SQL could answer it.
I am using Visual Paradigm to model a database in our project (using ER diagrams). When Visual Paradigm generates the SQL equivalent for the database and I import it in MSSQL it works pretty.
I took a look in generated SQL code to make sure anything is right and I saw something strange!:
For tblContracts
I defined a constraint named EndAfterStart
to make sure the value of endDate
is always bigger than startDate
. The generated SQL code for this constraint is here:
IF NOT EXISTS (SELECT * FROM sys.check_constraints WHERE object_id=OBJECT_ID(N'[dbo].[EndAfterStart]'))
ALTER TABLE [dbo].[tblContracts] WITH CHECK ADD CONSTRAINT [EndAfterStart] CHECK (([startDate]<=[endDate]))
GO
ALTER TABLE [dbo].[tblContracts] CHECK CONSTRAINT [EndAfterStart]
GO
And the questions:
- Why
tblContracts
is altered twice to add this开发者_Go百科 constraint?! - Isn't first two lines enough?
- What is different between second line and forth line?
First and second lines create EndAfterStart
constraint if it doesn't exist. Fourth line enables EndAfterStart
constraint.
The second line adds the constraint to the table; the fourth line enables the constraint.
精彩评论