|
How can I comment inside my tables or any place in sql 2005 db?
(comments are locked)
|
|
You can use extended properties. They're available on most objects within the database and the database itself. This example is from Books Online: 2 mins... +1 :)
Oct 08 '10 at 09:22 AM
Matt Whitfield ♦♦
What is it, some sort of competition between the two of you?
Oct 08 '10 at 09:26 AM
ThomasRushton ♦
+1, Data dictionaries aren't comments within each table itself, but they're useful and simple to use too.
Oct 08 '10 at 09:28 AM
Mark
Stap me vitals, you guys are quick with the answers.
Oct 08 '10 at 09:34 AM
Phil Factor
@Phil - they are too quick for me sometimes!
Oct 08 '10 at 09:37 AM
ThomasRushton ♦
(comments are locked)
|
|
The problem (I hope I've guessed right) is that if you comment tables, columns and indexes, the comments disappear because SQL Server does not retain the creation script as it does for all the routines such as triggers, stored procedures and functions. You are supposed to use extended properties to do this. In SSMS, you usually have to get to the 'properties' context window and fill in the Extended properties with the 'MS_Description' name. (e.g. for a table, you right-click on the table in the object browser, click on properties, and when the window eventually pops up, you then click on extended properties, and add a name 'MS_Description' and the value should be the comment you wish to add. Of course this is so time-consuming that very few people do it this way. you can do it via the system stored procedures sp_addextendedproperty (Adds a new extended property to a database object), sp_dropextendedproperty (Removes an extended property from a database object), and sp_updateextendedproperty (you guessed it. Updates the value of an existing extended property) and there is a function fn_listextendedproperty. I like William Brewer's article Towards the Self-Documenting SQL Server Database. Of course, this lot is likely to drive you mad, but you can cook up a template to do the basic table documentation for you. I have to admit that I use a third-party tool to do this. @Phil - Which tool?
Oct 08 '10 at 09:38 AM
ThomasRushton ♦
I like Steve McCabe's SQLTac on http://www.sqltac.com/ but I also use SQLDoc. The advantage of SQLTac is that it nags you when you've missed putting documentation in.
Oct 08 '10 at 09:43 AM
Phil Factor
I've done a table-source builder on Simple-Talk that puts all the comments back into the table build script. http://www.simple-talk.com/sql/t-sql-programming/exploring-sql-server-table-metadata-with-ssms-and-tsql/
Oct 08 '10 at 09:45 AM
Phil Factor
(comments are locked)
|
|
When you use the table designed in management studio, you get MS_Description extended properties on tables and columns. Alternatively, there are many documentation tools that can do that for you.
(comments are locked)
|
|
There have been numerous good comments about extended properties, and they are well said and I agree. My personal preferred technique though is to keep that outside of the database and store it in the creation script for the tables which I keep in my source control. (Of course, I could also see how it would be nice if SQL Server retained the entire creation script for the tables including the comments just as it does for views and SPs, but even then I would find that to be a convenience that augments the source control, not a replacement for it.) Thank you all. I successfully used the extended properties 'MS_Description'. However can I get an example how to do this in the table creation script.
Oct 08 '10 at 07:20 PM
vihrao
(comments are locked)
|
|
OK. Here is a table template I use to get started with a new table. I then use what is produced by the Cntl Shift M in order to add the other colums and delete anything I don't want.
(comments are locked)
|
1 2 next page »


Thank you all. I successfully used the extended properties 'MS_Description'. However can I get an example how to do this in the table creation script.
I've added a second answer giving an SSMS template that one then use in order to create a new table. it gives you bits of script that you can then reuse to build up the table. Remember to save the template as a template and us Cntl Shift M to fill in all the place-holders.