Today we will go over very simple script which will list all the tables for all the database.
sp_msforeachdb ’select ”?” AS db, * from [?].sys.tables’
Update: Based on comments received below I have updated this article. Thank you to all the readers. This is good example where something small like this have good participation from readers.
Reference : Pinal Dave (http://www.SQLAuthority.com)
Archive for the ‘SQL Stored Procedure’ Category
SQL SERVER – List All the Tables for All Databases Using System Tables
Posted in Pinal Dave, Readers Question, SQL, SQL Authority, SQL Query, SQL Scripts, SQL Server, SQL Stored Procedure, SQL System Table, SQL Tips and Tricks, SQLServer, T SQL, Technology, tagged undocumented SQL on April 26, 2009 | 7 Comments »
SQL SERVER – 2008 – Optimize for Ad hoc Workloads – Advance Performance Optimization
Posted in Best Practices, Pinal Dave, SQL, SQL Authority, SQL Optimization, SQL Performance, SQL Query, SQL Scripts, SQL Server, SQL Stored Procedure, SQL System Table, SQL Tips and Tricks, T SQL, Technology on March 21, 2009 | 9 Comments »
Every batch (T-SQL, SP etc) when ran creates execution plan which is stored in system for re-use. Due to this reason large number of query plans are stored in system. However, there are plenty of plans which are only used once and have never re-used again. One time ran batch plans wastes memory and resources.
SQL [...]
SQL SERVER – Enable and Disable Index Non Clustered Indexes Using T-SQL
Posted in Pinal Dave, Readers Contribution, SQL, SQL Authority, SQL Index, SQL Query, SQL Scripts, SQL Server, SQL Stored Procedure, SQL Tips and Tricks, SQL Utility, T SQL, Technology on February 19, 2009 | 4 Comments »
Just a day before I received wonderful T-SQL Script from SQL Server Expert Imran Mohammed. What I am really impressed from this script is additional feature of changing recovery mode when SQL Server is enabling and disabling Index. When index are enabled changing SQL Server Recovery mode to simple makes whole operation faster. This stored [...]
SQL SERVER – FIX : ERROR : Msg 5834, Level 16, State 1, Line 1 The affinity mask specified conflicts with the IO affinity mask specified. Use the override option to force this configuration
Posted in Pinal Dave, SQL, SQL Authority, SQL Error Messages, SQL Index, SQL Optimization, SQL Performance, SQL Query, SQL Scripts, SQL Server, SQL Stored Procedure, SQL Tips and Tricks, T SQL, Technology on January 31, 2009 | 1 Comment »
Yesterday I came across following error while enabling fill factor for my database server, when I was trying to write article SQL SERVER – 2008 – 2005 – Rebuild Every Index of All Tables of Database – Rebuild Index with FillFactor.
I ran following T-SQL script and it gave me error.
sp_configure ’show advanced options’, 1
GO
RECONFIGURE
GO
sp_configure ‘fill [...]
SQL SERVER – Find Number of Rows and Disk Space Reserved – Using sp_spaceused Interesting Observation
Posted in Pinal Dave, SQL, SQL Authority, SQL Data Storage, SQL Query, SQL Scripts, SQL Server, SQL Server DBCC, SQL Stored Procedure, SQL Tips and Tricks, SQL Utility, T SQL, Technology on January 14, 2009 | 2 Comments »
Previously I posted SQL SERVER – Find Row Count in Table – Find Largest Table in Database – T-SQL. Today we will look into the same issue but with some additional interesting detail.
We can find the row count using another system SP sp_spaceused. This SP gives additional information regarding disk space reserved on database as [...]
SQL SERVER – 2008 – 2005 – Find Longest Running Query – TSQL
Posted in Pinal Dave, SQL, SQL Authority, SQL Optimization, SQL Performance, SQL Query, SQL Scripts, SQL Server, SQL Server DBCC, SQL Stored Procedure, SQL Tips and Tricks, T SQL, Technology on January 2, 2009 | 16 Comments »
UPDATE : Updated this query with bug fixed with one more enhancement SERVER – 2008 – 2005 – Find Longest Running Query – TSQL – Part 2.
Recently my company owner asked me to find which query is running longest. It was very interesting that I was not able to find any T-SQL script online which [...]
SQL SERVER – Simple Use of Cursor to Print All Stored Procedures of Database Including Schema
Posted in Database, Pinal Dave, SQL, SQL Authority, SQL Documentation, SQL Query, SQL Scripts, SQL Server, SQL Stored Procedure, SQL Tips and Tricks, T SQL, Technology on November 22, 2008 | 4 Comments »
I love active participation from my readers. Just a day ago I wrote article about SQL SERVER – Simple Use of Cursor to Print All Stored Procedures of Database. I just received comment from Jerry Hung who have improved on previously written article of generating text of Stored Procedure.
DECLARE @procName VARCHAR(100)
DECLARE @getprocName CURSOR
SET @getprocName = CURSOR FOR
SELECT [...]
SQL SERVER – Simple Use of Cursor to Print All Stored Procedures of Database
Posted in Pinal Dave, SQL, SQL Authority, SQL Cursor, SQL Query, SQL Scripts, SQL Server, SQL Stored Procedure, SQL Tips and Tricks, T SQL, Technology on November 20, 2008 | 5 Comments »
SQLAuthority Blog reader YordanGeorgiev has submitted very interesting SP, which uses cursor to generate text of all the Stored Procedure of current Database. This task can be done many ways, however, this is also interesting method.
USE AdventureWorks
GO
DECLARE @procName VARCHAR(100)
DECLARE @getprocName CURSOR
SET @getprocName = CURSOR FOR
SELECT s.name
FROM sysobjects s
WHERE type = ‘P’
OPEN @getprocName
FETCH NEXT
FROM @getprocName INTO @procName
WHILE @@FETCH_STATUS = [...]
SQL SERVER – Delete Backup History – Cleanup Backup History
Posted in Best Practices, Database, Pinal Dave, SQL, SQL Authority, SQL Backup and Restore, SQL Query, SQL Scripts, SQL Server, SQL Stored Procedure, SQL Tips and Tricks, T SQL, Technology on November 11, 2008 | 4 Comments »
SQL Server stores history of all the taken backup forever. History of all the backup is stored in msdb database. Many times older history is no more required. Following Stored Procedure can be executed with parameter which takes days of history to keep. In following example 30 is passed to keep history of month.
USE msdb
GO
DECLARE [...]
SQL SERVER – Refresh Database Using T-SQL
Posted in Pinal Dave, SQL, SQL Authority, SQL Performance, SQL Query, SQL Scripts, SQL Server, SQL Server DBCC, SQL Stored Procedure, SQL Tips and Tricks, T SQL, Technology on November 7, 2008 | 4 Comments »
Yesterday I received following questions on blog. Ashish Agarwal asked following question.
Hi Pinal,
Can we refresh a database (like we do by right clicking database node in object explorer and clicking on refresh) thru SQL Query?
If yes, can you please tell me the query?
Thanks,
Ashish Agarwal
Answer to above question is NO. It is not possible to do [...]
-
About Pinal Dave
Pinalkumar Dave is Microsoft SQL Server MVP, Solid Quality Mentor and a prominent author of over 1000 SQL Server articles at SQLAuthority. He is a dynamic and proficient Principal Database Architect, Corporate Trainer and Project Manager specializing in SQL Server Programming with over 7 years of hands-on experience. He holds a degree in Masters of Science and has accomplished a number of certifications including MCDBA and MCAD (.NET). He has also been awarded Regional Mentor for PASS Asia.
-
Blog Stats
- 8,544,742 Readers
-
SQLAuthority Links

My Homepage
My Resume
My Other Blog
--------------------
Top Downloads
PDF Downloads
Script Downloads
Script Bank
Favorite Scripts
All Scripts - 1
All Scripts - 2
Top Articles
Best Articles
Favorite Articles - 1
Favorite Articles - 2
--------------------
SQL Interview Q & A
SQL Coding Standards
SQL FAQ Download
--------------------
Jobs @ SQLAuthority
Categories
- About Me (50)
- Best Practices (81)
- Business Intelligence (6)
- Data Warehousing (26)
- Database (258)
- DBA (121)
- DigiCorp (7)
- MVP (82)
- Poll (5)
- Readers Contribution (22)
- Readers Question (29)
- Software Development (62)
- SQL Add-On (87)
- SQL Backup and Restore (51)
- SQL BOL (8)
- SQL Coding Standards (20)
- SQL Constraint and Keys (49)
- SQL Cursor (29)
- SQL Data Storage (39)
- SQL DateTime (36)
- SQL Documentation (193)
- SQL Download (197)
- SQL Error Messages (117)
- SQL Function (106)
- SQL Humor (22)
- SQL Index (81)
- SQL Interview Questions and Answers (53)
- SQL Joins (60)
- SQL Optimization (51)
- SQL Performance (203)
- SQL Puzzle (18)
- SQL Security (114)
- SQL Server DBCC (41)
- SQL Server Management Studio (17)
- SQL Stored Procedure (96)
- SQL String (17)
- SQL System Table (28)
- SQL Trigger (26)
- SQL User Group (41)
- SQL Utility (116)
- SQL White Papers (8)
- SQLAuthority (309)
- SQLAuthority Author Visit (62)
- SQLAuthority Book Review (18)
- SQLAuthority News (280)
- SQLAuthority Website Review (23)
- SQLServer (45)
- Tech (784)
- Pinal Dave (774)
- SQL Scripts (492)
- Technology (1031)
- SQL (1031)
- SQL Authority (1031)
- SQL Query (1031)
- SQL Server (1031)
- SQL Tips and Tricks (1031)
- T SQL (1031)
-
Top Posts
- SQL SERVER - SELECT 1 vs SELECT * - An Interesting Observation
- SQL SERVER - Insert Data From One Table to Another Table - INSERT INTO SELECT - SELECT INTO TABLE
- SQL SERVER - Insert Multiple Records Using One Insert Statement - Use of UNION ALL
- SQL SERVER - Retrieve Current Date Time in SQL Server CURRENT_TIMESTAMP, GETDATE(), {fn NOW()}
- SQL SERVER - Import CSV File Into SQL Server Using Bulk Insert - Load Comma Delimited File Into SQL Server
- SQL SERVER - Convert Text to Numbers (Integer) - CAST and CONVERT
- SQL Server Interview Questions and Answers Complete List Download
- SQL SERVER - 2005 - Create Script to Copy Database Schema and All The Objects - Stored Procedure, Functions, Triggers, Tables, Views, Constraints and All Other Database Objects
- SQL SERVER - 2008 - Interview Questions and Answers Complete List Download
- SQL SERVER - Restore Database Backup using SQL Script (T-SQL)
- SQL SERVER - 2005 List All Tables of Database
- SQL SERVER - Shrinking Truncate Log File - Log Full
-
Authors
-
pinaldave
- SQL SERVER – Two Methods to Retrieve List of Primary Keys and Foreign Keys of Database
- SQL SERVER – Four Different Ways to Find Recovery Model for Database
- SQL SERVER – Restore Sequence and Understanding NORECOVERY and RECOVERY
- SQL SERVER – Backup Timeline and Understanding of Database Restore Process in Full Recovery Model
- SQL SERVER – BLOB – Pointer to Image, Image in Database, FILESTREAM Storage
- SQLAuthority News – Big Thinkers – Robert Cain
- SQL SERVER – Standby Servers and Types of Standby Servers
- SQLAuthority News – Request SQLAuthority.com Stickers and SQL Server Cheat Sheet
- SQLAuthority News – Authors Visit – K-MUG TechEd Trivandrum on June 27, 2009
- SQLAuthority News – Book Review – Murach’s SQL Server 2008 for Developers
-
Archives
- July 2009
- June 2009
- May 2009
- April 2009
- March 2009
- February 2009
- January 2009
- December 2008
- November 2008
- October 2008
- September 2008
- August 2008
- July 2008
- June 2008
- May 2008
- April 2008
- March 2008
- February 2008
- January 2008
- December 2007
- November 2007
- October 2007
- September 2007
- August 2007
- July 2007
- June 2007
- May 2007
- April 2007
- March 2007
- February 2007
- January 2007
- December 2006
- November 2006
Pages
Category Cloud
Best Practices Database DBA MVP Pinal Dave Software Development SQL SQL Add-On SQL Authority SQLAuthority Author Visit SQLAuthority News SQL Backup and Restore SQL Documentation SQL Download SQL Error Messages SQL Function SQL Index SQL Interview Questions and Answers SQL Joins SQL Optimization SQL Performance SQL Query SQL Scripts SQL Security SQL Server SQL Stored Procedure SQL Tips and Tricks SQL Utility Technology T SQL


