T_Sql补充

--调用Dos命令查看文件夹
exec xp_cmdshell 'dir 本地磁盘:\\文件夹'

--让sqlserver可以执行'xp_cmdshell'
EXEC sp_configure 'show advanced options', 1
GO
-- To update the currently configured value for advanced options.
RECONFIGURE
GO
-- To enable the feature.
EXEC sp_configure 'xp_cmdshell', 1
GO
-- To update the currently configured value for this feature.
RECONFIGURE
GO

--调用Dos命令创建文件夹
exec xp_cmdshell 'mkdir(md) 本地磁盘:\\文件夹'

--设置是否显示影响行数
set nocount on

--删除登录用户
1-window exec sp_revokelogin
2-Sql exec sp_droplogin
--删除数据库用户
revokedbaccess


--给表中添加新列:
alter table 表名
add 列名 数据类型
--删除列:
alter table 表名
drop column 列名

注意:查找的数值必须转换为字符串输出
convert(varchar(字符串长度),变量)

--变量叠加:
declare @sum int
declare @count int
set @sum=0
set @count=0
while(1=1)
begin
set @count=@count+1
set @sum=@sum+@count
if(@count>=10)
break
end
print 'sum:='+Convert(varchar(20),@sum)

--事务的属性-ACID
》A—atomicity 原子性
》C—consistency 一致性
》I—isolation 隔离性
》D—durability 永久性

调试(逐步):print 变量名(输出变量值)

--创建事务:
》开始事务-begin transaction
》提交事务-commit transaction
》回滚(撤销)事务-rollback transaction
*****创建索引:
if exists(select * from sysindexes where name='ix_**)
drop index 表名.ix_**
create [unique][clustered|nonclustered]index index_name
on table _name (column_name[,column_name]...)
[with fillfactor=x]
--fillfactor:填充因子 X:为1-100的值
*****按索引查询
select * from 表名 with(index=索引名) [where<条件>]
*****创建视图:
if exists(select * from sysobjects where name='view_name')
drop view view_name
create view view_name as <select语句>
*****使用视图查询
select * from 视图名
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值