MySQL簡單語法(3)

2021-08-13 02:37:19 字數 1387 閱讀 3478

使用 truncate table 刪除資料

- 特點:不能新增where關鍵字,相當於刪除整個表中的資料

- 語法:truncate table table_name

- 例子:truncate table games

使用delete命令刪除資料

- 特點:可以新增where關鍵字,可以刪除表中指定的資料

- 語法:delete [from]table_name where condition_expression

- 例子:delete from games where gno=3

- 注意有的mysql版本認為不新增from關鍵字是錯誤的。

查詢表的全部行和列

- 語法:select col1_name,col2_name,col2_name…… from table_name 或者 select * from table_name

- 例子:select * from games

- 例子:select gno,gtype from games

查詢表的部分列

- 語法:select col1_name,col2_name from table_name

- 特點:在select後面新增我們要查詢的表中的欄位名

- 例子:select gno,gtype from games

別名的使用

- 語法:select col1_name as 『name1』, col2_name as 『name2』 from table_name

- 注意:as關鍵字可以省略

- 例子:select gname as 『序號』 from games

- 例子:select gno 『序』 from games

消除結果集的重複行

- 語法:select distinct col_name from table_name

- 例子:select distinct gname from games

指定結果集中資料的顯示範圍

- 語法:select * from limit number1,number2

- 注意:結果集中的第一條資料預設是0,number1表示從第number+1行開始查詢,number2表示一共查詢number條資料;如果limit關鍵字後面只有乙個數字,那麼預設從第一行資料開始查詢,一空查詢n條

- 例子:select * from games limit 2,2

- 例子:select * from games limit 2

MySQL簡單查詢語法

1.專案中如何儲存日期時間資料 大體上有三種方式 1 varchar儲存 不足 不便於比較大小 2 date time datetime儲存 不足 不便於實現國際化 3 bigint儲存 表示距離計算集元年的毫秒值,任何程式語言都可以把大數字轉換成為 日期時間 2.mysql中使用自增列 id in...

Mysql 語法簡單使用

我怕是個廢物了,sql永遠記不住。寫個文件記下來吧。以後直接copy。一 insert,插入資料語句 1.這種是不用欄位名的,一行所有字段插入,所以可以省略欄位名 insert table values value1,value2,valuen 2.這種是有欄位名的 insert into tabl...

D3的簡單語法

選擇 選擇單個元素用 select 選擇第乙個元素 選擇多個元素用 selectall 選擇 插入 刪除元素 insert 在選擇集前面插入元素 d3.select body insert p moon remove 刪除元素 d3.select moon remove 文字屬性樣式操作 資料連線 ...