> -----Original Message----- > From: Andrew Ballard [mailto:aballard@xxxxxxxxx] > Sent: Tuesday, January 27, 2009 11:39 AM > To: revDAVE > Cc: php-general@xxxxxxxxxxxxx > Subject: Re: Global Changes With Loop To Allow Nulls In A > Table... > > 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; > > > 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. I just thought I'd throw this out there... A lot of people who post questions on this list are programming their algorithms and structuring their applications in a certain way because that's what the client wants, or that's what their boss told them to do. Yes, accepting NULL values in a database is frowned upon (unless the table is a transaction table)... but I doubt his boss or his client cares in the least. My 2 cents. ;) // Todd