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
system: VMTOOLs Download: Link: https://pan.baidu...
Table of contents 1. Where is the self-incremente...
console.log( [] == ![] ) // true console.log( {} ...
Table of contents 1. Introduction 2. Scenario 3. ...
Table of contents 1. Scenario Description 2. Solu...
The <base> tag specifies the default address...
Copy code The code is as follows: <html> &l...
This article shares the specific code of JavaScri...
Table of contents 1. Preface 2. Find two pop-up c...
Copy code The code is as follows: <style> ....
Responsive design is to perform corresponding ope...
Preface When we installed the system, we did not ...
Since the default Linux kernel parameters are bas...
1. MYSQL index Index: A data structure that helps...
1. Review The Buffer Pool will be initialized aft...