MySQL Forums
Forum List  »  Newbie

Re: AUTO_INCREMENT Problem.
Posted by: Phillip Ward
Date: April 29, 2015 05:29AM

OK, let's try this once more ...

In most DBMSs, the INSERT statement creates a single row in a table, using the values that you supply:

create table table1
( forename varchar( 30 ) 
, surname varchar( 30 ) 
); 

insert into table1 values ( 'Fred', 'Flintstone' ); 

select * from table1 ; 
+----------+------------+ 
| forename | surname    | 
+----------+------------+ 
| Fred     | Flintstone | 
+----------+------------+

This simplest syntax inserts into every field in the row but you can, if you want, tell the database which fields you want to supply values for (and the rest will be left NULL or have a default value applied to them):

insert into table1 ( forename ) values ( 'Dino' ); 

select * from table1 
order by 1 ; 
+----------+------------+ 
| forename | surname    | 
+----------+------------+ 
| Dino     | [NULL]     | 
| Fred     | Flintstone | 
+----------+------------+

MySQL has extended the Insert statement to allow you to insert multiple rows in a single statement. You do this by providing a comma-separated list of "tuples", each of which can contain a comma-separated list of field values:

insert into table1 ( forename, surname ) 
values 
  ( 'Wilma', 'Flintstone' ) 
, ( 'Barney', 'Rubble' ) 
, ( 'Betty', 'Rubble' ) 
; 

select * from table1 
order by 2, 1 ; 
+----------+------------+ 
| forename | surname    | 
+----------+------------+ 
| Dino     | [NULL]     | 
| Fred     | Flintstone | 
| Wilma    | Flintstone | 
| Barney   | Rubble     | 
| Betty    | Rubble     | 
+----------+------------+

http://dev.mysql.com/doc/refman/5.6/en/insert.html

Regards, Phill W.

Options: ReplyQuote


Subject
Written By
Posted
April 27, 2015 03:26PM
April 27, 2015 04:39PM
April 28, 2015 05:37AM
April 28, 2015 09:07AM
April 28, 2015 04:14PM
April 28, 2015 05:05PM
Re: AUTO_INCREMENT Problem.
April 29, 2015 05:29AM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.