Insert is a commonly used command in the Structured Query Language (SQL) data manipulation language (DML) used by SQL Server and Oracle relational databases. The insert command inserts one or more rows into a database table with the specified table column values. The insert statement is the first DML command executed immediately after creating a table.
Syntax:
There are two basic syntaxes of the INSERT query, shown below.
INSERT INTO TABLE_NAME VALUES (value1,value2,value3,...valueN);
INSERT INTO TABLE_NAME (column1, column2, column3,...columnN)
VALUES (value1, value2, value3,...valueN);
Insert value into Customer Table:
INSERT INTO CUSTOMERS (ID,NAME,AGE,ADDRESS,SALARY)
VALUES (1, 'Ramesh', 32, 'Ahmedabad', 2000.00 );
Insert value into the specific column:
INSERT INTO CUSTOMERS (ID,NAME)
VALUES (2, 'Fatima');
Insert NULL value to a column:
INSERT INTO CUSTOMERS (ID,NAME,AGE,ADDRESS,SALARY)
VALUES (3, 'Sharda', 29, NULL, 34000.00 );
Insert Default value to a column:
INSERT INTO CUSTOMERS VALUES (4, 'Abdul', 30, NULL, default );
ID | NAME | AGE | ADDRESS | SALARY |
1 | Ramesh | 32 | Ahmedabad | 25000.00 |
2 | Fatima | |||
3 | Sharda | 29 | 34000.00 | |
4 | Abdul | 30 | 10000.00 |
To copy rows from one table and insert them into another, we can use the SELECT statement in conjunction with the INSERT INTO statement. This statement is used in the same way as the INSERT INTO statement. In this case, the SELECT statement is used to select data from a different table.
Syntax:
INSERT INTO first_table SELECT * FROM second_table;
OR
INSERT INTO table1 SELECT * FROM table2 WHERE condition;
here we are inserting into another table based on some conditions.
Note: also read about SQL: Truncate, Drop, Rename Query
Please follow me to read my latest post on programming and technology if you like my post.
https://www.instagram.com/coderz.py/
https://www.facebook.com/coderz.py
Staying up to the mark is what defines me. Hi all! I’m Rabecca Fatima a keen learner, great enthusiast, ready to take new challenges as stepping stones towards flying colors.
Find the length of the longest absolute path to a file within the abstracted file…
You manage an e-commerce website and need to keep track of the last N order…
You are given a stream of elements that is too large to fit into memory.…
The formula for the area of a circle is given by πr². Use the Monte…
Given an integer k and a string s, write a function to determine the length…
There is a staircase with N steps, and you can ascend either 1 step or…