How to use MySQL 5 Part 2: Add Data |
||||||||||||
This article and tutorial describes and demonstrates how you can:
-
[ click here ] Add data using the INSERT command
-
[ click here ] Add and update data using the REPLACE command
The MySQL INSERT command is how you put information into the tables you create and use. It is the primary way of adding new information to your mysql database.
INSERT will give an error if you use it to add data that is a duplicate of row data already in the table. In other words, if the key portion of what you are adding is already there, then an error will result.
INSERT SYNTAX
Steps To Add Data using the |
Visual Demonstration |
|---|---|
|
Syntax:
INSERT MyTable SET CustomerNumber='100', CustomerName='ACME Hardware'
or
INSERT MyTable (CustomerNumber, CustomerName) Values('100', 'ACME Hardware')
"INSERT inserts new rows into an existing table. The INSERT ... VALUES and INSERT ... SET forms of the statement insert rows based on explicitly specified values. ... "
[ return to top ]
The MySQL REPLACE command is how you can also put information into the tables you create and use. It is the a way of adding or updating new information to your mysql database.
REPLACE will not give an error if you use it to add data that is a duplicate of row data already in the table, instead, it will put the information on top of the existing data. In other words, if the key portion of what you are adding is already there, then an update will result.
REPLACE SYNTAX
Steps To Add Data using the |
Visual Demonstration |
|---|---|
|
Syntax:
REPLACE MyTable SET CustomerNumber='100', CustomerName='ACME Hardware'
or
REPLACE MyTable (CustomerNumber, CustomerName) Values('100', 'ACME Hardware')
"REPLACE works exactly like INSERT, except that if an old row in the table has the same value as a new row for a PRIMARY KEY or a UNIQUE index, the old row is deleted before the new row is inserted. ... "
[ return to top ]















