Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*Show the content in all tables*/
- DECLARE @table varchar(20); /*Declare a variable It will be used to store the name of the current table in the loop*/
- /*Declare the cursor CurrTable, get and assign all the table names*/
- /* Since we plan to iterate linearly, FAST_FORWARD is used. It makes the cursor read-only and only move forward. Also, it is better for performance */
- DECLARE CurrTable CURSOR FAST_FORWARD FOR SELECT name FROM SYSOBJECTS WHERE xtype = 'U'
- /*Activate the cursor and populate it with the data*/
- OPEN CurrTable
- FETCH NEXT FROM CurrTable INTO @table /* Set table to the first item in the cursor*/
- /* Start iterating through the cursor */
- WHILE @@FETCH_STATUS = 0 /* if the status of the previous fetch was successful */
- BEGIN
- /* Show the content of the table with a select statement*/
- /* EXEC statement executes the statement. It's used for integrating the table variable into it*/
- EXEC('SELECT * FROM ' + @table)
- /* Set table to the next item in the cursor*/
- FETCH NEXT FROM CurrTable INTO @table
- END
- /* Deactivate the cursor and free it */
- CLOSE CurrTable
- /* Remove the cursor reference, it is no longer needed */
- DEALLOCATE CurrTable
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement