Monday, September 9, 2024

How do I get the list of columns in a table with their data types in SQL Server?

 Use the following query to retrieve a list of all columns and their data types:

SELECT COLUMN_NAME, DATA_TYPE, CHARACTER_MAXIMUM_LENGTH FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = 'YourTableName';

This will return all column names, data types, and their maximum length for the specified table.