Retrieve Table and Column Names in SQL Server
This query retrieves the names of all tables and their corresponding columns in the current SQL Server database. It joins sys.tables (which stores information about all user-defined tables) with sys.columns (which stores information about table columns) using the object_id. This helps in understanding the structure of the database schema.
SELECT T.name AS TableName, C.name AS ColumnName FROM sys.tables T JOIN sys.columns C ON T.object_id = C.object_id;