SQL Server – Can you add field descriptions in CREATE TABLE?

I can see plenty of posts about where the field description extended property lives and how I can get it, but nothing about adding these at the CREATE TABLE stage.

I’m dynamically creating tables so dynamically adding field descriptions would be a tidy thing to do but I cannot see a way.

  • Insert local data into SQL Server temp table
  • Update data in a cursor row not yet fetched sql server
  • Selecting data across day boundaries from Star schema with separate date and time dimensions
  • Does MS-SQL support in-memory tables?
  • Bitwise and logic in sql server
  • Concatenate one field after GROUP BY
  • Has anyone managed to do this?

    2 Solutions collect form web for “SQL Server – Can you add field descriptions in CREATE TABLE?”

    While you can’t do it in CREATE TABLE, you can do it at the same time, in the same database script, using this approach:

    CREATE table T1 (id int , name char (20))
    EXEC   sp_addextendedproperty 'MS_Description', 'Employee ID', 'user', dbo, 'table', 'T1', 'column', id
    EXEC   sp_addextendedproperty 'MS_Description', 'Employee Name', 'user', dbo, 'table', 'T1', 'column', name

    Then you can see your entries using this:

    SELECT   *
    FROM   ::fn_listextendedproperty (NULL, 'user', 'dbo', 'table', 'T1', 'column', default)

    I don’t believe the Create Table T-SQL statement supports this. However, if you are defining your tables via SSMS, you can easily enter table level and column level comments at the same time you create your table.

    MS SQL Server is a Microsoft SQL Database product, include sql server standard, sql server management studio, sql server express and so on.