- 5 years ago
- Zaid Bin Khalid
- 3,037 Views
-
3
In this tutorial, you will learn how to enter records and maintain database Tables by using SQL.
Inserting Data in Table.
In the previous session, we have learned how to create a table named persons in our database. Now In this session, we will learn and entered data inside the newly created database table by using SQL.
The INSERT INTO command is used to insert new rows in a database table
Syntax.
This basic syntax is used inserting data into a table which shown as given below.
INSERT INTO table_name (column1,column2,...) VALUES (value1,value2,...);
In the column1, column2,…, etc. shows the name of
the table columns, whereas the value1, value2,…, and
so on represents the corresponding values for these columns.
Let’s entered some records into the persons table.
Step 1: View Table Structure.
Before started on entering the data, it’s very useful to collect more information about table structure.
You must Enter the following command on the MySQL command line. Which will show the information about the columns in person’s table such as column name, data type, constraints, etc?
Now it will show the column information or the structure of any table in MySQL and Oracle Database by using the Command DESCRIBE table name, In SQL Server (replace the Table name with original table name).
Step 2: Adding Records to a Table.
By using mention below example statement you can inserts a new row in-person table.
INSERT INTO persons (name, birth_date, phone)
VALUES ('Peter Wilson', '1990-07-15', '0711-020361');
Have you noticed that we did not insert any value in the id field? This is because, in our previous create table chapter, the field Id has been marked as the flag of auto_increment, which allows MySQL to automatically assign value within this field if they left unspecified.
Similarly, insert another row into the persons table, as follow.
INSERT INTO persons (name, birth_date, phone)
VALUES ('Carrie Simpson', '1995-05-01', '0251-031259');
Now in a similar manner, Insert another row into the persons table.
INSERT INTO persons (name, birth_date, phone)
VALUES ('Victoria Ashworth', '1996-10-17', '0695-346721');
Now if you select the records from the person table, the output will now look like this.
+----+--------------------+------------+-------------+
| id | name | birth_date | phone |
+----+--------------------+------------+-------------+
| 1 | Peter Wilson | 1990-07-15 | 0711-020361 |
| 2 | Carrie Simpson | 1995-05-01 | 0251-031259 |
| 3 | Victoria Ashworth | 1996-10-17 | 0695-346721 |
+----+--------------------+------------+-------------+
- 5 years ago
- Zaid Bin Khalid
- 3,037 Views
-
3