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 |
Adam West
Constraint Violating Yak Guru
261 Posts |
Posted - 2009-08-04 : 12:09:20
|
I have a table of colors for use in a chart.Right now, not all categories have a color but I want the categories entered into the table with the color as blank but I am getting this errorCannot insert the value NULL into column 'Color', table 'CDEV_MODS.dbo.Colors'; column does not allow nulls. INSERT fails.The statement has been terminated. |
|
Transact Charlie
Master Smack Fu Yak Hacker
3451 Posts |
Posted - 2009-08-04 : 12:20:17
|
post your table definition.How are you implementing the [colors] column? A foreign key to a colours table? or are you denormalised (using VARCHAR and 'BLUE', 'RED') etc.I'm guessing your column definition doesn't allow nulls (is it the primary key of the table?)Charlie===============================================================Msg 3903, Level 16, State 1, Line 1736The ROLLBACK TRANSACTION request has no corresponding BEGIN TRANSACTION |
|
|
Adam West
Constraint Violating Yak Guru
261 Posts |
Posted - 2009-08-04 : 12:25:53
|
Description (varchar (50) not null)Color (varchar (50) not null)no keys or indexes. This was setup by an outside developer. What happened was I deleted the rows by accident and have to recreate this. |
|
|
Transact Charlie
Master Smack Fu Yak Hacker
3451 Posts |
Posted - 2009-08-04 : 12:32:19
|
your column definition says NOT NULL. you can't put NULLS in it.Check out the ALTER TABLE statement in books online to change this..You should still be able to put the empty string '' instead but NULL is much more suitable for Not / appropriate / UnkownCharlie===============================================================Msg 3903, Level 16, State 1, Line 1736The ROLLBACK TRANSACTION request has no corresponding BEGIN TRANSACTION |
|
|
Adam West
Constraint Violating Yak Guru
261 Posts |
Posted - 2009-08-04 : 13:48:01
|
I tried this but it doesn't compileALTER TABLE colorsMODIFY color varchar(50) null |
|
|
Transact Charlie
Master Smack Fu Yak Hacker
3451 Posts |
Posted - 2009-08-05 : 05:09:17
|
your syntax is wrong.example:IF OBJECT_ID('tempdb..#foo') IS NOT NULL DROP TABLE #fooGOCREATE TABLE #foo ( [id] INT IDENTITY(1,1) , [val] VARCHAR(50) NOT NULL )goINSERT #foo ([val])VALUES (NULL)GOALTER TABLE #foo ALTER COLUMN [val] VARCHAR(50) NULLGOINSERT #foo ([val])VALUES (NULL)GOSELECT * FROM #foo Charlie===============================================================Msg 3903, Level 16, State 1, Line 1736The ROLLBACK TRANSACTION request has no corresponding BEGIN TRANSACTION |
|
|
|
|
|
|
|