Setting Key Constraints using a Diagram
-
20-12-2020 - |
Question
I been using SSMS for diagramming my databases and I got used to create the key constraints with this tool. Now I started thinking, while going through related chapter of a book, "...maybe this is not such a good practice"
Is there any downside towards this practice? That is defining key constraints using the Diagram Designer on SSMS?
Solution
I would suggest NOT to use Designer in creating key constraints or doing any DDL / DML operations.
Best is to use T-SQL - much flexible, more options, more powerful and you can automate many things with it. There is a learning curve, but its worth learning TSQL rather than keep using GUI.
Also, make sure you are using the latest version of SSMS - sql server 2014. Download it from here.
Read up : Managing SQL Server via Management Studio vs TSQL Commands
e.g. From BOL
ALTER TABLE dbo.DocExc
ADD ColumnD int NULL
CONSTRAINT CHK_ColumnD_DocExc -----> This is your constraint
CHECK (ColumnD > 10 AND ColumnD < 50);
GO