Video Hướng dẫn
- [MySQL] Create Database, table
- [MySQL] Add PRIMARY KEY, FOREIGN KEY Constraint
- [MySQL] Create Database ER diagram
Video Hướng dẫn
Cột khóa chính thường không được phép null
NOT NULLvà được cho tự động tăngAUTO_INCREMENT
ALTER TABLE
clients
ALTER COLUMN
phoneCú pháp chuẩn lúc tạo bảng
CREATE TABLE Persons (
Personid int NOT NULL AUTO_INCREMENT,
LastName varchar(255) NOT NULL,
FirstName varchar(255),
Age int,
PRIMARY KEY (Personid)
);https://chartio.com/resources/tutorials/how-to-alter-a-column-from-null-to-not-null-in-sql-server/
https://www.w3schools.com/sql/sql_autoincrement.asp
Tạo Khóa ngoại, liên kết bảng
https://www.w3schools.com/sql/sql_foreignkey.asp
https://youtu.be/MSrC5gqGhS8
Cú pháp
Chúng ta có thể khai báo luôn khóa chính lúc tạo bảng luôn, như thế này
Nếu đã tạo rồi thì giờ ta update lại thôi
Thực hành