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.

 All Forums
 SQL Server 2008 Forums
 Other SQL Server 2008 Topics
 Re:Problem with modifying table

Author  Topic 

spradhan
Starting Member

3 Posts

Posted - 2010-03-18 : 18:32:00
Actually i create field and assign as foriegn key for table and accidentally i allow null for that field in table but in primary table it is primary key and don't allow null.So when i found that i allow null for that field i changed it to not allow null and try to save table but it didn't allow to save or modify table.

So how can i save table.

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2010-03-18 : 20:41:48
Drop the foreign key, alter the column, then add the foreign key back.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

spradhan
Starting Member

3 Posts

Posted - 2010-03-19 : 18:46:29
I try it as you mention but again i get message like this:
Unable to modify table.
Cannot insert the value NULL into column 'HistoryID', table 'MyDatabase.dbo.Tmp_tblMHistory'; column does not allow nulls. INSERT fails.
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2010-03-19 : 18:54:14
I don't understand what you want then as your error mentions an INSERT statement, yet that's not what you mentioned in your original post.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2010-03-20 : 01:47:57
you cant modify an existing column to be of type NOT NULL unless you specify a DEFAULT constraint for it or you change all NULL values in it to a NON NULL value using UPDATE before modification.

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -