dbTalk Databases Forums  

Adding to a database

comp.databases.mysql comp.databases.mysql


Discuss Adding to a database in the comp.databases.mysql forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Bint
 
Posts: n/a

Default Adding to a database - 02-09-2011 , 11:18 AM






Hello,

I have a mysql database that keeps track of some users and their files.
The database is manipulated with an iphone app that communicates with a php
script on a server.

I put this together last year, and it was my first foray into mysql. It has
worked great this whole time, but now I need to make some changes.

Being new to mysql, I just wanted to ask if it poses any problems to go in
there and add attributes to tables and possibly add other tables? You can
modify the structure once it is already in use, right? As long as the
existing structure still functions like it did before?

I just don't want to screw anything up with it as I make changes!
Thanks
B

Reply With Quote
  #2  
Old   
Erick T. Barkhuis
 
Posts: n/a

Default Re: Adding to a database - 02-09-2011 , 11:23 AM






Bint:


Quote:
Being new to mysql, I just wanted to ask if it poses any problems to
go in there and add attributes to tables and possibly add other
tables? You can modify the structure once it is already in use,
right? As long as the existing structure still functions like it did
before?
Exactly.
Keep in mind that you can define default values for new table fields.
Your existing records will also contain the new fields, so it might
make sense to have appropriate default values for records that haven't
been assigned values so far.

Oh: have you considered copying your database first and use it as a
test database? That way, you can experiment all you like, without
destroying any valuable data in your production database.
And...at least make a backup first (if you don't have one yet).

Enjoy and good luck.

--
Erick

Reply With Quote
  #3  
Old   
Luuk
 
Posts: n/a

Default Re: Adding to a database - 02-09-2011 , 11:26 AM



On 09-02-11 18:18, Bint wrote:
Quote:
Hello,

I have a mysql database that keeps track of some users and their files.
The database is manipulated with an iphone app that communicates with a php
script on a server.

I put this together last year, and it was my first foray into mysql. It has
worked great this whole time, but now I need to make some changes.

Being new to mysql, I just wanted to ask if it poses any problems to go in
there and add attributes to tables and possibly add other tables? You can
modify the structure once it is already in use, right? As long as the
existing structure still functions like it did before?

I just don't want to screw anything up with it as I make changes!
Thanks
B

Adding tables is not a problem,

The only problem i see in changing tables is, when you do something like
this now:
SELECT * from tablename;

If you do it like above, than you should first change the code to look like:
SELECT field1, field2 FROM tablename;
before you can add/change fields in this tables.

And, of course, *backup* is a safe to to begin with......

--
Luuk

Reply With Quote
  #4  
Old   
Bint
 
Posts: n/a

Default Re: Adding to a database - 02-09-2011 , 11:56 AM



Thanks, I did make a backup. Hopefully I will not have to use it!

Would it be easy to make a copy of the current database to use as an
experiment? How would I transfer the changes back to the original -- just
redo them?

Thanks
B


On 2/9/11 11:23 AM, in article 8rg0sdFcn4U1 (AT) mid (DOT) individual.net, "Erick T.
Barkhuis" <erick.use-net (AT) ardane (DOT) c.o.m> wrote:

Quote:
Bint:


Being new to mysql, I just wanted to ask if it poses any problems to
go in there and add attributes to tables and possibly add other
tables? You can modify the structure once it is already in use,
right? As long as the existing structure still functions like it did
before?

Exactly.
Keep in mind that you can define default values for new table fields.
Your existing records will also contain the new fields, so it might
make sense to have appropriate default values for records that haven't
been assigned values so far.

Oh: have you considered copying your database first and use it as a
test database? That way, you can experiment all you like, without
destroying any valuable data in your production database.
And...at least make a backup first (if you don't have one yet).

Enjoy and good luck.

Reply With Quote
  #5  
Old   
Erick T. Barkhuis
 
Posts: n/a

Default Re: Adding to a database - 02-09-2011 , 12:14 PM



Bint:

[Fullquote and toppost corrected.
Please, refrain from that. Thank you!]

Quote:

On 2/9/11 11:23 AM, in article 8rg0sdFcn4U1 (AT) mid (DOT) individual.net,
"Erick T. Barkhuis" <erick.use-net (AT) ardane (DOT) c.o.m> wrote:

....
Oh: have you considered copying your database first and use it as a
test database? That way, you can experiment all you like, without
destroying any valuable data in your production database.
And...at least make a backup first (if you don't have one yet).

Thanks, I did make a backup. Hopefully I will not have to use it!
You might want to use it to copy the database!

Quote:
Would it be easy to make a copy of the current database to use as an
experiment? How would I transfer the changes back to the original
-- just redo them?
What I had in mind was:
1. Backup table definitions and data
2. Create a second database (Test-DB), and import the backup from (1).
A tool like phpMyAdmin will come very handy
3. Copy your current scripts to another subdomain/directory and change
the DB-connection in that version to reflect the name of the Test-DB.

Now, you should be set. You have a working copy of your old application
(software and database) while the live system is still running.
You want to make changes to your Test-DB, and expand the functionality
in your Test-scripts to see if it works. Also, you will find out
whether or not you need to program, test and perform a data conversion.

[This is assuming you don't use some type of software version
management tool].

Once you're done, you can implement the changes in your live system.
All by hand, or partly automated (e.g. using MySql Workbench or such
tool).


--
Erick

Reply With Quote
  #6  
Old   
The Natural Philosopher
 
Posts: n/a

Default Re: Adding to a database - 02-09-2011 , 02:12 PM



Bint wrote:
Quote:
Hello,

I have a mysql database that keeps track of some users and their files.
The database is manipulated with an iphone app that communicates with a php
script on a server.

I put this together last year, and it was my first foray into mysql. It has
worked great this whole time, but now I need to make some changes.

Being new to mysql, I just wanted to ask if it poses any problems to go in
there and add attributes to tables and possibly add other tables? You can
modify the structure once it is already in use, right? As long as the
existing structure still functions like it did before?

yes. You can change tables by adding fields, or add tables, seamlessly.
Modifying fields or removing them is much riskier, as you then have to
consider if your application code will try to explicitly access fields
that no longer exist and throw an error.

But I have e.g. turned a BLOB into a MEDIUM_BLOB (IIRC) to get an
oversize image to fit, with no side effects beyond thecode suddenly
working like it should, and not sending me truncated pikkies! :-)
Quote:
I just don't want to screw anything up with it as I make changes!#
well backup first then plan carefully and consider implications, and
test afterwards, but yes, in general this is not a huge issue at the
MySQL level. It is far more an issue with the applications that use the
database.

Reply With Quote
  #7  
Old   
Captain Paralytic
 
Posts: n/a

Default Re: Adding to a database - 02-09-2011 , 02:36 PM



On Feb 9, 5:26*pm, Luuk <L... (AT) invalid (DOT) lan> wrote:
Quote:
On 09-02-11 18:18, Bint wrote:





Hello,

* I have a mysql database that keeps track of some users and their files.
The database is manipulated with an iphone app that communicates with aphp
script on a server.

I put this together last year, and it was my first foray into mysql. *It has
worked great this whole time, but now I need to make some changes.

Being new to mysql, I just wanted to ask if it poses any problems to goin
there and add attributes to tables and possibly add other tables? *You can
modify the structure once it is already in use, right? *As long as the
existing structure still functions like it did before?

I just don't want to screw anything up with it as I make changes!
Thanks
B

Adding tables is not a problem,

The only problem i see in changing tables is, when you do something like
this now:
SELECT * from tablename;
Not as devastating as INSERT INTO tablename VALUES (...)

Reply With Quote
  #8  
Old   
Gordon Burditt
 
Posts: n/a

Default Re: Adding to a database - 02-09-2011 , 03:57 PM



Quote:
Being new to mysql, I just wanted to ask if it poses any problems to go in
there and add attributes to tables and possibly add other tables? You can
Learn how to use ALTER TABLE (and how to undo changes you make).
Also it's probably best to have a test database and a production
database. And learn how to make backups and restore them.

Quote:
modify the structure once it is already in use, right? As long as the
existing structure still functions like it did before?
There are some gotchas which you need to watch out for, but you
can avoid these with careful SQL programming. You might want
to change some existing code.

Adding new tables should not cause problems.

Adding columns to tables might cause problems (especially if they
are not added at the end). Re-ordering columns within tables might
cause problems.

For example:

INSERT INTO members VALUES (756, 'John Doe', 'john (AT) doe (DOT) com', 'Y');
will quit working if you add a 5th column and/or re-order the
columns. Fix: list the column names.

INSERT INTO members (id, name, email, active)
VALUES (756, 'John Doe', 'john (AT) doe (DOT) com', 'Y');

SELECT * from members;
might quit working, especially if you re-order the columns and
your access to the columns is by order, not by name. Fix: list
the columns you want. Not retrieving columns you don't need will
save a small amount of CPU time and network activity.


Quote:
I just don't want to screw anything up with it as I make changes!
Make backups.

Reply With Quote
  #9  
Old   
Captain Paralytic
 
Posts: n/a

Default Re: Adding to a database - 02-10-2011 , 03:55 AM



On Feb 9, 5:18*pm, Bint <b... (AT) ign (DOT) com> wrote:
Quote:
I just don't want to screw anything up with it as I make changes!
Surely you are not making changes to the live system first???

You make changes on your development system, then test the changes and
put them live when you are happy that all is working fine.

Reply With Quote
  #10  
Old   
Bint
 
Posts: n/a

Default Re: Adding to a database - 02-10-2011 , 11:33 AM



On 2/9/11 2:36 PM, in article
d06a4383-dd44-4f4d-b097-c49e4d8c49ef...oglegroups.com, "Captain
Paralytic" <paul_lautman (AT) yahoo (DOT) com> wrote:

Quote:
On Feb 9, 5:26*pm, Luuk <L... (AT) invalid (DOT) lan> wrote:
On 09-02-11 18:18, Bint wrote:

Hello,

* I have a mysql database that keeps track of some users and their files.
The database is manipulated with an iphone app that communicates with a php
script on a server.

I put this together last year, and it was my first foray into mysql. *It has
worked great this whole time, but now I need to make some changes.

Being new to mysql, I just wanted to ask if it poses any problems to go in
there and add attributes to tables and possibly add other tables? *You can
modify the structure once it is already in use, right? *As long as the
existing structure still functions like it did before?

I just don't want to screw anything up with it as I make changes!
Thanks
B

Adding tables is not a problem,

The only problem i see in changing tables is, when you do something like
this now:
SELECT * from tablename;

Not as devastating as INSERT INTO tablename VALUES (...)
Yikes! I have that in my upload script. It's ok if I name the values,
right? But I don't. I just use INSERT INTO files VALUES (...).

Still, though, if I added the new field at the end and gave it a default
value, won't it still work ok?

Thanks
B

Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.