• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Devaka Cooray
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Tim Moores
  • Carey Brown
  • Mikalai Zaikin
Bartenders:
  • Lou Hamers
  • Piet Souris
  • Frits Walraven

howto modify database structure ?

 
Ranch Hand
Posts: 834
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi, does anyone have idea to modify structure od existing database, say example, i have a table in mysql, and this table contains 5 fields/columns now, we now allow user to add existing fields/columns in the existing table, can we do that ? thank you !
 
Ranch Hand
Posts: 2874
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i think you mean allow user to add new fields/columns in existing table. yeah we can.
[ September 28, 2004: Message edited by: adeel ansari ]
 
Adeel Ansari
Ranch Hand
Posts: 2874
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
make two tables for example,

USER_DEFINED_COLUMN
COLUMN_ID, TABLE_ID, STATUS_ID, COLUMN_NAME, COLUMN_LENGTH, LABLE, DATATYPE

DYNAMIC_TABLE
TABLE_ID, TABLE_NAME

now you can manipulate the new fields with the help of these tables. you can:

delete added columns
modify added columns
add new columns

these table just keep the record of the added columns. the real columns are gonna add in the real table.

if you need some code i think i can provide you some.
 
Alvin chew
Ranch Hand
Posts: 834
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
adeel, kindly please provide me some sample code on it if possible , thank you very much for your help !!

i'm sorry since i'm not clear on your idea, do you mind to specify it ? thank you again !!
 
Adeel Ansari
Ranch Hand
Posts: 2874
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ok this is my DAO. I hope you would be able to get logic atleast.

method for adding fields in the existing table



method for deleting fields (previously added) in the existing table



method for modifying fields (previously added) in the existing table


[ September 28, 2004: Message edited by: adeel ansari ]
 
Alvin chew
Ranch Hand
Posts: 834
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
adeel, thanks for helping !!!
 
Alvin chew
Ranch Hand
Posts: 834
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
adeel, any reason why you put "?" in your query string ?
 
Adeel Ansari
Ranch Hand
Posts: 2874
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
we should use ? when using prepared statement. afterwards by doing

pStmt.setString(1, "example");

the first ? of your string gets changed by the value. in this case ? would be changed into "example".

- it will allow you to set the value on the fly
- it will save you from sql injection
- easy in writing. dont really have to bother with string concatenations
- prepared statements are precompiled unlike statement
 
Alvin chew
Ranch Hand
Posts: 834
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thanks for answering , adeel !!
 
The first person to drink cow's milk. That started off as a dare from this tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic