一些常用SQL

2021-03-31 08:56:59 字數 1675 閱讀 4062

1、對select 查詢出來的資料時行修改...

1)select  t.rowid, t.*  fromtablename t

//取出資料物理rowid 並顯示,些時可以對其進行修改....

2)select *  fromtablenamefor update

//取出資料顯示,此時可以對其進行編輯....

以上兩種修改,修改後一定要進行***mit,不然會鎖住table...

2、update 的用法....

例:updatetablenamesettable的字段 ='我設定的字段'

wheretable欄位 = '條件1'

andtable欄位 = '條件2'

and .......

3、insert into 的用法....

例:1)

insert   intotablename ('欄位1','欄位2','欄位3',.....,'欄位n')

values('內容1','內容2','內容3',......,'內容n')

例:2) 

insert intotablename select * from  tablename1

//將table1 內的所有資料傳入tablename 裡

//tablename1 的結構必須跟tablename 的結構完全一樣...

4、delete 的用法....

delete  fromtablename  

where字段=條件

and .................

5、grant 的用法.

//授權給指定的使用者..

grant select,

insert,

update,

delete

ontablenameto使用者;

例:grant select,

insert,

update,

delete

on tablename to public ;

//給指定的使用者授入所有的許可權...

grant all on  tablenametopublic ;

6、truncate 清空乙個table...

truncate table tablename ;

一些常用的sql(一)

在列名和別名之間放上as或者空格 select empno as employee number ename name,500 sal 12 annual salary from emp 用兩個豎線 把乙個或多個字串連起來 select ename annual salary is 500 sal ...

一些常用的sql函式

select abs 5 from dual select sqrt 2 from dual select power 2,3 from dual select cos 3.14159 from dual select mod 1600 300 from dual select ceil 2.35 ...

一些常用的 sql語句總結

查詢賣最好的商品名稱 select goods name from indent detail group by goods id order by sum goods num limit 1 查詢張三購買過的商品名稱 select goods name from user join indent ...