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 |
|
tvspsekhar
Starting Member
20 Posts |
Posted - 2010-03-08 : 06:06:18
|
| Please help me in correcting the following query. ( Even though no null data is available in locno column, it is not being executed.alter table towersch add primary key(locno);error message:Msg 8111, Level 16, State 1, Line 1Cannot define PRIMARY KEY constraint on nullable column in table 'towersch'.Msg 1750, Level 16, State 0, Line 1Could not create constraint. See previous errors.locno twrtypw span fdn count earth1/0 DA+0 325.00 DFR 1 NULL1/1 DA+0 276.00 DRY 1 NULL1/2 DA+3 346.00 DFR 1 NULL1/3 DA+6 222.00 DFR 1 NULL1/4 DA+0 256.00 DFR 1 NULL2/0 DC+0 333.00 DFR 1 NULL2/1 DA+9 290.00 DRY 1 NULL2/2 DA+0 329.00 PS 1 NULL2/3 DA+3 290.00 PS 1 NULL3/0 DB+3 333.00 WFR 1 NULL3/1 DA+3 239.00 WFR 1 NULL3/2 DA+6 328.00 SFR 1 NULL4/0 DC+9 289.00 WET 1 NULL4/1 DA+0 324.00 WET 1 NULL4/2 DA+9 389.00 WET 1 NULL5/0 DB+6 400.00 WET 1 NULL5/1 DA+6 375.00 DFR 1 NULL5/2 DA+0 267.00 WET 1 NULL6/0 DB+3 300.00 WET 1 NULLtvspsekhar |
|
|
AndrewMurphy
Master Smack Fu Yak Hacker
2916 Posts |
Posted - 2010-03-08 : 06:20:56
|
| the problem is not that there are currently no null data itemsthe column "as defined" allows nulls in future.fix this and then your primary key can be added. |
 |
|
|
raky
Aged Yak Warrior
767 Posts |
Posted - 2010-03-08 : 07:33:49
|
| try thisalter table towersch alter column locno <dataType> not nullgoalter table towersch add primary key(locno) |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2010-03-08 : 09:50:30
|
quote: Originally posted by raky try thisalter table towersch alter column locno <dataType> not nullgoalter table towersch add primary key(locno)
where did you get latter syntax from? It wont work in SQL Server------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
Lamprey
Master Smack Fu Yak Hacker
4614 Posts |
Posted - 2010-03-08 : 13:19:45
|
quote: Originally posted by visakh16
quote: Originally posted by raky try thisalter table towersch alter column locno <dataType> not nullgoalter table towersch add primary key(locno)
where did you get latter syntax from? It wont work in SQL Server------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/
It'll work in 2005 and 2008. Not sure about previous versions of SQL.But, I'd suggest naming the constraint:ALTER TABLE <table name> ADD CONSTRAINT <constriant name> PRIMARY KEY CLUSTERED (<column(s)>) |
 |
|
|
|
|
|