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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Tue, Jan 27, 2009 at 11:53 AM, revDAVE <Cool@xxxxxxxxxxxxxxxx> 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....
>
> My Beginning attempt needs help...
>
>
> $i = 1;
> while ($i <= 100):
>
> // how do I word this to just change whatever field we are on to allow
> nulls?
>
> $sql = 'ALTER TABLE `mytable` ?*update*? `'.$???WhatEverField??[$i].'`
> ?ALLOWNULL?;';
>
> //mysql_query($sql);
>
> $result = mysql_query($sql) or die("<br /><br /> Could not renumber dB $sql
> <br /><br />" . mysql_error());
>
>
>    $i++;
> endwhile;
>
>
> Thanks in advance
>
>
>
> --
> Thanks - RevDave
> Cool @ hosting4days . com
> [db-lists 09]


The other responses should get you started if this is something you
really want to do. However, I'll play devil's advocate here and just
raise the question why you would want to make this change in the first
place. I'm not quite as anti-NULL as a lot of arguments I've read
against them, but I tend to agree that the number of columns that
accept NULL values should be kept as small as possible. Even if you
decide that you need to allow NULL values in some cases, IMHO I
wouldn't write a script that ran through my entire database and opened
every column in every table to accept.

Just my 2 cents.

Andrew

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux