Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

I am trying to alter a column within a table and set the default value to 0:

 

I am using SQL Server 2000

 

here is what I am using (it gives 'incorrect syntax near DEFAULT')

 

alter table chronology alter column oper_id numeric(10,0) set default 0 not null

  • *Experts*
Posted

Your syntax is close, but a bit off. At least, it's off if you're using SQL Server:

alter table chronology alter column oper_id numeric(10,0) not null DEFAULT 0 

At least, that's the syntax when using "add" column, not sure if you can set a default when altering a column. I would think so, but not positive. If not, you can always do a mass update followed by an alter that sets the column to NOT NULL.

 

-ner

"I want to stand as close to the edge as I can without going over. Out on the edge you see all the kinds of things you can't see from the center." - Kurt Vonnegut
  • *Experts*
Posted

Yep, I read the help more and see there's no option to set a default for an existing column that would update the data.

 

Assuming you've already got the column in the table but want to change to not null, do the mass update before altering the table/column:

UPDATE chronology SET oper_id = 0 WHERE oper_id IS NULL
GO -- The GO is optional
alter table chronology alter column oper_id numeric(10,0) not null

 

-ner

"I want to stand as close to the edge as I can without going over. Out on the edge you see all the kinds of things you can't see from the center." - Kurt Vonnegut

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...