create
database
《資料庫名》
use 《資料庫名》 指定資料庫use student create
table studentinfo(
name varchar(20
),id char(10
),score int
notnull
);
char 是固定位元組長度, varchar 是可變的位元組長度,後面的數字是最大位元組,
not null 表示該列資訊不得為空。
select命令被用來選取表中的資料
列名為*則代表選擇所有的列select
《列名》
from
《表名》
select 可以選多個列select
*from
《表名》
在表中選取的列有可能會有重複項,需要加distinct去重select
《列1>
,《列2
>..
.from
《表名》
where子句被用來條件性的選擇列。select
distinct
《列》from
《表》
例如:在info表中選擇年齡》18歲的姓名:select
《列名》
from
《表名》
where
《列名》
《運算子》
《值》
and 和 or 可以在選擇的時候把選擇條件連線起來。select name from info where age>
18
將選擇的列按照規則進行排序,預設是公升序排列
按照列名b降序的規則對列a進行排序。select
《列名a>
from
《表名》
order
by《列名b>
如果要進行降序,則在後面加 desc關鍵字。
update 用於表的更新insert
into
《表名》
(列1,列2,.
..)values
(值1,值2,.
..)
delete用於刪除列,而drop用於刪除表和資料庫update
《表名》
set《列1
>
=《新值》
where
《列2>
=《值》
delete
from
《表名》
where
《列名》
《關係》
《值》
mysql學習筆記之sql基礎語法
結構化查詢語言 structured query language 由國際標準化組織 iso 制定的,對dbms的統一操作方式 例如相同的語句可以操作 mysql oracle等 ps 例如sql99,即1999年制定的標準。某種dbms不只會支援sql標準,而且還會有一些自己獨有的語法,這就稱之為...
SQL基礎語法
select 語句用於從表中選取資料。結果被儲存在乙個結果表中 稱為結果集 select 列名稱 from 表名稱select from 表名稱如需獲取名為 lastname 和 firstname 的列的內容 從名為 persons 的資料庫表 請使用類似這樣的 select 語句 select ...
SQl基礎語法
1 ddl data define language 01.用來建立和刪除儲存資料的資料庫以及表等物件。create 建立資料庫或者表 create table a create database a drop 用來刪除表或者資料庫,刪除後無法恢復。drop table a drop databas...