searchsanjaysharma
asked on
How to execute a procedure at certain time and how to use database in cursor
1.How can i activate/exec a procedure at a certain time on routine basis.
2. I want to use all thedatabases and print all the tables inside two databases.
But the following code is not working.
Declare @t_database varchar(300)
Declare @t_table varchar(300)
Declare curdatabase cursor for
select name from sys.databases where database_id > 4 order by name
OPEN curdatabase
FETCH curdatabase into @t_database
WHILE(@@fetch_status=0)
BEGIN
print 'Database : = '+@t_database
DECLARE @s NVARCHAR(MAX)
SET @s = 'USE ' + @T_DATABASE
EXECUTE sp_executesql @s
Declare curtables cursor for
select name from sys.tables order by name
OPEN curtables
FETCH curtables into @t_table
WHILE(@@fetch_status=0)
BEGIN
Print 'Table = '+@t_table
FETCH curtables into @t_table
END
CLOSE curtables
DEALLOCATE curtables
FETCH curdatabase into @t_database
END
CLOSE curdatabase
DEALLOCATE curdatabase
2. I want to use all thedatabases and print all the tables inside two databases.
But the following code is not working.
Declare @t_database varchar(300)
Declare @t_table varchar(300)
Declare curdatabase cursor for
select name from sys.databases where database_id > 4 order by name
OPEN curdatabase
FETCH curdatabase into @t_database
WHILE(@@fetch_status=0)
BEGIN
print 'Database : = '+@t_database
DECLARE @s NVARCHAR(MAX)
SET @s = 'USE ' + @T_DATABASE
EXECUTE sp_executesql @s
Declare curtables cursor for
select name from sys.tables order by name
OPEN curtables
FETCH curtables into @t_table
WHILE(@@fetch_status=0)
BEGIN
Print 'Table = '+@t_table
FETCH curtables into @t_table
END
CLOSE curtables
DEALLOCATE curtables
FETCH curdatabase into @t_database
END
CLOSE curdatabase
DEALLOCATE curdatabase
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER