troubleshooting Question

Looping code through tables in a SQl Server database

Avatar of Lenny Gray
Lenny GrayFlag for United States of America asked on
Microsoft SQL ServerMicrosoft SQL Server 2008
3 Comments1 Solution301 ViewsLast Modified:
I developed code that lists the columns, types and attributes (below) and it lists what I need.
Capture3.PNGIn SysObjects, I can see xtype = 'u' as the selection criteria but how can I iterate through all tables in the database so that I will get a continuous listing of the columns, types and attributes?

select
    t.TABLE_NAME as 'Table', c.COLUMN_NAME as 'Column Name' ,c.DATA_TYPE as 'Type' ,c.CHARACTER_MAXIMUM_LENGTH as 'Length',c.NUMERIC_PRECISION as 'Numeric length',c.NUMERIC_SCALE as 'Decimals',c.DATETIME_PRECISION as 'Date/Time'
    from INFORMATION_SCHEMA.Tables t
        INNER JOIN INFORMATION_SCHEMA.Columns c ON t.TABLE_CATALOG=c.TABLE_CATALOG AND t.TABLE_SCHEMA=c.TABLE_SCHEMA AND t.TABLE_NAME=c.TABLE_NAME
    WHERE t.TABLE_NAME='assetprice'
    ORDER BY t.TABLE_NAME, c.COLUMN_NAME
ASKER CERTIFIED SOLUTION
Kyle Abrahams
Director of Information Technology

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 1 Answer and 3 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 3 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros