1. 顯示數據庫 show databases;數據庫
show databases;
2. 顯示當前數據庫spa
select current_database();
3. 建立數據庫code
create database db_name;
4. 選擇某個數據庫blog
use db_name;
5. 顯示當前數據庫下的表io
show tables;
6. 建立表 create tabletable
create table if not exists my_test( id INT UNSIGNED AUTO_INCREMENT, name_people VARCHAR(40) NOT NULL, submission_time DATETIME, PRIMARY KEY(id) )ENGINE=InnoDB DEFAULT CHARSET=utf8;
7. 描述表結構DESC或者DESCRIBE、show columns fromclass
DESC my_test;
SHOW COLUMNS FROM my_test; #顯示錶結構
8. 插入數據 insert intotest
INSERT my_test( id, name_people, submission_time ) VALUES (1, 'Mary', NOW());
9 .查詢 selectdate
select * from my_test;
select name_people from my_test;
select name_peole from my_test where id=1;
10. 刪除一條記錄 deleteselect
delete from my_test where id=1;
11. 刪除表中的全部記錄,可是保存原來的表結構
delete from my_test;
12. 更新表的某一列 update
UPDATE my_test SET name_people = '陛下' WHERE id=1
13. 更新多列數據,用 ',' 逗號隔開
UPDATE my_test SET name_people = '將軍', submission_time = NOW() WHERE id=1
14. 增長新列 alter,而後update
ALTER table my_test add name_adress VARCHAR(50) not null; update my_test set name_adress='北京';
15. 複製另外一張表的數據和表結構,來新建表 create,使用as關鍵詞
CREATE TABLE my_test_copy AS SELECT * FROM my_test; SELECT * from my_test_copy;
#歡迎交流