Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Unhiding those hidden comments 1

Status
Not open for further replies.

kupe

Technical User
Sep 23, 2002
376
Paul DuBois shows how to write comments in mysql. But where do you see them, how can you refer to them again, please Gurus?
 
Not sure what you mean there, so might as well cover the whole subject of comments.

Anything enclosed between /* ... */ is treated as a comment, as is anything between a # and the end of the line, for example:[tt]
SELECT fld1,fld2 /* comment */ FROM tbl1 # comment[/tt]

Comments can also be associated with table columns, and stored in the table definition, for later retrieval. For example:[tt]
CREATE TABLE tbl1
(
id CHAR(4) PRIMARY KEY,
name CHAR(20) NOT NULL,
dateofbirth DATE NOT NULL COMMENT 'zero means the person is dead'
);[/tt]
Those comments will then be shown if you do a SHOW CREATE TABLE query.
 
Tony, you deserve more stars than I can offer. Thanks very much for this. (And those others.) I wondered about comments because I can see them so easily in VB in Access and with Dreamweaver, but I couldn't find how to retrieve them again here. Very grateful.
 
Hi Tony

In your line -

"dateofbirth DATE NOT NULL COMMENT 'zero means the person is dead'"

- I presume that the word COMMENT is not necessary.(?)

I put your advice to the test last night. But SHOW CREATE TABLE wouldn't let me see the comments. Perhaps I need to code more than SHOW CREATE TABLE MyTbl; ? Be grateful for guidance. Cheers

 
I forgot to mention that the comments are only stored in MySQL 4.1 onwards, so if you have an older MySQL version, you won't be able to use that facility.

If you want to store a comment in the database definition, you have to use the COMMENT keyword followed by a string enclosed in single or double quotes, as shown.
 
Not sure of the version, but I suspect it is just before 4.1. However, following excellent direction from hvass, I have downloaded the apachefriends xampp, which may have a later version of mysql.

All noted about stating COMMENT, thanks. Cheers.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top