Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

An example of using cursors in sybase

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)06/01 Report--

The following is an example of using cursors in sybase, because it took some time to use, so it was specially made to record

-- query the object permissions directly granted to the user

DECLARE cur_DBName CURSOR FOR SELECT [name] FROM master..sysdatabases

Go

BEGIN

DECLARE @ temDBName VARCHAR (30)

DECLARE @ v_sql VARCHAR 8000

CREATE TABLE # tb_t1 (dbName VARCHAR 50) NULL, objectName VARCHAR (50) NULL,userName VARCHAR (50) NULL, loginName VARCHAR (50) NULL, action INT NULL, protecttype INT, grantor INT)

OPEN cur_DBName

FETCH cur_DBName into @ temDBName

WHILE @ @ SQLSTATUS=0

BEGIN

SET @ v_sql='insert into # tb_t1 select''+ @ temDBName+''',d.name,b.name,c.name,a.action,a.protecttype,a.grantor from'+ @ temDBName+'..sysprotects a

Inner join'+ @ temDBName+'..sysusers b on a.uid = b.uid

Inner join master..syslogins c on b.suid = c.suid

Inner join'+ @ temDBName+'..sysobjects d on a.id = d.id

'

Exec (@ v_sql)

FETCH cur_DBName into @ temDBName

END

Close cur_DBName

Deallocate CURSOR cur_DBName

SELECT * FROM # tb_t1

DROP TABLE # tb_t1

END

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report