Friday, February 24, 2012

Default Value Prorperty

I have a question, and I can't seem to find a reference to
it anywhere, so I am hoping someone out here can assist.
Is there any way to programmatically change the Default
Value Property value ?
I have several tables with a default value of 1 setup, and
I would like to change them all to a different value.
Possible ?
Thanks in advance for your assistance !
Michael.
Hi,
You have to drop the default constraint and add the new default constraint.
See the below steps with code.
See SP_HELP <table_name> to get the constarint name
Create a table with default constraint
create table x_df(i int, j int default (100))
After that drop the constraint.
alter table x_df drop constraint <constraint_name>
Add the constraint
ALTER TABLE x_df ADD CONSTRAINT defaul1_cons DEFAULT (200) for j
Thanks
Hari
MCDBA
"Michael" <MYKLIV@.hotmail.com> wrote in message
news:479201c48007$985043e0$a501280a@.phx.gbl...
> I have a question, and I can't seem to find a reference to
> it anywhere, so I am hoping someone out here can assist.
> Is there any way to programmatically change the Default
> Value Property value ?
> I have several tables with a default value of 1 setup, and
> I would like to change them all to a different value.
> Possible ?
> Thanks in advance for your assistance !
> Michael.
|||Thanks, worked like a charm !

>--Original Message--
>Hi,
>You have to drop the default constraint and add the new
default constraint.
>See the below steps with code.
>See SP_HELP <table_name> to get the constarint name
>Create a table with default constraint
>create table x_df(i int, j int default (100))
>After that drop the constraint.
>alter table x_df drop constraint <constraint_name>
>Add the constraint
>ALTER TABLE x_df ADD CONSTRAINT defaul1_cons DEFAULT
(200) for j[vbcol=seagreen]
>Thanks
>Hari
>MCDBA
>
>
>"Michael" <MYKLIV@.hotmail.com> wrote in message
>news:479201c48007$985043e0$a501280a@.phx.gbl...
to[vbcol=seagreen]
and
>
>.
>
|||Ok, that does work fine, but now I would like to scroll
through several tables. I cant seem to get the Alter
Table<table_name> to respond to a declared variable.
This is what I am using to test it...
************************************************** ********
Declare @.TableName varchar(30), @.ConstName varchar(30)
set @.TableName = 'tblS01Test'
set @.ConstName = 'DF_' + @.TableName + '_ExerciseID'
Print @.TableName
Print @.ConstName
Alter Table @.TableName add constraint @.ConstName default
(1) for ExerciseID
************************************************** ******
Ultimately I am trying to use this to alter several tables
ExerciseID ('s), and figure that I can use a cursor to do
so.
Thanks for any and all advice !!
Michael.

>--Original Message--
>Hi,
>You have to drop the default constraint and add the new
default constraint.
>See the below steps with code.
>See SP_HELP <table_name> to get the constarint name
>Create a table with default constraint
>create table x_df(i int, j int default (100))
>After that drop the constraint.
>alter table x_df drop constraint <constraint_name>
>Add the constraint
>ALTER TABLE x_df ADD CONSTRAINT defaul1_cons DEFAULT
(200) for j[vbcol=seagreen]
>Thanks
>Hari
>MCDBA
>
>
>"Michael" <MYKLIV@.hotmail.com> wrote in message
>news:479201c48007$985043e0$a501280a@.phx.gbl...
to[vbcol=seagreen]
and
>
>.
>

No comments:

Post a Comment