Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
rajasekhar857
Constraint Violating Yak Guru
396 Posts |
Posted - 2009-05-19 : 07:29:09
|
| hi,i am having a table CREATE TABLE [dbo].[EMREchartCategoriesLkup] ( [ECHART_CATEGORY_ID] [NUMERIC](20,0) NOT NULL, [ECHART_CATEGORY_NAME] [VARCHAR](50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL, [GROUP_ID] [NUMERIC](20,0) NULL, [ECHART_STATUS] [BIT] NULL)ON [PRIMARY]GOand having constraints 1)ALTER TABLE [dbo].[EMREchartCategoriesLkup] WITH NOCHECK ADD CONSTRAINT [PK_echartcategorieslkup] PRIMARY KEY CLUSTERED ( [ECHART_CATEGORY_ID] ) ON [PRIMARY]GO2)ALTER TABLE [dbo].[EMREchartCategoriesLkup] ADD CONSTRAINT [DF_EMREchartCategoriesLkup_ECHART_STATUS] DEFAULT (1) FOR [ECHART_STATUS]GOi want to change datatype from bit to numericwhen i use thisalter table EMREchartCategoriesLkup alter column ECHART_STATUS numeric(10,0)error message:Msg 5074, Level 16, State 1, Line 1The object 'DF_EMREchartCategoriesLkup_ECHART_STATUS' is dependent on column 'ECHART_STATUS'.Msg 4922, Level 16, State 9, Line 1ALTER TABLE ALTER COLUMN ECHART_STATUS failed because one or more objects access this column.how can i change the data type from bit to numeric |
|
|
robvolk
Most Valuable Yak
15732 Posts |
Posted - 2009-05-19 : 07:49:19
|
| You have to drop the default on that column first, change the data type, then add the default constraint back. |
 |
|
|
rajasekhar857
Constraint Violating Yak Guru
396 Posts |
Posted - 2009-05-19 : 08:11:52
|
| is there no harm in doing such thing right? |
 |
|
|
robvolk
Most Valuable Yak
15732 Posts |
Posted - 2009-05-19 : 10:12:54
|
| Nope, as long as you don't insert any new data while the default has been dropped. |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2009-05-19 : 10:42:48
|
| you can do drop and add in same script itself so that it happens immediately without much delay |
 |
|
|
|
|
|
|
|