資料庫語句知識點

2021-07-09 06:38:01 字數 1574 閱讀 2043

1.select運算

select distinct companyfrom

orders;

select * from orders;

2.and

& or運算

select * from person where firstname='thomas' andlastname='carter'

3.top語句

top

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

對於擁有數千條記錄的大型表來說,

top

子句是非常有用的。

select  top number|percent

column_name  from table_name

eg:select top 2 * from persons

上面的

"persons"

表中選取頭兩條記錄。

select

top 50 percrnt * from persond

"persons"

表中選取

50%

的記錄。

4.like

操作符

like

操作符用於在

where

子句中搜尋列中的指定模式。

select * from persons werecity like 'n%' 

"persons"

表中選取居住在以 "

n" 開始

的城市裡的人

"%"

可用於定義萬用字元(模式中缺少的字母)。

select

* from persons where city like'%g' 

"persons"

表中選取居住在以 "

g" 結尾

的城市裡的人

select * from persons wherecity like'%lon%'

"persons"

表中選取居住在

包含 "

lon"

的城市裡的人

,不包含加上

not

5.in

in 操作符允許我們在

where

子句中規定多個值。

select

* from

persons  where lastname  in('adams','carter')

6.sql 約束

可以在建立表時規定約束(通過

createtable

語句),或者在表建立之後也可以(通過

altertable

語句)。

notnull  

lastname varchar(255)

notnull,

unique 

unique

約束唯一標識資料庫表中的每條記錄。

id_p int not null

unique;

unique (id_p)

primarykey 

foreignkey

check

資料庫知識點

1.truncate delete和drop delete delete是一行行刪除資料,不影響表結構,並且會記錄日誌,可以進行回滾。truncate 刪除表中所有資料,不記錄日誌,不可以回滾,truncate之後表空間和索引大小會回到初始值。所以truncate之前最好備份 drop 刪除整個表結...

資料庫知識點

資料庫的事務,是指作為單個邏輯工作單元執行的一系列操作。事務處理可以確保除非事務性單元內的所有操作都成功完成,否則不會永久更新面向資料的資源。通過將一組相關操作組合為乙個要麼全部成功要麼全部失敗的單元,可以簡化錯誤恢復並使應用程式更加可靠。乙個邏輯工作單元要成為事務,必須滿足所謂的acid 原子性 ...

資料庫知識點

oracle 安裝oracle時需要的所需的軟體包安裝命令 yum install binutils compat libcap1 gcc glibc ksh libaio libgcc libstdc libxi libxtst make sysstat 1 建使用者create user ora...