Unix Technical Forum

Re: Should the CREATE TABLE statement include CONSTRAINTS?

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 ...


Go Back   Unix Technical Forum > Database Server Software > Microsoft SQL Server > SQL Server

Register FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 02-28-2008, 05:41 PM
Dan Guzman
 
Posts: n/a
Default Re: Should the CREATE TABLE statement include CONSTRAINTS?

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



Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 01:10 AM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0
www.UnixAdminTalk.com