How to set the default value  
Author Message
ismiff





PostPosted: Mon May 23 07:03:51 CDT 2005 Top

SQL Server >> How to set the default value

I want to use SQL to set the default of a field.
How can I implement with DDL?

SQL Server68  
 
 
Uri





PostPosted: Mon May 23 07:03:51 CDT 2005 Top

SQL Server >> How to set the default value ad
CREATE TABLE #Test
(
col1 INT NOT NULL PRIMARY KEY,
col2 DATETIME DEAFULT GETDATE()
)
INSERT INTO #Test (col1) VALUES (1)
GO
SELECT * FROM #Test








> I want to use SQL to set the default of a field.
> How can I implement with DDL?
>
>


 
 
Jens





PostPosted: Mon May 23 07:12:27 CDT 2005 Top

SQL Server >> How to set the default value CREATE TABLE Testdata
(
TestIDCOlumn INT,
TestColumn varchar(10) DEFAULT 'Test'
)

Insert into Testdata(TestIDColumn) Values (1)

Select * from Testdata

Drop Table Testdata

--
HTH, Jens Suessmeyer.

---
http://www.sqlserver2005.de
---


>I want to use SQL to set the default of a field.
> How can I implement with DDL?
>
>


 
 
ad





PostPosted: Mon May 23 16:40:17 CDT 2005 Top

SQL Server >> How to set the default value Thank,
If the TestColumn have create before, but did not set default value yet.
Can I modify the structrue now , set the default value to that column?



> CREATE TABLE Testdata
> (
> TestIDCOlumn INT,
> TestColumn varchar(10) DEFAULT 'Test'
> )
>
> Insert into Testdata(TestIDColumn) Values (1)
>
> Select * from Testdata
>
> Drop Table Testdata
>
> --
> HTH, Jens Suessmeyer.
>
> ---
> http://www.sqlserver2005.de
> ---


> >I want to use SQL to set the default of a field.
> > How can I implement with DDL?
> >
> >
>
>


 
 
Gert-Jan





PostPosted: Mon May 23 16:56:35 CDT 2005 Top

SQL Server >> How to set the default value alter table TestData
add constraint DF_TestDate_TestColumn
default ('Test') for TestColumn

HTH,
Gert-Jan




>
> Thank,
> If the TestColumn have create before, but did not set default value yet.
> Can I modify the structrue now , set the default value to that column?
>


> > CREATE TABLE Testdata
> > (
> > TestIDCOlumn INT,
> > TestColumn varchar(10) DEFAULT 'Test'
> > )
> >
> > Insert into Testdata(TestIDColumn) Values (1)
> >
> > Select * from Testdata
> >
> > Drop Table Testdata
> >
> > --
> > HTH, Jens Suessmeyer.
> >
> > ---
> > http://www.sqlserver2005.de
> > ---


> > >I want to use SQL to set the default of a field.
> > > How can I implement with DDL?
> > >
> > >
> >
> >
 
 
Wayne





PostPosted: Mon May 23 16:53:47 CDT 2005 Top

SQL Server >> How to set the default value You would probably have to
rename the column
add a new column with default value
move data from orig column to new column
drop orig column
rename new column to orig name

--
Wayne Snyder, MCDBA, SQL Server MVP
Mariner, C****te, NC
www.mariner-usa.com
(Please respond only to the newsgroups.)

I support the Professional Association of SQL Server (PASS) and it's
community of SQL Server professionals.
www.sqlpass.org



> Thank,
> If the TestColumn have create before, but did not set default value yet.
> Can I modify the structrue now , set the default value to that column?
>

> ¼¶¼g©ó¶l

>> CREATE TABLE Testdata
>> (
>> TestIDCOlumn INT,
>> TestColumn varchar(10) DEFAULT 'Test'
>> )
>>
>> Insert into Testdata(TestIDColumn) Values (1)
>>
>> Select * from Testdata
>>
>> Drop Table Testdata
>>
>> --
>> HTH, Jens Suessmeyer.
>>
>> ---
>> http://www.hide-link.com/
>> ---


>> >I want to use SQL to set the default of a field.
>> > How can I implement with DDL?
>> >
>> >
>>
>>
>
>