MySQL table constraints

MySQL table constraints

MySQL table constraints

1: Open the MySQL Workbench.

2: MySQL constraints:

1: NOT NULL

2: UNIQUE

3: DEFAULT

4: CHECK

5: FOREGIN KEY

6: PRIMARY KEY

3: Table without constraints.

IdNameAgeGenderPhoneStatus
1A17M32691
2B20F58621
3C30M32691
 D25M20391
4E23M10961

4: Use a Database.

Code: use walikhankakar;

5: Create a new table.

Code: CREATE TABLE students

(

   id INT NOT NULL unique,

   name varchar(100) not null,

   email varchar(150) not null unique,

   age tinyint check (age >= 18),

   status boolean default 1

)  

6: Execute the command.

Shortcut key: Ctrl + Enter

MySQL table constraints 1

7: Insert the data into the students table.

Code: INSERT INTO students

(id,name,email,age)

VALUES (1,”WaliKhan”,”walikhan@gmail.com”,24)

8: Execute the command.

Shortcut key: Ctrl + Enter

MySQL table constraints 2

MySQL

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top