Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Visual Studio Database Project Constraints - Table Script or separate file?

In Visual Studio Database Projects I've seen table constraints being added in 2 different ways:

  1. As part of the same script file used to create the table, after the CREATE TABLE statement;
  2. In a separate file, kept in a "Tables\Constraints" folder, one constraint per file.

Are there good reasons to do one or the other?

Visual Studio does number 2 when importing a database from SQL Server, so I would guess that's the best way, but I can't see why. From a developer point of view number 1 seems better, as it keeps the table definition and constraints "closer" to each other.

like image 206
Farinha Avatar asked May 02 '26 08:05

Farinha


1 Answers

I can only think of reasons to keep them together (#1) for exactly the reasons you mentioned: it keeps the table definition and constraints closer to each other.

Visual Studio used to keep constraints in separate files but stopped that practice in the latest "SQL Server Database Project" template introduced by SQL Server Data Tools (installed in VS 2012 out of the box, and requires a separate download for VS 2010).

like image 105
Keith Avatar answered May 03 '26 23:05

Keith