MYSQL命令小記

本人不才,記錄一下SQL命令。使用MYSQL。

 

1、顯示數據庫:show databases;// 要加s

2、創建數據庫:create database one;// 數據庫名字爲one(下面都是用one來代表),可通過show databases查看

3、刪除數據庫:drop database one;

4、進入數據庫:use one;

5、查看數據庫表:show tables;// 同樣要s

6、建表:create table one_table (id int(4) not null primary key auto_increment,name char(20) not null);// 表明爲one_table,id不可爲空,主鍵,自增

7、查看錶結構:show columns from one_table;或者DESCRIBE one_table;或者desc one_table;

8、查詢表內容:select * from one_table;// 所有

9、插入表內容:insert into one_table values(1,'A'),(2,'B');

10、查詢前幾個的內容:select * from one_table order by id limit 0,2;或者select * from one_table limit 0,2;

11、刪除內容:delete from one_table where id=1;// 通過id刪除

12、修改表明:rename one_table to two_table;//表明從one_table修改爲two_table;

13、修改表內容(替換):update one_table set name=replace(name,'b''bbbb');//修改name字段,值爲b的全部修改爲bbbb

        修改表內容(插入):update one_table set name=concat('wwwww, name);//這裏的關鍵字是concat,在name字段中的值簽名添加"wwww",是所有的值

        修改某個值:update one_table set name='xiaoqi' where id=1;(語句順序有關係,順序不對會錯誤,= =、開始set放後面,不可以)

14、插入字段:alter table one_table add password varchar(50) not null;

刪除表:drop table one_table;

待續。。。
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章