Welcome, Guest: Register On Nairaland / LOGIN! / Trending / Recent / New
Stats: 3,150,568 members, 7,809,070 topics. Date: Thursday, 25 April 2024 at 10:20 PM

Creating Multiple Columns In The Db - Programming - Nairaland

Nairaland Forum / Science/Technology / Programming / Creating Multiple Columns In The Db (1476 Views)

How To Bundle Java Db Database In My App. / How To Deploy An Embedded Sqlite Db / Summation Of Columns (2) (3) (4)

(1) (Reply) (Go Down)

Creating Multiple Columns In The Db by rukie(f): 1:15pm On Feb 16, 2012
I have a table in database. I want to add like 50 columns into the table. What query can i write to create the 50 columns at the same time. i don't want to start creating the columns 1 by 1.

Thanks
Re: Creating Multiple Columns In The Db by naijaswag1: 3:50pm On Feb 16, 2012
Do you know sql and which dbms is that?

50 rows of data or 50 columns that represent attributes of your entity.What kind of entity will have 50 attributes? am not saying that their cant be.
Re: Creating Multiple Columns In The Db by rukie(f): 4:07pm On Feb 16, 2012
50 fields
Re: Creating Multiple Columns In The Db by Fayimora(m): 8:06pm On Feb 16, 2012
What DBMS you using? You can just create all the columns alongside the table at once but then you gonna type quite a lot of DDL and DML code.
Re: Creating Multiple Columns In The Db by Fayimora(m): 8:10pm On Feb 16, 2012
What DBMS you using? You can just create all the columns alongside the table at once but then you gonna type quite a lot of DDL and DML code.
Re: Creating Multiple Columns In The Db by eazyd(m): 8:48pm On Feb 16, 2012
I guess you using access which is easy to create rows and columns, state your DBMS and you will get help!
Re: Creating Multiple Columns In The Db by okeyxyz(m): 9:24pm On Feb 16, 2012
50 columns for one dB table is rather too much & bad design, but if u still want to go ahead, just write the sql instructions for all 50 columns at once, separating them with semicolons [;].
Re: Creating Multiple Columns In The Db by rukie(f): 8:35am On Feb 17, 2012
Thanks all, i later built a query string like this and it worked. the DBMS is mysql.

<?php
// Connects to your Database
mysql_connect("host", "username", "password"wink or die(mysql_error());
mysql_select_db("dbname"wink or die(mysql_error());
$sql="CREATE TABLE table namet (";
for($i=1; $i<=50;$i++)
{
$sql.="col_".$i." VARCHAR(255), ";
}
$sql = rtrim($sql,', ').' )';
//echo $sql;
if(mysql_query($sql)) echo 'Successful';
else echo mysql_error();

?>
Re: Creating Multiple Columns In The Db by okeyxyz(m): 1:59am On Feb 19, 2012
rukie:

<?php
// Connects to your Database
mysql_connect("host", "username", "password"wink or die(mysql_error());
mysql_select_db("dbname"wink or die(mysql_error());
$sql="CREATE TABLE table namet (";
for($i=1; $i<=50;$i++)
{
$sql.="col_".$i." VARCHAR(255), ";
}
$sql = rtrim($sql,', ').' )';
//echo $sql;
if(mysql_query($sql)) echo 'Successful';
else echo mysql_error();

?>

hmm, that's very good concept. i don't have a php/mysql system to run it but it looks great to me. i'd never have approached it like this.
though this 50 column table will be more useful as a spreadsheet, not as a database table.
Re: Creating Multiple Columns In The Db by Nobody: 4:06pm On Feb 21, 2012
i still cant picture a scenario where a "lazy" approach like this will work

maybe deadline is so close
Re: Creating Multiple Columns In The Db by rukie(f): 4:33pm On Feb 22, 2012
webdezzi:

i still cant picture a scenario where a "lazy" approach like this will work

maybe deadline is so close

So you think
Re: Creating Multiple Columns In The Db by Beaf: 12:08am On Feb 23, 2012
webdezzi:

i still cant picture a scenario where a "lazy" approach like this will work

maybe deadline is so close

I use a similar method all the time. I have just generated a project with 538 classes. I started just a week ago with some barely related XML.
The week was spent designing the app, mapping the relationships between the classes and interfaces, sorting out inheritances, generating a database and writing the generation code. After that? Press the button.

It would have taken me months and an untold amount of frustration and misery with any other approach.
Re: Creating Multiple Columns In The Db by Onyeasi(m): 5:47am On Mar 04, 2012
Please can 1 retrieve its account password. I registered an account with my school and i forgot the password likewise the security question. Please will i have it back if i go to the ITC centre? Please help me out on this
Re: Creating Multiple Columns In The Db by kodewrita(m): 7:59am On Mar 04, 2012
Onyeasi:

Please can 1 retrieve its account password. I registered an account with my school and i forgot the password likewise the security question. Please will i have it back if i go to the ITC centre? Please help me out on this
go to your itc and ask them.
Re: Creating Multiple Columns In The Db by Ghenghis(m): 8:56am On Mar 04, 2012
The approach isn't lazy, like Beaf I use the technique a lot also , but on the command prompt. You use code/sql to generate template like code/sql.

Though wrapping it with PHP probably isn't as flexible as simply storing it as .sql for later use.
Re: Creating Multiple Columns In The Db by Mobinga: 12:39pm On Mar 04, 2012
What sort of database structure is that that requires 50 columns?

Perhaps you should restructure your database.

(1) (Reply)

Help With Java Programing: Changing Motion Of A Particle In A Jpanel / Print ("how Long Will It Take To Be An Expert Python Programmer") / PHP Programmers, Pls Step In

(Go Up)

Sections: politics (1) business autos (1) jobs (1) career education (1) romance computers phones travel sports fashion health
religion celebs tv-movies music-radio literature webmasters programming techmarket

Links: (1) (2) (3) (4) (5) (6) (7) (8) (9) (10)

Nairaland - Copyright © 2005 - 2024 Oluwaseun Osewa. All rights reserved. See How To Advertise. 21
Disclaimer: Every Nairaland member is solely responsible for anything that he/she posts or uploads on Nairaland.