Primary key constraint PRIMARY KRY The primary key is unique. A table can only have one primary key. ##No constraintsCreate table stu0( Id int Name varcahr(50) ) Insert into stu0(name)value("Zhang Sanfeng"); ##Method 1: Create a table and add a primary key constraintCreate table stu1( Id int primary key; Name varchar(50) ) ##Method 2: Create table stu2( Id int, Name varchar(50), Primary key(name) ) Success: insert intostu1(in,name)value("2,张三丰"); Success Test 1: insert into stu(id,name)value(null,"张三丰"); #Failed, prompt cannot be empty Test 2: Unique ConstraintUNIQUE KEY unique constraint can ensure the uniqueness of data. Each data table can have multiple unique constraints. Unique constraint ##Add a unique constraint to the name Create table stu3( Id int primary key, Name varchar(50) unique ) Insert into stu3(id,name)value(1,"Zhang Sanfeng"); Insert into stu3(id,name)value(2,"Zhang Sanfeng"); ERROR 1062(23000):Duplicate entry '张三丰' for key 'name' Insert into stu3(id,name)value(2,"张三"); This concludes this article on the difference between MYSQL primary key constraints and unique constraints. For more information about MYSQL primary key constraints and unique constraints, please search previous articles on 123WORDPRESS.COM or continue to browse the following related articles. I hope you will support 123WORDPRESS.COM in the future! You may also be interested in:
|
<<: Detailed explanation of the relationship between Vue and VueComponent
>>: Nginx reverse proxy learning example tutorial
I recently deployed MySQL 5.6 and found that by d...
This article shares the specific code of the WeCh...
Business requirements One of the projects I have ...
With the emergence of docker, many services have ...
#String concatenation concat(s1,s2); concatenate ...
1. Press win + R and type cmd to enter the DOS wi...
inherit 1. What is inheritance Inheritance: First...
Table of contents 1. System Information 2. Shutdo...
Linux often encounters situations such as adding ...
The width of the parent container is fixed. In or...
We know that the commonly used events in JS are: ...
Hyperlinks are the most frequently used HTML elem...
CSS naming rules header: header Content: content/c...
There are four types of positioning in CSS, which...
Preface: I recently encountered the problem of in...