Re: Re: Global Changes With Loop To Allow Nulls In A Table...

From: Date: Tue, 27 Jan 2009 17:21:52 +0000
Subject: Re: Re: Global Changes With Loop To Allow Nulls In A Table...
References: 1 2  Groups: php.general 
Request: Send a blank email to php-general+get-287221@lists.php.net to get a copy of this message
Jay Moore wrote:
revDAVE wrote:
Hi Folks, Newbie question.... I have a mysql table with 100 fields, currently all do not allow nulls. Rather than hand typing in phpMyAdmin, I would like a way to loop through all fields and update them to allow nulls....
First I would DESCRIBE the table so you get a list of column names and attributes. Then I would go thru each column and CHANGE it so it has the same attributes, adding the NULL flag if necessary. There may be an easier way however. Jay
I wouldn't bother mixing in PHP in all this. In the mysql client, do a SHOW CREATE TABLE tableName\G (The \G will save you from seeing lots of wrapping ---------'s) Copy the returned CREATE TABLE statement, paste into your editor. Re-use the column definitions to craft the appropriate ALTER TABLE statement. Run in your mysql client, after testing on a copy of the table, or backup your data first, whichever is appropriate to your situation.. For a PHP solution, PEAR MDB2 (specifically the Manager and Reverse modules) could be used, but I would only use it for recurring situations where a generic solution is appropriate, not for a one-off operation like this seems to be. Cheers, Mattias

« previous php.general (#287221) next »