MS SQL Server – Loop through database tables and columns

Test Environment: MS Server 2008

Stored procedure to loop through all tables and all columns in a database


Execute Stored Procedure:

3 thoughts on “MS SQL Server – Loop through database tables and columns

  1. Vevin says:

    The code above works with SQL Server 2005. However, for SQL Server 2000, you will need to use the code below:SELECT AS TableName, AS ColumnName, AS Type, C.length AS MaxLengthFROM sysobjects OINNER JOIN snucolsmys C ON = C.idINNER JOIN systypes T ON C.xtype = T.xtypeWHERE O.type = U’ORDER BY, C.colid

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">