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
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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

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.   Restore formatting

  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...

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.