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
  #11  
Old   
Erick T. Barkhuis
 
Posts: n/a

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






Bint:

Quote:
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:

On Feb 9, 5:26*pm, Luuk <L... (AT) invalid (DOT) lan> wrote:

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?
May I suggest you change that to:
INSERT tablename SET
field1 = "..."
field2 = 3456
(etc.)

That way, missing fields in the query will obtain the default value.
Disadvantage: only by means of testing, you will notice whether or not
you forgot to add a field if you wanted to. With the VALUES clause, on
the other hand, if you forget a field, you will get a MySQL error
message. It's up to you which advantage you prefer and which
disadvantage you accept.


--
Erick

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

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






On 10-02-11 18:54, Erick T. Barkhuis wrote:
Quote:
Bint:

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:

On Feb 9, 5:26 pm, Luuk <L... (AT) invalid (DOT) lan> wrote:

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?

May I suggest you change that to:
INSERT tablename SET
field1 = "..."
field2 = 3456
(etc.)

That way, missing fields in the query will obtain the default value.
Disadvantage: only by means of testing, you will notice whether or not
you forgot to add a field if you wanted to. With the VALUES clause, on
the other hand, if you forget a field, you will get a MySQL error
message. It's up to you which advantage you prefer and which
disadvantage you accept.


same is true for:
INSERT INTO tablename(field1, field2) VALUES (.....);

i like this syntax more, but that's personal

--
Luuk

Reply With Quote
  #13  
Old   
Jerry Stuckle
 
Posts: n/a

Default Re: Adding to a database - 02-10-2011 , 01:15 PM



On 2/10/2011 1:46 PM, Luuk wrote:
Quote:
On 10-02-11 18:54, Erick T. Barkhuis wrote:
Bint:

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:

On Feb 9, 5:26 pm, Luuk<L... (AT) invalid (DOT) lan> wrote:

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?

May I suggest you change that to:
INSERT tablename SET
field1 = "..."
field2 = 3456
(etc.)

That way, missing fields in the query will obtain the default value.
Disadvantage: only by means of testing, you will notice whether or not
you forgot to add a field if you wanted to. With the VALUES clause, on
the other hand, if you forget a field, you will get a MySQL error
message. It's up to you which advantage you prefer and which
disadvantage you accept.



same is true for:
INSERT INTO tablename(field1, field2) VALUES (.....);

i like this syntax more, but that's personal

It's also SQL standard. Using SET in an INSERT statement is not.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex (AT) attglobal (DOT) net
==================

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

Default Re: Adding to a database - 02-11-2011 , 05:38 AM



Luuk wrote:
Quote:
On 10-02-11 18:54, Erick T. Barkhuis wrote:
Bint:

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:

On Feb 9, 5:26 pm, Luuk <L... (AT) invalid (DOT) lan> wrote:
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?
May I suggest you change that to:
INSERT tablename SET
field1 = "..."
field2 = 3456
(etc.)

That way, missing fields in the query will obtain the default value.
Disadvantage: only by means of testing, you will notice whether or not
you forgot to add a field if you wanted to. With the VALUES clause, on
the other hand, if you forget a field, you will get a MySQL error
message. It's up to you which advantage you prefer and which
disadvantage you accept.



same is true for:
INSERT INTO tablename(field1, field2) VALUES (.....);

i like this syntax more, but that's personal

I don't, because on-screen the values, especially with a BIG insert, are
separated too far from the field names..

Any syntax that helps me. or a maintainer who may come after me, not
make stupid mistakes, is the one I go for. :-)

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.