天天看點

SQL語句大全

--說明:建立資料庫

create database USER(表名)

--說明:删除資料庫

drop database USER(表名)

--說明:備份 sql server

--建立備份資料的  device

USE master

EXEX sp_addumpdevice 'disk','testBack','C:\mssql17backup\MyNwi'

nd_1.dat'

--開始備份

BACKUP DATABASE pibs 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

--說明:删除新表

drop table tabname

--說明:增加一個列

Alter table tabname add column col type

--說明:添加主鍵

Alter table tabname add primary key(col)

--說明:删除主鍵

Alter table tabname drop primary key(col)

--說明:建立索引

create [unique] index idxname on tabname(col….)

--删除索引

drop index idxname 

--說明:建立視圖

create view viewname as select statement

--說明:删除視圖

drop view viewname

--說明:幾個最簡單的基本的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%’ ---like

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

總數: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

外連接配接:left (outer) join

本文轉自12691034部落格51CTO部落格,原文連結http://blog.51cto.com/12701034/1929636如需轉載請自行聯系原作者

笑容掩飾愛