在創(chuàng)建數(shù)據(jù)庫(kù)表時(shí),可以通過以下方式設(shè)置主鍵:
CREATE TABLE employees (
employee_id INT PRIMARY KEY,
first_name VARCHAR(50),
last_name VARCHAR(50)
);
CREATE TABLE employees (
employee_id INT AUTO_INCREMENT PRIMARY KEY,
first_name VARCHAR(50),
last_name VARCHAR(50)
);
CREATE TABLE employees (
employee_id INT,
department_id INT,
PRIMARY KEY (employee_id, department_id)
);
無論使用哪種方式設(shè)置主鍵,都可以確保表中每行數(shù)據(jù)的唯一性,并且提高數(shù)據(jù)查詢的效率。