Re: Alter Column

Tech-Archive recommends: Fix windows errors by optimizing your registry

From: Mark Allison (marka_at_no.tinned.meat.mvps.org)
Date: 10/19/04


Date: Tue, 19 Oct 2004 11:08:14 +0100

Bob,

You need to add a constraint to the column:

ALTER TABLE [tablename]
ADD CONSTRAINT <constraintname>
DEFAULT getdate() FOR [columnB]

--
Mark Allison, SQL Server MVP
http://www.markallison.co.uk
Looking for a SQL Server replication book?
http://www.nwsu.com/0974973602m.html
Bob Trask wrote:
> Hi
> 
> How come this doesnt work?
> 
> 
> ALTER TABLE [tablename] ALTER COLUMN [columnB] SET DEFAULT getdate()
> 
> Server: Msg 156, Level 15, State 1, Line 2
> Incorrect syntax near the keyword 'SET'.
> 
> 


Relevant Pages

  • Re: Cant DROP CONSTRAINT DF_ on a bit data type?
    ... ALTER TABLE MyTable DROP CONSTRAINT DF_MyTable_MyField ... Pro SQL Server 2000 Database Design - ... > Customers = MyTable ... >>> ALTER TABLE MyTable DROP CONSTRAINT DF_MyTable_MyField>>> ...
    (microsoft.public.sqlserver.programming)
  • Re: T-SQL: Deleting Column Defaults (Not Default Objects)
    ... You definitely have to get to the constraint name. ... Tibor Karaszi, SQL Server MVP ... "Simon E" wrote in message ... > defined in the CREATE TABLE or ALTER TABLE statements, ...
    (microsoft.public.sqlserver.programming)
  • Re: alter table
    ... The alter table command is used to modify the logical structure ... It is not a SQL Standard that a unique constraint has to create a unique ... is how SQL Server implements unique constraint. ... > alter table tablename add constraint IX_custid unique nonclustered custid ...
    (microsoft.public.sqlserver.programming)
  • Re: ALTER TABLE statement conflicted with COLUMN FOREIGN KEY
    ... Columnist, SQL Server Professional ... "ALTER TABLE statement conflicted with COLUMN FOREIGN KEY ... CONSTRAINT FOREIGN KEY ...
    (microsoft.public.sqlserver.server)
  • Re: Simple Question
    ... alter table t add constraint pk primary key ... insert into t select 'a', 1, getdate() ...
    (microsoft.public.sqlserver.programming)