The effect of non-null constraints on data update

Source: Internet
Author: User

As the expression "non-null constraint" means, if a non-null constraint is added to a field, we cannot update the value in this field to null. The Famount field of the T_DEBT table has a non-null constraint, if we execute the following sql:

UPDATE T_Debt set FAmount = NULLWHERE FPerson="Tom"

This SQL sets a null value for Famount. After we execute this SQL, the database system will report an error message similar to the following:

You cannot insert a value of NULL into the column "Famount", the Table "Demo.dbo.T_Debt", and the column does not allow null values. Update failed.

If we set a non-null value for Famount, it will be inserted successfully and execute the following sql:

UPDATE T_Debt set FAmount =123WHERE FPerson="Tom"

This sentence of SQL can be successfully executed correctly. Perform a SELECT * from t_debt to view the data in the table:

You can see that the data has been updated correctly in the table.

The effect of non-null constraints on data update

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.