Inserting data in MySQL tables
The INSERT SQL statement impregnates our table with data. Here is a general form of INSERT.
INSERT into table_name (column1, column2....) values (value1, value2...);
where table_name is the name of the table into which we want to insert data; column1, column2 etc. are column names and value1, value2 etc. are values for the respective columns. This is quite simple, isn’t it?
The following statement inserts the first record in employee_data table.
INSERT INTO employee_data
(f_name, l_name, title, age, yos, salary, perks, email)
values
("Manish", "Sharma", "CEO", 28, 4, 200000,
50000, "manish@bignet.com");
As with other MySQL statements, you can enter this command on one line or span it in multiple lines.
Some important points:
Once you type the above command correctly in the mysql client, it displays a success message.
mysql> INSERT INTO employee_data
-> (f_name, l_name, title, age, yos, salary, perks, email)
-> values
-> ("Manish", "Sharma", "CEO", 28, 4, 200000,
-> 50000, "manish@bignet.com");
Query OK, 1 row affected (0.00 sec)
Inserting additional records requires separate INSERT statements. In order to make life easy, I’ve packed all INSERT statements into a file. Click to download the file, employee.dat.
Once you download the file, open it in a text editor. You’ll notice that it’s a plain ASCII file with an INSERT statement on each line.
|
« Previous
|
Next »
|
Creating tables In this section of the mysql training course we will explore the MySQL commands to create database tables and selecting the database. Databases ...
MySQL tables Now that we've created our employee_data table, let's check its listing. Type SHOW TABLES; at the mysql prompt. This should present you with ...
Column Types part 2 MySQL Text data type Text can be fixed length (char) or variable length strings. Also, text comparisions can be case sensitive ...
Possible Answers create database addressbook; OR CREATE DATABASE addressbook; Note: SQL statements are case-insensitive, though table names and database names might be sensitive to case ...
MySQL Date column type part 1 Till now we've dealt with text (varchar) and numbers (int) data types. To understand date type, we'll create one ...