存档

2013年9月 的存档,文章数:3

mark:

rand2()  ASE 15.0.2

newid()  ASE 12.5.1

rand()    Any Version

set rowcount N
select * from table order by rand(convert(int,row1)+datepart(ms,getdate()))
set rowcount 0

本博客已经有一篇关于的:Sybase ASE 统计当前执行的SQL语句的存储过程! 

现在提供另外一种方法:使用系统存储过程sp_monitor查看当前数据库连接中正在执行的SQL语句信息!

sp_monitor connection

在执行上面语句之前需要启用对connection的监控, 执行:sp_monitor enable,connection。可以在监控完成后关闭该选项。

设置参数:max SQL text monitored为2048,该参数为静态参数,需要重启ASE。

sp_monitor connection的结果默认按照连接占用的cpu时间和等待时间的总和进行逆序排序。

sp_monitor connection的第二个参数有:cpu , diskio , elapsed time 分别表示按照cpu时间、物理读取次数、cpu时间+等待时间 进行逆序排序。

在查看完正在执行的SQL语句内容后,关闭对connection的监控以减少对生产服务器的影响。

执行的语句如下:

sp_configure "max SQL text monitored",2048
go
--reboot ASE
--...
sp_monitor enable,connection
go
sp_monitor connection
go
-- some SQL statement
-- ...
sp_monitor disable,connection
go

以将dbo创建的所有表授予相应权限给普通用户userA为例。

将dbo拥有的表的相应权限(select/insert/update/delete)授予给普通用户userA,使用以下SQL生成授权语句:

select 'grant select  on ' + user_name(uid) + '.' + name + ' to userA'  from sysobjects where type='U' and uid=user_id('dbo')

union all

select 'grant insert on ' + user_name(uid) + '.' + name + ' to userA'  from sysobjects where type='U' and uid=user_id('dbo')

union all

select 'grant update on ' + user_name(uid) + '.' + name + ' to userA'  from sysobjects where type='U' and uid=user_id('dbo')

union all

select 'grant delete on ' + user_name(uid) + '.' + name + ' to userA'  from sysobjects where type='U' and uid=user_id('dbo')

查看某张表的上用户的权限情况:

sp_helprotect table_name

查看用户所拥有的对象权限情况:

sp_helprotect user_name