欢迎光临
我们一直在努力

SQL的基本命令和几个常用函数汇总-数据库专栏,SQL Server

建站超值云服务器,限时71元/月

–创建对象(表、视图、存储过程、函数)命令]
create table/view/procedure/function
–创建表
create table tabtestvb
(vbname varchar(10),value numeric(10))
go
create table tabtestvb1
(vbname varchar(10),value1 numeric(10))
go
–插入数据(两种方式)
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)
–更改数据
update tabtestvb set value=798 where vbname=aaa
–关联更改
update tabtestvb set value=tabtestvb1.value1
from tabtestvb1 where tabtestvb.vbname=tabtestvb1.vbname
–删除数据
delete tabtestvb where  vbname=aaa
–无日志删除数据
truncate table tabtestvb
–删除对象(表、视图、存储过程、函数)命令
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 @sum=@sum+@nn
  set @nn=@nn+1
 end
select @sum

–加上条件:当@nn=20 时退出循环(计算出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 @sum=@sum+@nn
   –end
  else
   –begin
   break
   –end
  set @nn=@nn+1
 end
select @sum

–全局变量
@@rowcount
–返回受上一语句影响的行数
select 1
union all
select 3
select @@rowcount

@@error
–返回最后执行的 transact-sql 语句的错误代码。
set @n =1
select @@error

—-函数的使用
–返回当前日期
select getdate()

–生成16进制的标志列uniqueidentifier
select newid()

–转换数据类型和格式
select convert(varchar(10),getdate(),120)

 

 

 

赞(0)
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com 特别注意:本站所有转载文章言论不代表本站观点! 本站所提供的图片等素材,版权归原作者所有,如需使用,请与原作者联系。未经允许不得转载:IDC资讯中心 » SQL的基本命令和几个常用函数汇总-数据库专栏,SQL Server
分享到: 更多 (0)

相关推荐

  • 暂无文章