tldr tsql show create table
- User
tldr tsql show create table
Assistant
TL;DR: T-SQL Show Create Table Equivalent
In T-SQL (Microsoft SQL Server), there isn't a direct
SHOW CREATE TABLEcommand like in MySQL, but you can get similar information using these methods:Option 1: Using
sp_helpEXEC sp_help 'YourTableName';Option 2: Using
OBJECT_DEFINITIONwithsys.sql_modulesSELECT OBJECT_DEFINITION(OBJECT_ID('YourTableName'));Option 3: Generate Scripts in SSMS
- Right-click the table in SQL Server Management Studio
- Select "Script Table as" > "CREATE To" > "New Query Editor Window"
Option 4: Using
INFORMATION_SCHEMAviewsSELECT c.COLUMN_NAME, c.DATA_TYPE, c.CHARACTER_MAXIMUM_LENGTH, c.IS_NULLABLE, CASE WHEN pk.COLUMN_NAME IS NOT NULL THEN 'PRIMARY KEY' ELSE '' END AS KeyType FROM INFORMATION_SCHEMA.COLUMNS c LEFT JOIN (SELECT COLUMN_NAME FROM INFORMATION_SCHEMA.KEY_COLUMN_USAGE WHERE TABLE_NAME = 'YourTableName') pk ON c.COLUMN_NAME = pk.COLUMN_NAME WHERE c.TABLE_NAME = 'YourTableName';Note: For a complete CREATE TABLE script with all constraints, the SSMS scripting option is most comprehensive.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.