SQL Server | How Mysql implements the unique implementation of a table

Source: Internet
Author: User

There are two implementations of unique in the ANSI SQL standard

1. It is possible to insert multiple null values, which means that multiple null values are considered to be distinct.

2, it is only possible to insert a null value, also the main is to say that all the empty values to see the same.

In SQL Server | The second standard is implemented in MySQL.

Example: (Code with SQL Server syntax as an example)

CREATE TABLE tmp (x int primary key, y int);

ALTER TABLE TMP add constraint unique_cons unique (y);

INSERT into TMP (x, Y) VALUES (1,null);

INSERT into TMP (x, Y) VALUES (2,null); This is not going to happen. This means that when the second null is inserted, two null is treated as the same value.

SQL Server | How Mysql implements the unique implementation of a table

Related Article

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.