MySQL筆記:數據插入
阿新 • • 發佈:2018-03-19
opened tab play RR 分享 eat name med creat
一、插入記錄
CREATE DATABASE MYDB; USE MYDB; CREATE TABLE IDENTITY ( NAME CHAR(20) PRIMARY KEY, BIRTH DATETIME NOT NULL, HOME CHAR(20) ); CREATE TABLE STUDENT ( NUMBER INT PRIMARY KEY AUTO_INCREMENT, NAME CHAR(20) NOT NULL, AGE TINYINT NOT NULL, HOME CHAR(30) ); INSERT INTO STUDENT VALUESView Code(30, ‘Curry‘, 10, ‘Golden State‘); #不指定字段名 INSERT INTO STUDENT (NAME, AGE, HOME) VALUES (‘Durant‘, 11, ‘Golden State‘); #指定字段名 INSERT INTO STUDENT (NAME, AGE, HOME) VALUES (‘Curry‘, 30, ‘Golden State‘), (‘Durant‘, 29, ‘Golden State‘), (‘James‘, 23, ‘Cleveland‘), (‘Irving‘, 11, ‘Boston‘); #插入多條記錄INSERT INTO STUDENT (NAME, AGE, HOME) SELECT NAME, TIMEDIFF(NOW(), BIRTH), HOME FROM IDENTITY; #插入查詢結果 SELECT * FROM STUDENT; DROP DATABASE MYDB;
二、更新記錄
INSERT INTO STUDENT VALUES (35, ‘Durant‘, 0, 29, ‘Oklahoma‘); UPDATE STUDENT SET HOME = ‘Golden State‘ WHERE NUMBERView Code= 35;
三、刪除記錄
DELETE FROM STUDENT WHERE HOME = ‘Golden State‘; #清除指定條件的數據 DELETE FROM STUDENT; #清空所有數據View Code
MySQL筆記:數據插入