Sql常用語句總結

2021-08-07 08:43:10 字數 4496 閱讀 7492

sql對大小寫不敏感,分為資料操作語言(dml)和資料定義語言(ddl);

sql 使用單引號來環繞 文字值(大部分資料庫系統也接受雙引號)。如果是 數值,請不要使用引號

  select - 從資料庫表中獲取資料

  update - 更新資料庫表中的資料

  delete - 從資料庫表中刪除資料

  insert into - 向資料庫表中插入資料

//

  create database - 建立新資料庫

  alter database - 修改資料庫

  create table - 建立新錶

  alter table - 變更(改變)資料庫表

  drop table - 刪除表

  create index - 建立索引(搜尋鍵)

  drop index - 刪除索引

sql select 語句

select 列名稱 from 表名稱

select * from 表名稱

select distinct 列名稱 from 表名稱

// select 列名稱 from 表名稱 where 列 運算子 值

//如需有條件地從表中選取資料,還可以多個條件的邏輯運算(and,or)

select column_name(s)

from table_name

where column_name in (value1,value2,...)

//選取多個特定值的列或行

select column_name(s)

from table_name

where column_name

between value1 and value2

// 列值範圍選取

not betweeen

select 列名稱 from 表名稱 order by 列名 desc

//按列排序,字典順序或值的大小

asc

select column_name(s)

from table_name

where column_name like pattern

not like pattern

(

pattern='%n』or 'n%' or '%n%'

結尾       開始          包含

)

select column_name(s) from table_name1

//必須擁有相同數量的列,列也必須擁有相似的資料型別,

每條 select 語句中的列的順序必須相同

union

//union(不允許重複行)/union all(允許重複行)

操作符用於合併兩個或多個 select 語句的結果集

select column_name(s) from table_name2

select *

into persons  in 'backup.mdb'

//in 子句可用於向另乙個資料庫中拷貝表

from persons

where ***

sql insert into 語句,

用於向**中插入新的行

insert into 表名稱 values (值 1, 值 2,....)

//用於向**中插入新的行

insert into 表名稱(列1, 列2) values (值1, 值2)

//在指定的列中插入資料

sql update  語句

update 表名稱 set 列1 = 新值1,列2=新值2  where 列名稱 = 某值

//update 語句用於修改表中某行的資料

sql delete  語句

delete from 表名稱 where 列名稱 = 值

//用於刪除表中的行

delete * from 表名稱

//刪除所以行

sql top 

子句用於規定要返回的記錄的數目

select top number|percent column_name(s)

from table_name

select  top 2 * from persons

select  top 50 percent * from persons

主鍵(primary key)是乙個列,在這個列中的每一行的值都是

唯一的。在表中,每個主鍵的值都是唯一的。

SQL常用語句總結

要點 1.語法 4.索引 2.表 建立表,針對表的增刪改查。5.儲存過程 3.資料 增刪改查。6.觸發器及鎖.一 sql語言 1.主要操作語句 1.對資料庫操作 show use alert 2.對錶的操作 show desc drop alter 3.對資料的操作 insert delete up...

sql常用語句

use myoa select from delete from department where departmentid 1 insert department departmentid,departmentname values 1,技術部 update department set depa...

sql常用語句

在sqlserver,簡單的組合sp spaceused和sp msforeachtable這兩個儲存過程,可以方便的統計出使用者 資料表的大小,包括記錄總數和空間占用情況,非常實用,在sqlserver2k和sqlserver2005中都測試通過。1.exec sp spaceused 表名 sq...