Jump to content

Exclude a Column from a mysql command


lorddemos90

Recommended Posts

Is there a way to exclude one specific column in a mysql database from a command.  IE: I want to use the command

$sql = "TRUNCATE TABLE DailyDataSF_copy";  But have it affect all columns except just one specified column that'll stay the same.  Any solutions to this?  The table has like 90+ columns, which is why I'd like to do it this way if at all possible.

Link to comment
https://forums.phpfreaks.com/topic/50537-exclude-a-column-from-a-mysql-command/
Share on other sites

One possible approach is do a describe on the table and from that data returned loop through it and do an update on each column name or use that to build a query on the fly. That way you do not have to type in the columns.

 

Not sure how it would work or if it would work but it might be something similiar to this:

 

<?php
$res = mysql_query("describe table_name;");

while ($row = mysql_fetch_assoc($res)) {
    if ($row['column_name'] != "90thcolumnname")
          $update .= "`".$row['column_name']."` = NULL,";
}

$update = "Update `table_name` SET " . substr($update, -1);
mysql_query($update);
?>

 

Note I am not sure of the "column_name" portion or if the describe will return a result array. But something like that should work.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.