I need to create some pretty big tables in SQL Server 2008, while I do have SQL Server Management Studio, I would like to comment the tables and the columns when I create the table. How do I do this?
Example of the query I am running:
CREATE TABLE cert_Certifications ( certificationID int PRIMARY KEY IDENTITY, profileID int, cprAdultExp datetime null )
I've tried COMMENT'Expiration Date for the Adult CPR' and COMMENT='Expiration Date for the Adult CPR' after the data type, and SQL Server is giving me an error.
In SSMS, in Object Explorer, connect to the instance of Database Engine that contains the database to be modified. In Object Explorer, expand the Databases node and then expand the database that will contain the new table. In Object Explorer, right-click the Tables node of your database and then click New Table.
Right click the table or column and select properties. Look in the extended properties. If the database has a diagram, check the description field in the properties of the table or column. You can also query that data from the "ms_description" extended property.
To add a comment to a table, view, or materialized view, you must have COMMENT ANY TABLE system privilege. To add a comment to an indextype, you must have the CREATE ANY INDEXTYPE system privilege. To add a comment to an operator, you must have the CREATE ANY OPERATOR system privilege.
This is what I use
/*==============================================================*/ /* Table: TABLE_1 */ /*==============================================================*/ create table TABLE_1 ( ID int identity, COLUMN_1 varchar(10) null, COLUMN_2 varchar(10) null, constraint PK_TABLE_1 primary key nonclustered (ID) ) go declare @CurrentUser sysname select @CurrentUser = user_name() execute sp_addextendedproperty 'MS_Description', 'This is my table comment', 'user', @CurrentUser, 'table', 'TABLE_1' go declare @CurrentUser sysname select @CurrentUser = user_name() execute sp_addextendedproperty 'MS_Description', 'This is the primary key comment', 'user', @CurrentUser, 'table', 'TABLE_1', 'column', 'ID' go declare @CurrentUser sysname select @CurrentUser = user_name() execute sp_addextendedproperty 'MS_Description', 'This is column one comment', 'user', @CurrentUser, 'table', 'TABLE_1', 'column', 'COLUMN_1' go declare @CurrentUser sysname select @CurrentUser = user_name() execute sp_addextendedproperty 'MS_Description', 'This is column 2 comment', 'user', @CurrentUser, 'table', 'TABLE_1', 'column', 'COLUMN_2' go
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With