Mysql之增加資料_INSERT INTO
阿新 • • 發佈:2021-01-31
一、增加單行資料
1.
USE sql_store;
INSERT INTO customers
VALUES(
DEFAULT,
'John',
'Smith',
'1990-07-07',
NULL,
'Beijing',
'Beijing',
'CA',
200)
2.
二、單表插入多行資料USE sql_store; INSERT INTO customers( # 順序不用和資料表保持一致,插入關係對應即可 last_name, first_name, birth_date, address, city, state, points ) VALUES( 'Smith', 'John', '1990-07-07', 'Beijing', 'Beijing', 'CA', 200)
USE sql_store;
INSERT INTO shippers(name)
VALUES ('Shipper1'),
('Shipper2'),
('Shipper3')
三、在多表中插入資料
USE sql_store; INSERT INTO orders (customer_id,order_date,status) VALUE (2,'2021-01-30',1); INSERT INTO order_items VALUES (LAST_INSERT_ID(),1,2,2.02), #LAST_INSERT_ID()最近插入的id (LAST_INSERT_ID(),2,52,2.35)