This is a discussion on Re: Should the CREATE TABLE statement include CONSTRAINTS? within the SQL Server forums, part of the Microsoft SQL Server category; --> We maintain individual scripts (under source control) for constraints. This allows us to use the same constraint scripts for ...
| |||||||
| Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| ||||
| We maintain individual scripts (under source control) for constraints. This allows us to use the same constraint scripts for new installs and, when necessary, upgrades. -- Hope this helps. Dan Guzman SQL Server MVP ----------------------- SQL FAQ links (courtesy Neil Pike): http://www.ntfaq.com/Articles/Index....partmentID=800 http://www.sqlserverfaq.com http://www.mssqlserver.com/faq ----------------------- "Jason Berkan" <jason_berkan@canada.com> wrote in message news:3f4f7255.3759573@enews.newsguy.com... > Forgive me if this question has an obvious answer, but I am trying to > figure out the "best practices" for designing a database, and am > fairly new to SQL/relational databases, having worked with flat file > databases for years. > > When you write the CREATE TABLE statements for a database, should you > include the constraints as part of the create statement, or should the > constraints be added later via ALTER TABLE statements? > > In CREATE TABLE: > > CREATE TABLE [dbo].[Testing] ( > [Description] [varchar] (30) NOT NULL , > [Active] [bit] NOT NULL , > CONSTRAINT [PK_Testing] PRIMARY KEY CLUSTERED ( > [Description] > ) > ) > > Through ALTER TABLE: > > CREATE TABLE [dbo].[Testing] ( > [Description] [varchar] (30) NOT NULL , > [Active] [bit] NOT NULL , > ) > GO > > ALTER TABLE [dbo].[Testing] > ADD CONSTRAINT [PK_Testing] PRIMARY KEY CLUSTERED ( > [Description] > ) > > My initial thought is to add the constraints later, via ALTER TABLE, > as that allows all the tables to be created before foreign key > relationships are setup, thus preventing the problem where table A > must be created before table B. Is there anything else I should be > considering? > > Jason |