1. 程式人生 > >MySQL的增刪改查

MySQL的增刪改查

先建立三個表

 CREATE TABLE clazz(
    id INT NOT NULL  PRIMARY KEY,
    name VARCHAR(100) NOT NULL,
    clazzroom VARCHAR(40) NOT NULL
 );
 CREATE TABLE group1(
    id INT NOT NULL PRIMARY KEY ,
    name VARCHAR(100) NOT NULL,
    clazz_id INT NOT NULL,
    foreign key(clazz_id) references clazz(id)
 );
 CREATE TABLE stu(
    id INT NOT NULL PRIMARY KEY,
    name VARCHAR(100) NOT NULL,
    group_id INT NOT NULL,
    foreign key(group_id) references group1(id)
 );

通過外來鍵把三個表聯絡起來

增刪改查語句。

INSERT INTO table_name () VALUES ();
DELETE FROM table_name WHERE .....;
UPDATE table_name SET ··· WHERE ···;
SELECT * FROM table_name; 可以加where