all groups > sql server new users > november 2004 >
You're in the

sql server new users

group:

Newbie: Help with T-SQL


Newbie: Help with T-SQL Kaimuri
11/29/2004 2:40:41 PM
sql server new users:
I have created a table called events with default Start and End Dates. I
would like to modify the EndDate. Here's the table created.

CREATE TABLE Events

(

EventID int IDENTITY(1,1) NOT NULL,

EventType nvarchar(10) NOT NULL Default 'Party', EventTitle nvarchar(100)
NULL, EventDescription ntext NULL, EventLanguage nvarchar (2) NULL,
EventDate smalldatetime NULL DEFAULT GETDATE(), EventEndDate smalldatetime
NULL DEFAULT DATEADD(day, 1, GETDATE()), EventCreator nvarchar (50) NOT NULL
DEFAULT SYSTEM_USER)

I would like to alter the EventEndDate column to

EventEndDate smalldatetime NULL DEFAULT DATEADD(day, 5, GETDATE())

I have tried

Alter Table Events

Alter column EventEndDate smalldatetime NOT NULL DEFAULT DATEADD(day, 5,

GETDATE())

I get the error : Server: Msg 156, Level 15, State 1, Line 2 Incorrect
syntax near the keyword 'DEFAULT'.

Please advise,

Kaimuri

Re: Newbie: Help with T-SQL Tom Moreau
11/29/2004 8:48:23 PM
That's what happens when you don't name your constraints. Run
sp_helpconstraint to get the name of your constraint:

sp_helpconstraint Events

Pick out the relevant default and drop it:

alter table events drop constraint DF__Events__EventEnd__61130711
go

Next, add in the correct default:

alter table Events add constraint DF1_Events default (DATEADD(day, 5,
GETDATE())) for EventEndDate
go



--
Tom

----------------------------------------------------
Thomas A. Moreau, BSc, PhD, MCSE, MCDBA
SQL Server MVP
Columnist, SQL Server Professional
Toronto, ON Canada
www.pinnaclepublishing.com
..
[quoted text, click to view]
I have created a table called events with default Start and End Dates. I
would like to modify the EndDate. Here's the table created.

CREATE TABLE Events

(

EventID int IDENTITY(1,1) NOT NULL,

EventType nvarchar(10) NOT NULL Default 'Party', EventTitle nvarchar(100)
NULL, EventDescription ntext NULL, EventLanguage nvarchar (2) NULL,
EventDate smalldatetime NULL DEFAULT GETDATE(), EventEndDate smalldatetime
NULL DEFAULT DATEADD(day, 1, GETDATE()), EventCreator nvarchar (50) NOT NULL
DEFAULT SYSTEM_USER)

I would like to alter the EventEndDate column to

EventEndDate smalldatetime NULL DEFAULT DATEADD(day, 5, GETDATE())

I have tried

Alter Table Events

Alter column EventEndDate smalldatetime NOT NULL DEFAULT DATEADD(day, 5,

GETDATE())

I get the error : Server: Msg 156, Level 15, State 1, Line 2 Incorrect
syntax near the keyword 'DEFAULT'.

Please advise,

Kaimuri

Re: Newbie: Help with T-SQL Kaimuri
12/7/2004 4:50:38 PM
Thanks..that worked..now I'll get into the habit of naming all my
constraints. It makes life a lot easier.

[quoted text, click to view]

Re: Newbie: Help with T-SQL Tom Moreau
12/7/2004 6:57:56 PM
You got that right!

--
Tom

----------------------------------------------------
Thomas A. Moreau, BSc, PhD, MCSE, MCDBA
SQL Server MVP
Columnist, SQL Server Professional
Toronto, ON Canada
www.pinnaclepublishing.com
..
[quoted text, click to view]
Thanks..that worked..now I'll get into the habit of naming all my
constraints. It makes life a lot easier.

[quoted text, click to view]

AddThis Social Bookmark Button