Jump to content

Mysql: Query A Table Column For Default Value


Recommended Posts

I am working on a script that will support a MySQL db, I am currently still learning MySQL. I am about 95% finished with the script but I have "painted myself into a corner."

 

I have written the script to change the "default value" for a table column based the last thing the script has done when it is finished. The problem is, I would like to query the "default value" for the table column early in the script. I cannot find a way to do it. Can anyone help me?

Link to post
Share on other sites
The SQL query would look something like this:

>SELECT DISTINCT `defaultvalue`
FROM `your_table`
WHERE `recordid` = yourvariable

Thanks, but that does not give me what I want.

 

I actually want to query the table structure not the data in the table.

Link to post
Share on other sites
You want the "DESCRIBE" statement.

 

Thanks, that does the trick. This is basically what I came up with.

>$sql = "DESCRIBE tbl_name col_name";

if ( $query = mysql_query($sql) )
if ( $row = mysql_fetch_row($query) ) {
	print $row[4]."<br />\n";
}
 else  print 'Error Reading Database!'."<br />\n";

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...