国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 開發(fā) > 綜合 > 正文

SQL的基本命令和幾個常用函數(shù)匯總

2024-07-21 02:06:19
字體:
來源:轉載
供稿:網(wǎng)友

--創(chuàng)建對象(表、視圖、存儲過程、函數(shù))命令]
create table/view/procedure/function
--創(chuàng)建表
create table tabtestvb
(vbname varchar(10),value numeric(10))
go
create table tabtestvb1
(vbname varchar(10),value1 numeric(10))
go
--插入數(shù)據(jù)(兩種方式)
insert into tabtestvb(vbname,value)
select 'aaa',123
insert into tabtestvb1(vbname,value1)
select 'aaa',456

insert into tabtestvb(vbname,value) values ('bbb',345)
insert into tabtestvb1(vbname,value1) values ('ccc',1002)
--更改數(shù)據(jù)
update tabtestvb set value=798 where vbname='aaa'
--關聯(lián)更改
update tabtestvb set value=tabtestvb1.value1
from tabtestvb1 where tabtestvb.vbname=tabtestvb1.vbname
--刪除數(shù)據(jù)
delete tabtestvb where  vbname='aaa'
--無日志刪除數(shù)據(jù)
truncate table tabtestvb
--刪除對象(表、視圖、存儲過程、函數(shù))命令
drop table/view/proc/function
--刪除表
drop table tabtestvb
drop table tabtestvb1
--賦值命令
set
--定義變量
declare


--流程控制語句
while ... break
begin ... end
if ...else
----1...100 的和
declare @nn numeric(3)
declare @sum numeric(8)
set @nn=1
set @sum=0
while @nn<=100
 begin
  set @[email protected][email protected]
  set @[email protected]+1
 end
select @sum

--加上條件:當@nn=20 時退出循環(huán)(計算出1...19的和)
declare @nn numeric(3)
declare @sum numeric(8)
set @nn=1
set @sum=0
while @nn<=100
 begin
  if @nn<>20
   --begin
   set @[email protected][email protected]
   --end
  else
   --begin
   break
   --end
  set @[email protected]+1
 end
select @sum


--全局變量
@@rowcount
--返回受上一語句影響的行數(shù)
select '1'
union all
select '3'
select @@rowcount

@@error
--返回最后執(zhí)行的 transact-sql 語句的錯誤代碼。
set @n =1
select @@error

----函數(shù)的使用
--返回當前日期
select getdate()

--生成16進制的標志列uniqueidentifier
select newid()

--轉換數(shù)據(jù)類型和格式
select convert(varchar(10),getdate(),120)

 

 

 
發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 平和县| 辽阳县| 常熟市| 西盟| 苏尼特右旗| 双鸭山市| 勐海县| 金溪县| 慈溪市| 南充市| 南乐县| 静宁县| 天柱县| 乌海市| 泌阳县| 德保县| 塘沽区| 略阳县| 叙永县| 荥阳市| 库伦旗| 岗巴县| 湘潭县| 苏尼特右旗| 洮南市| 宕昌县| 松桃| 青浦区| 湘西| 隆尧县| 葵青区| 普兰店市| 长兴县| 林口县| 新乡县| 丰城市| 三原县| 连南| 吴江市| 诏安县| 滕州市|