This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes JDBC and the fly likes Can we add null constraint to existing table Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Can we add null constraint to existing table" Watch "Can we add null constraint to existing table" New topic
Author

Can we add null constraint to existing table

sam liyanage
Ranch Hand

Joined: Nov 25, 2008
Posts: 1071
Can we add null constraint to existing table?
Shinil Mohan
Ranch Hand

Joined: Aug 24, 2011
Posts: 37

Yes we can add null constraint to existing table.

ALTER TABLE `hibernate`.`billingdetails` CHANGE COLUMN `BANK_NAME` `BANK_NAME` VARCHAR(255) NOT NULL ;

ALTER TABLE `hibernate`.`billingdetails` CHANGE COLUMN `BANK_ACCOUNT_NO` `BANK_ACCOUNT_NO` VARCHAR(255) NULL ;
Matthew Brown
Bartender

Joined: Apr 06, 2010
Posts: 4343
    
    8

As long as the data already in the table satisfies the constraint. If it doesn't you'll have to fix the data first.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Can we add null constraint to existing table
 
Similar Threads
To identify Primary Keys in a table
Check Constraints
Hibernate and database data modifications
Identify not null columns
Create primary and foreign key with SQL