国产探花免费观看_亚洲丰满少妇自慰呻吟_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ā)表
主站蜘蛛池模板: 汶上县| 湾仔区| 三都| 洛南县| 兰考县| 邳州市| 东港市| 新蔡县| 泾源县| 乌兰察布市| 枞阳县| 社旗县| 扶沟县| 泗洪县| 大关县| 临桂县| 绥宁县| 临漳县| 格尔木市| 丹江口市| 大理市| 若尔盖县| 金门县| 甘谷县| 富川| 昌图县| 民丰县| 靖边县| 盘锦市| 张家口市| 吉安市| 商河县| 灵璧县| 甘德县| 曲靖市| 宁德市| 昂仁县| 潍坊市| 奈曼旗| 辽阳县| 英吉沙县|