欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

詳解Sql基礎(chǔ)語法

 更新時(shí)間:2016年01月01日 15:30:04   投稿:mrr  
這篇文章主要介紹了詳解Sql基礎(chǔ)語法的相關(guān)資料,需要的朋友可以參考下

1.創(chuàng)建數(shù)據(jù)庫

create  database 數(shù)據(jù)庫名稱

2.刪除數(shù)據(jù)庫

drop database 數(shù)據(jù)庫名稱

3.備份sql server

創(chuàng)建備份數(shù)據(jù)的device

use master

exec sp_addumpdevice '名稱','新的名稱','路徑'

開始備份

backup database pubs to 新的名稱

4.創(chuàng)建表

create table 表名(列名1 類型,列名2 類型)

5.根據(jù)已有表創(chuàng)建新表

create table 新表名稱 like 舊表名稱

create table 新表名稱 as select 列名 from 舊表名稱 defintion only

6. 增加一個(gè)列

Alter table 表名稱 add 列名稱 數(shù)據(jù)類型

7.添加主鍵

alter table 表名稱 add primary key(列名稱)

8.自增id屬性從1開始每次加1

identity (1,1)

9.創(chuàng)建索引

create index 索引名 on 表名(列名)

10.刪除索引

drop index idx_name

11.CTE查詢

;with t as(
select openid,ROW_NUMBER()over(partition by openid order byopenid)as row
from #temp)delete t where row>1

12.case when的用法(修改表名稱id,當(dāng) t 的名字不為空,則還是 t 的名字,否則變?yōu)楸砻Q的名字,把被修改的數(shù)據(jù)輸出到臨時(shí)表)

update pn
set pn.id=case when t.id>'' then t.id else pn.id end
output deleted.id into 臨時(shí)表
from 表名稱 pn with(nolock)
join #temp t

13.查詢、插入、刪除、求和、平均、最大值

select * from table
insert into new_table(id,name)values(1,'張三')
delete from table where 范圍
select sum(field1) as sumvalue from table1
select avg (field1) as avgvalue from table1
select max(field1) as maxvalue from table1

通過以上內(nèi)容給大家詳解Sql基礎(chǔ)語法,希望本文介紹能夠給大家?guī)韼椭?/p>

相關(guān)文章

最新評論