Get the App
SLTechnology News&Howtos  ›  Database  › 

What are the add constraint statements in mysql

Shulou Source: shulou.com Published: 2022-05-31 21:24:45 11月12日 Update

This article introduces what add constraint statements in mysql, the content is very detailed, interested friends can refer to, I hope it can be helpful to you.

-- add table comments

CREATE TABLE user (

Id int PRIMARY KEY AUTO_INCREMENT COMMENT 'primary key'

Name VARCHAR (10) COMMENT 'name'

Age TINYINT

Birth DATETIME

Salary DOUBLE (7 dint 2)

Tel char (11)

) COMMENT 'user Table'

-- add default constraint

CREATE TABLE user (

Id int PRIMARY KEY AUTO_INCREMENT COMMENT 'primary key'

Name VARCHAR (10) COMMENT 'name'

Age TINYINT

Birth DATETIME

Salary DOUBLE (7 dint 2)

Tel char (11)

) COMMENT 'user Table'

-- add unique constraints

CREATE TABLE register (

Id int PRIMARY KEY AUTO_INCREMENT

Name VARCHAR (10) UNIQUE KEY

RegisTime TIMESTAMP DEFAULT CURRENT_TIMESTAMP ()

Fund DOUBLE (9 dint 2) DEFAULT 1000000.00

Tel char (11)

)

-- non-empty constraint

CREATE TABLE register (

Id int PRIMARY KEY AUTO_INCREMENT

Name VARCHAR (10) DEFAULT NULL UNIQUE KEY

RegisTime TIMESTAMP DEFAULT CURRENT_TIMESTAMP ()

Fund DOUBLE (9 dint 2) DEFAULT 1000000.00

Tel char (11) NOT NULL

)

On the mysql which add constraints to share here, I hope that the above content can be of some help to you, can learn more knowledge. If you think the article is good, you can share it for more people to see.

Tags: Sentences content name more users user tables help good interest guys buddies articles comments knowledge articles references Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Tech Info vpn OPPO Reno Shulou Information Docker