Wrox Programmer Forums
|
SQL Server 2000 General discussion of Microsoft SQL Server -- for topics that don't fit in one of the more specific SQL Server forums. version 2000 only. There's a new forum for SQL Server 2005.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the SQL Server 2000 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old October 29th, 2003, 02:09 PM
Registered User
 
Join Date: Oct 2003
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default ALTER TABLE syntax

I'm trying to alter the default value for a column in a table to a blank (there currently is no default and nulls are not allowed). Everything I've tried returns an error. Does anyone know the exact syntax for this?

 
Old October 29th, 2003, 02:30 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 839
Thanks: 0
Thanked 1 Time in 1 Post
Default

A DEFAULT value is a constraint. Constraints can be placed in one of two ways: on a column, or on a table.

A column DEFAULT can only be added when you create the table or when you add a column to a table.

But, you can define a table constraint which is a DEFAULT constraint FOR a given column:

Code:
ALTER TABLE yourtable
    ADD CONSTRAINT someconstraintname DEFAULT <yourdefaultvalue>
        FOR yourcolumn;
By convention DEFAULT constraints are given a name beginning with DF_ if you add then via EM, but you can call it anything you like as long as it is a unique constraint name.

It's sometimes handy to make the change in EM in table design mode, then click the generate script toolbar button and look at what EM would to to effect the change you want to make to the table. What it chooses to do may not always be the most efficient way to do it, but the way it chooses has the advantage that it always (almost, anyway ;)) works.

Jeff Mason
Custom Apps, Inc.
www.custom-apps.com





Similar Threads
Thread Thread Starter Forum Replies Last Post
ALTER TABLE(s) within a LOOP seananderson SQL Server 2000 4 March 16th, 2007 02:05 AM
ALTER TABLE CHECKING moooon MySQL 2 May 5th, 2006 01:56 AM
Alter Table Permissions Colonel Angus SQL Server 2000 2 September 21st, 2005 07:29 AM
(oracle 8i)Alter Table <table> coalesce partition combo Oracle 3 October 13th, 2004 09:35 AM
ALTER TABLE Daniel Schaffer Access ASP 0 April 25th, 2004 12:47 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.