Gmail Calendar Documents Reader Web more »
Recently Visited Groups | Help | Sign in
Google Groups Home
T-SQL to change a default value.
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  4 messages - Expand all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Chris Scheers  
View profile  
 More options Nov 7 2000, 3:00 am
Newsgroups: comp.databases.ms-sqlserver
From: Chris Scheers <ch...@applied-synergy.com>
Date: 2000/11/07
Subject: T-SQL to change a default value.
I'm a newbie to MSSQL7, and am a bit mystified as to how to proceed.

I need to write a T-SQL script to update a database without disturbing
existing data.  Part of the update includes clearing the NULL flag and
setting a default value.

I have code to clear the NULL flag.  I can also set a default value, but
only if one doesn't already exist.

To change a default, the documentation for ALTER TABLE says that the
existing DEFAULT must be dropped, but it doesn't say how.

It appears that the default value is actually a constraint.  Quite
often, the constraint is named DF_<table>_<column>, but not
necessarilly.  If I can find the constraint name, it appears that I can
drop it and then add a new default value.

How can I find the name of the constraint that implements the DEFAULT
value?

How can I find out if the column currently has a DEFAULT value?

Am I going at this wrong?

Thanx!

-----------------------------------------------------------------------
Chris Scheers, Applied Synergy, Inc.

Voice: 817-237-3360            Internet: ch...@applied-synergy.com
  Fax: 817-237-3074


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Dan Guzman  
View profile  
 More options Nov 7 2000, 11:46 pm
Newsgroups: comp.databases.ms-sqlserver
From: "Dan Guzman" <danguz...@nospam-earthlink.net>
Date: Wed, 08 Nov 2000 04:46:34 GMT
Local: Tues, Nov 7 2000 11:46 pm
Subject: Re: T-SQL to change a default value.
To list the current constraints on a table:

    EXEC sp_help TableName

Hope this helps.

"Chris Scheers" <ch...@applied-synergy.com> wrote in message

news:96ACF408D83E4F38.25603A781BE00CA6.C79E1896010C54C3@lp.airnews.net...


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Chris Scheers  
View profile  
 More options Nov 8 2000, 3:00 am
Newsgroups: comp.databases.ms-sqlserver
From: Chris Scheers <ch...@applied-synergy.com>
Date: 2000/11/08
Subject: Re: T-SQL to change a default value.

Dan Guzman wrote:

> To list the current constraints on a table:

>     EXEC sp_help TableName

> Hope this helps.

Not really.  I need to know how to do this from a script.  Any
suggestions?

Is there an FAQ for this type of question?

-----------------------------------------------------------------------
Chris Scheers, Applied Synergy, Inc.

Voice: 817-237-3360            Internet: ch...@applied-synergy.com
  Fax: 817-237-3074


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Dick Christoph  
View profile  
 More options Nov 11 2000, 3:00 am
Newsgroups: comp.databases.ms-sqlserver
From: "Dick Christoph" <dchri...@minn.net>
Date: 2000/11/11
Subject: Re: T-SQL to change a default value.
Hi Chris

To Drop a constriant (Default value) you would say:

ALTER TABLE TestNames Drop CONSTRAINT [DF_TestNames_Value]

To Create a Default value you would say:

ALTER TABLE TestNames WITH NOCHECK ADD
 CONSTRAINT [DF_TestNames_Value] DEFAULT (0) FOR [Value]
GO

To find out iof a constraint exists, look at the code in stored procedure
sp_HelpConstraint in the Master Database. Use the Ent. Mgr to go to that SP
and check its properties.

That procedure returns the constratint name in the second result set and by
copying and editing this code you can probably determine which system tables
to query to determine if a constraint exists.

Be very careful of course, not to actually alter the Text of
sp_HelpConstraint, or that function may stop working on your SQL Server.

HTH

-Dick Christoph

"Chris Scheers" <ch...@applied-synergy.com> wrote in message

news:96ACF408D83E4F38.25603A781BE00CA6.C79E1896010C54C3@lp.airnews.net...


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »

Create a group - Google Groups - Google Home - Terms of Service - Privacy Policy
©2009 Google