-- --------------------------------------------------------------------------------------- -- Written by Kimberly L. Tripp - all rights reserved. -- -- For more scripts, sample code and Kimberly's schedule check out www.SQLSkills.com -- For "More than Just Training," see the Industry Experts at www.SolidQualityLearning.com -- -- Disclaimer - Thoroughly test this script, execute at your own risk. -- --------------------------------------------------------------------------------------- -- Since I ALWAYS recommend using a column list rather than always -- using SELECT *, here's a simple script to nicely capture all columns -- as well as adding an alias and properly "quoting" the column name -- using the QUOTENAME function. -- Change to the database in which your tables are located: USE northwind go -- This query accesses the system tables - probably not a wise -- choice moving forward but this is not likely code that will be -- within you procedures, etc. SELECT 'c.' + quotename(name, ']') + ', ' -- Change the 'c.' to be your table's alias FROM dbo.syscolumns WHERE id = object_id('customers') -- change this to be the correct table name ORDER BY colid -- OR - if you'd prefer to access this information from the -- information schema views... SELECT 'c.' + quotename(column_name, ']') + ', ' -- Change the 'c.' to be your table's alias FROM information_schema.columns WHERE table_name = 'customers' -- change this to be the correct table name ORDER BY ordinal_position