(jlive)[crashcourse]>DESC customers;
+--------------+-----------+------+-----+---------+----------------+
| Field
+--------------+-----------+------+-----+---------+----------------+
| cust_id
| cust_name
| cust_address | char(50)
| cust_city
| cust_state
| cust_zip
| cust_country | char(50)
| cust_contact | char(50)
| cust_email
+--------------+-----------+------+-----+---------+----------------+
9 rows in set (0.00 sec)
(jlive)[crashcourse]>INSERT INTO customers VALUES(NULL, 'Pep E. LaPew', '100 Main Street', 'Los Angeles', 'CA', '90046', 'USA', NULL, NULL);
(jlive)[crashcourse]>SELECT cust_name,cust_address,cust_city,cust_state,cust_zip FROM customers;
+----------------+---------------------+-------------+------------+----------+
| cust_name
+----------------+---------------------+-------------+------------+----------+
| Coyote Inc.
| Mouse House
| Wascals
| Yosemite Place | 829 Riverside Drive | Phoenix
| E Fudd
| Pep E. LaPew
+----------------+---------------------+-------------+------------+----------+
6 rows in set (0.15 sec)
插入一行中的某几个字段
(jlive)[crashcourse]>INSERT INTO customers(cust_name, cust_address, cust_city, cust_state, cust_zip, cust_country, cust_contact, cust_email) VALUES('Pep E. LaPew', '100 Main Street', 'Los Angeles', 'CA', '90046', 'USA', NULL, NULL);
Query OK, 1 row affected (0.00 sec)
一条插入语句插入多条数据
INSERT INTO customers(cust_name,cust_address, cust_city, cust_state, cust_zip, cust_country)
VALUES
('Pep E. LaPew','100 Main Street', 'Los Angeles', 'CA','90046','USA' ),
('M. Martian', '42 Galaxy Way', 'New York',
'NY','11213','USA');
插入查询到的数据
INSERT INTO customers(cust_id,cust_contact, cust_email, cust_name, cust_address, cust_city, cust_state, cust_zip, cust_country)
SELECT
cust_id, cust_contact,cust_email, cust_name,
cust_address, cust_city, cust_state, cust_zip,
cust_country
UPDATE
(jlive)[crashcourse]>UPDATE customers SET cust_name = 'The Fudds', cust_email = 'elmer@fuddd.com' WHERE cust_id = 10005;
Query OK, 1 row affected (0.00 sec)
Rows matched: 1
(jlive)[crashcourse]>SELECT cust_id, cust_name, cust_email FROM customers WHERE cust_id = 10005;
+---------+-----------+-----------------+
| cust_id | cust_name | cust_email
+---------+-----------+-----------------+
|
+---------+-----------+-----------------+
1 row in set (0.00 sec)
(jlive)[crashcourse]>UPDATE customers SET cust_email = NULL WHERE cust_id = 10005;
Query OK, 0 rows affected (0.00 sec)
Rows matched: 1
(jlive)[crashcourse]>SELECT cust_id, cust_name, cust_email FROM customers WHERE cust_id = 10005;
+---------+-----------+------------+
| cust_id | cust_name | cust_email |
+---------+-----------+------------+
|
+---------+-----------+------------+
1 row in set (0.00 sec)
DELETE
(jlive)[crashcourse]>DELETE FROM customers WHERE cust_id = 10006;
Query OK, 1 row affected (0.00 sec)