473,651 Members | 2,792 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

changing the default value for a column

Does anybody know how I can change the default value for a column?
I was trying to remove the default value in order to add the new one
afterwards. This is what I tried:

alter table /table-name/ drop default for /column-name/
alter table /table-name/ alter column /column-name/
(/new-decl-without-default/)

It did not work. I cannot find a solution in the documentation. Maybe
you can help me out?

Thank you,
Johan
Jul 23 '05 #1
4 14345
ALTER TABLE table_name
DROP CONSTRAINT name_of_default _constraint

ALTER TABLE table_name
ADD CONSTRAINT name_of_default _constraint DEFAULT 123 FOR column_name
--
David Portas
SQL Server MVP
--

Jul 23 '05 #2
David Portas schreef:
ALTER TABLE table_name
DROP CONSTRAINT name_of_default _constraint


Thank you for the quick reply. But how do I know the
name_of_default _constraint? I created the default value like this:

alter table /table_name/ add default /default_value/ for /column_name/

Johan
Jul 23 '05 #3
It's a good idea to give constraints meaningful names when you create
them, otherwise the server assigns them an obscure unique identifier
name. Use a consistent naming convention and then you'll know the
constraint names for tables and columns.

You can find the name of an existing default using the Object Browser
in Query Analyzer or in the output of sp_help 'table_name'
--
David Portas
SQL Server MVP
--

Jul 23 '05 #4
Hi,

something like this could meet your requirements:

declare @myStatement nvarchar(4000)

select @myStatement=(' ALTER TABLE RP_CUSTOM_ATTRI BUTE DROP CONSTRAINT ' +
(select so.name
from sysobjects so, syscolumns sc
where sc.name = 'YOUR_COLUMN_NA ME' and sc.cdefault = so.id))

EXEC sp_executesql @myStatement
go

Karsten

"Johan Vervloet" <jo****@chiro.b e> schrieb im Newsbeitrag
news:41******** *************** @news.xs4all.nl ...
David Portas schreef:
ALTER TABLE table_name
DROP CONSTRAINT name_of_default _constraint


Thank you for the quick reply. But how do I know the
name_of_default _constraint? I created the default value like this:

alter table /table_name/ add default /default_value/ for /column_name/

Johan


Jul 23 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
11120
by: David Wright | last post by:
How can i change the default value of a column? I already have a column named DateOfRental but I want to alter it so that it has default value getdate() Thanks David -- http://www.nintendo-europe.com/NOE/en/GB/register/index.jsp?m=l&a=Prodigious
2
4272
by: akl | last post by:
How can I create such a default value that it depends on the value in other field (drop down)? So that the default value would be updated every time I change the value of drop-down field.
5
2558
by: HandersonVA | last post by:
should I set to "0" as a default value on a quantity and a price field or set to "null"? if a user enter nothing on the quantity or price field on a web browser, should I treat it as null or "0"? I am so confused about this concept. please advise me. thank you.
3
13657
by: binder | last post by:
I am designing a new table with a few columns that may or may not have a value on each row that is inserted. What issues determine whether to allow a NULL value to be inserted for that column or define a default value to be used? I want to think through the repercussions of this decision before I get into production.
0
2784
by: spatik | last post by:
Hi, I have a tableevent] with a columnevent_description] as ntext and default value ''. Now, I want to change the column type to nvarchar(max) using this script, alter table alter column nvarchar(max) null ; The event_description column was created with a default value ''. Now this constraint is not allowing me to alter the column type. It throws an exception, Msg 5074, Level 16, State 1, Line 1
8
18992
by: Leon_Amirreza | last post by:
I have a column named "ID" and its type is "uniqueidentifier" in SQL Server 2005 Express. this column is the primary key and its default value is "newid()" in SQL Server. I have generated a DataSet in C# that has this column but its default value is DBNull what can I do to make the default value be the return value of this function ( or I want the Id be generated by default in the DataSet)? System.Guid.NewGuid()
6
2607
by: JC21 | last post by:
Hi All, On my main table(tblCust) I have a field called Status, the default value is set to No. All the accounts currently in the table have a default value No. On my form I have a combo box(cboCust) when an option is selected from the combo box, the account is copied to another table. In the After Update event in the combo box there is an event procedure. My question is there a way for me to change the default value of that account in the...
4
2340
by: Torilyn73 | last post by:
I have a combo box set up off a query. I want the default value to be the column heading so I don't have to put a label over it. So far I haven't been able to figure this out. Can anyone tell me if this is possible... and if so..how? Thanks!
1
2260
by: vinodkus | last post by:
dear sir/madam what is the syntex for changing default value. table name is test uno numeric(9) name1 char(10) address char(10) default value of addres is set to 'delhi' i have to change it to 'patna'
0
8352
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8275
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8697
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8465
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
6158
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5612
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4283
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2699
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1587
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.