以下是MySQL的一些基礎(chǔ)語句:
1. 創(chuàng)建數(shù)據(jù)庫
CREATE DATABASE database_name;
2. 刪除數(shù)據(jù)庫
DROP DATABASE database_name;
3. 切換數(shù)據(jù)庫
USE database_name;
4. 創(chuàng)建數(shù)據(jù)庫表
CREATE TABLE table_name (
column1 datatype,
column2 datatype,
...
);
5. 刪除數(shù)據(jù)庫表
DROP TABLE table_name;
6. 插入數(shù)據(jù)
INSERT INTO table_name (column1, column2, ...) VALUES (value1, value2, ...);
7. 更新數(shù)據(jù)
UPDATE table_name SET column1 = value1, column2 = value2, ... WHERE condition;
8. 刪除數(shù)據(jù)
DELETE FROM table_name WHERE condition;
9. 查詢數(shù)據(jù)
SELECT column1, column2, ... FROM table_name WHERE condition;
10. 簡單查詢例子
SELECT * FROM table_name;
11. 條件查詢例子
SELECT * FROM table_name WHERE column1 = 'value1' AND column2 = 'value2';
12. 排序例子
SELECT * FROM table_name ORDER BY column1 ASC;
13. 分組統(tǒng)計(jì)例子
SELECT column1, COUNT(column2) FROM table_name GROUP BY column1;
14. 連接查詢例子
SELECT * FROM table1 JOIN table2 ON table1.column1 = table2.column2;
15. 帶聚合函數(shù)的查詢例子
SELECT COUNT(column1), AVG(column2), SUM(column3) FROM table_name;
16. 創(chuàng)建唯一索引
CREATE UNIQUE INDEX index_name ON table_name (column1, column2, ...);
17. 創(chuàng)建非唯一索引
CREATE INDEX index_name ON table_name (column1, column2, ...);
18. 刪除索引
DROP INDEX index_name ON table_name;
這些基礎(chǔ)語句可以幫助你進(jìn)行數(shù)據(jù)庫的基本操作。不同的應(yīng)用場景可能需要使用更復(fù)雜的SQL語句,需要根據(jù)具體情況進(jìn)行學(xué)習(xí)和實(shí)踐。