all groups > sql server programming > december 2004 >
You're in the

sql server programming

group:

What is wrong with this simple line?


What is wrong with this simple line? jayesh131 NO[at]SPAM hotmail.com
12/5/2004 9:54:03 PM
sql server programming:
IF NOT EXISTS(SELECT [Name] FROM sysobjects WHERE [Name] =
'dfltStatus' AND type = 'D')
CREATE DEFAULT dfltStatus AS 1


I get the following error msg:
Incorrect syntax near the keyword 'DEFAULT'.

Note, the statement "CREATE DEFAULT dfltStatus AS 1" and the SQL
statement
"SELECT [Name] FROM sysobjects WHERE [Name] = 'dfltStatus' AND type =
'D'" work fine on their own.


Re: What is wrong with this simple line? Kalen Delaney
12/5/2004 10:12:37 PM
Hi Jay

I believe problem is that CREATE DEFAULT has to be in a batch all by itself.

Try this instead:

IF EXISTS(SELECT [Name] FROM sysobjects WHERE [Name] =
'dfltStatus' AND type = 'D')
DROP DEFAULT dfltStatus
GO
CREATE DEFAULT dfltStatus AS 1


--
HTH
----------------
Kalen Delaney
SQL Server MVP
www.SolidQualityLearning.com


[quoted text, click to view]

Re: What is wrong with this simple line? Kalen Delaney
12/6/2004 8:42:48 AM
Hi Jack

If you run this code, you actually get confirmation of what I said in my
reply:

'CREATE DEFAULT' must be the first statement in a query batch.

He will have to do the drop and the create in separate batches.

--
HTH
----------------
Kalen Delaney
SQL Server MVP
www.SolidQualityLearning.com


[quoted text, click to view]

Re: What is wrong with this simple line? jack.lee
12/6/2004 2:28:56 PM
Hi Jay,
You have to create default as the following code:
IF NOT EXISTS(SELECT [Name] FROM sysobjects WHERE [Name] =
'dfltStatus' AND type = 'D')
Begin
DROP DEFAULT dfltStatus
End
CREATE DEFAULT dfltStatus AS 1

Thanks!
Jack

"Jay" <jayesh131@hotmail.com> ????
news:fb0ff48e.0412052154.269c3168@posting.google.com...
[quoted text, click to view]

AddThis Social Bookmark Button