The effect of non-null constraints on data insertion

Source: Internet
Author: User

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

INSERT INTO T_Debt (FNumber, FPerson) VALUES ("1", "Jim")

This SQL does not assign a value to the field Famount, that is, Famount is a null value. 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. Insert failed.

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

INSERT into T_debt (Fnumber,famount, Fperson) VALUES ("1", "$", "Jim")

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

The effect of non-null constraints on data insertion

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.