Mysql: Query A Table Column For Default Value

liunx

Guest
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."<br /><br />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?<!--content-->
The SQL query would look something like this:<br /><!--c1--><div class='codetop'>CODE</div><div class='codemain'><!--ec1-->SELECT DISTINCT `defaultvalue`<br />FROM `your_table`<br />WHERE `recordid` = yourvariable<!--c2--></div><!--ec2--><!--content-->
<!--quoteo(post=171483:date=Mar 25 2006, 12:01 PM:name=timhodge)--><div class='quotetop'>QUOTE(timhodge @ Mar 25 2006, 12:01 PM) <a href="http://www.totalchoicehosting.com/forums/index.php?act=findpost&pid=171483"><img src='http://www.totalchoicehosting.com/forums/style_images/1/post_snapback.gif' alt='*' border='0' /></a></div><div class='quotemain'><!--quotec-->The SQL query would look something like this:<br /><!--c1--><div class='codetop'>CODE</div><div class='codemain'><!--ec1-->SELECT DISTINCT `defaultvalue`<br />FROM `your_table`<br />WHERE `recordid` = yourvariable<!--c2--></div><!--ec2--><!--QuoteEnd--></div><!--QuoteEEnd--><br />Thanks, but that does not give me what I want.<br /><br />I actually want to query the table structure not the data in the table.<!--content-->
You want the "DESCRIBE" statement.<br /><a href="http://dev.mysql.com/doc/refman/4.1/en/describe.html" target="_blank">http://dev.mysql.com/doc/refman/4.1/en/describe.html</a><!--content-->
<!--quoteo(post=171494:date=Mar 25 2006, 10:18 AM:name=jhollin1138)--><div class='quotetop'>QUOTE(jhollin1138 @ Mar 25 2006, 10:18 AM) <a href="http://www.totalchoicehosting.com/forums/index.php?act=findpost&pid=171494"><img src='http://www.totalchoicehosting.com/forums/style_images/1/post_snapback.gif' alt='*' border='0' /></a></div><div class='quotemain'><!--quotec-->I actually want to query the table structure not the data in the table.<!--QuoteEnd--></div><!--QuoteEEnd--><br />Guess my reading comprehension skills could use some work. In this case, I agree that DESCRIBE is the way to go.<!--content-->
<!--quoteo(post=171497:date=Mar 25 2006, 01:29 PM:name=borfast)--><div class='quotetop'>QUOTE(borfast @ Mar 25 2006, 01:29 PM) <a href="http://www.totalchoicehosting.com/forums/index.php?act=findpost&pid=171497"><img src='http://www.totalchoicehosting.com/forums/style_images/1/post_snapback.gif' alt='*' border='0' /></a></div><div class='quotemain'><!--quotec-->You want the "DESCRIBE" statement.<!--QuoteEnd--></div><!--QuoteEEnd--><br /><br />Thanks, that does the trick. This is basically what I came up with.<br /><!--c1--><div class='codetop'>CODE</div><div class='codemain'><!--ec1-->$sql = "DESCRIBE tbl_name col_name";<br />    <br />if ( $query = mysql_query($sql) )<br />    if ( $row = mysql_fetch_row($query) ) {<br />        print $row[4]."<br />\n";<br />    }<br />  else  print 'Error Reading Database!'."<br />\n";<!--c2--></div><!--ec2--><!--content-->
Thanks for the update. Glad you got it working.<!--content-->
 
Back
Top