MySql 基本動作陳述式整理,mysql基本動作陳述式

來源:互聯網
上載者:User

MySql 基本動作陳述式整理,mysql基本動作陳述式
資料庫 DATABASE:建立
CREATTE {DATABASE | SCHEMA} [IF NOT EXISTS] db_name [DEFAULT] CHARACTER SET [=] charset_name ;
刪除:
DROP {DATABASE | SCHEMA} [IF EXISTS] db_name;
顯示:
SHOW{ DATABASES| SCHEMAS} [LIKE 'pattern'|WHERE expr];
選擇:
USE database_name ;


資料表 TABLE :建立:
CREATE TABLE [IF NOT EXISTS] table_name( column_name data_type, ...) //()內為庫裡面每一列的名稱
刪除:
DROP TABLE [IF EXISTS] table_name;
顯示:
SHOW TABLES [ FROM db_name] [ LIKE 'pattern'||EHERE expr];






列 COLUMN:添加:
ALTER TABLE tbl_name ADD [COLUMN] col_name column_definition [FIRST|AFTER col_name]
//FIRST 添加到最前端, AFTER col_name ,跟在col_name 後邊,省略該項,則加在最後面;
刪除:
ALTER TABLE tbl_name DROP [COLUMN] col_name;


記錄 ROW:添加:
INSERT [INTO]tbl_name [(col_name,...)] VALUES(val,..)
刪除:
DELETE FROM tbl_name [WHERE where_condition]
修改/更新:
UPDATA[LOW_PRIORITY][IGNORE ] table_reference SET col_name1={expr1|DEFAULT} [,col_name2={expr2|DEFAULT}]...
[WHERE where_condition]
例子: UPDATE users SET age=18 WHERE age=17;
顯示:
SELECT expr, ...FROM tal_name;
SELECT * FROM tal_name; //查看所有
查詢:
SELECT select_expr[, select_expr...] 
[
FROM table_references
[WHERE where_condition]
[GROUP BY {col_name|position}[ASC|DESC],...]
[HAVING where_condition]
[ORDER BY {col_name|expr|position} [ASC|DESC], ...]
[LIMIT {[offset,]row_count|row_count OFFSET offset}]
]
//例如: SELECT name FROM users WHERE id=3;


其他:
約束條件:NOT NULL ; PRIMARY KEY; UNIQUE KEY; DEFAULT; FOREIGN KEY
其他常用關鍵字:AUTO_INCREMENT



相關文章

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.