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 |
|
Mefhisto1
Starting Member
2 Posts |
Posted - 2011-04-14 : 16:08:49
|
| Hi,i want to change a column type on 2 columns, one column references to another (so, they're foreign key and primary key, respectively) but when i try either of those it says they're all dependent and query fails.Then i dropped both constraints (foreign key and primary key) and i was able to change the file type. Then i wanted to add the constraints back, but i wasn't able to do so, because those columns had only PK and FK constraints not 'not null' ones and when i try to add constraints error says unable to add PK constraint on a not null-ed column. Is there any way to do this ?Thank you all in advance |
|
|
Mefhisto1
Starting Member
2 Posts |
Posted - 2011-04-14 : 16:19:36
|
| I've triedalter table blablaalter column bloblo not nullbut that doesn't work ... any thoughts on this ? |
 |
|
|
sunitabeck
Master Smack Fu Yak Hacker
5155 Posts |
Posted - 2011-04-14 : 20:07:52
|
A primary key column has to be non-nullable. So what I suspect is that when you altered the column type, you did not also specify that it should be non-null. If you do the alter column command again, this time specifying that it should be non-null, then you can add the PK.ALTER TABLE YourTable ALTER COLUMN YourCol VARCHAR(10) NOT NULL; |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2011-04-17 : 02:46:40
|
| you need to make sure that there're not any NULL values present in column before you make it NOT NULL. in case it has NULL values make sure you specify a default value. then fire an update to make values unique before making it PK------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
|
|
|