網站首頁 學習教育 IT科技 金融知識 旅遊規劃 生活小知識 家鄉美食 養生小知識 健身運動 美容百科 遊戲知識 綜合知識
當前位置:趣知科普吧 > IT科技 > 

數據庫sql語句大全

欄目: IT科技 / 發佈於: / 人氣:3.15W

數據庫sql語句有哪些呢?下面就讓我們一起來了解一下吧:

sql語句有很多,比較基本的sql語句有:

選擇:select * from table1 where 範圍

插入:insert into table1(field1,field2) values(value1,value2)

刪除:delete from table1 where 範圍

更新:update table1 set field1=value1 where 範圍

查找:select * from table1 where field1 like ’%value1%’

排序:select * from table1 order by field1,field2 [desc]

總數:select count as totalcount from table1

求和:select sum(field1) as sumvalue from table1

平均:select avg(field1) as avgvalue from table1

最大:select max(field1) as maxvalue from table1

最小:select min(field1) as minvalue from table1

數據庫sql語句大全

當然也還有其他的sql語句,具體介紹如下:

若是備份sql server

1、創建、備份數據的 device,示例代碼爲:

USE master

EXEC sp_addumpdevice 'disk', 'testBack', 'c:mssql7backupMyNwind_1.dat'

2、開始、備份,示例代碼爲:

BACKUP DATABASE pubs TO testBack

若是創建新表

示例代碼爲:

create table tabname(col1 type1 [not null] [primary key],col2 type2 [not null],..)

若是依照已有的表創建新表

示例代碼爲:

A:create table tab_new like tab_old (使用舊錶創建新表) 

B:create table tab_new as select col1,col2… from tab_old definition only

數據庫sql語句大全 第2張

若是刪除新表

示例代碼爲:

drop table tabname