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.
Problem Statement: Given n pairs of parentheses, write a function to generate all combinations of well-formed parentheses. Example…
Given an integer A. Compute and return the square root of A. If A is…
Given a zero-based permutation nums (0-indexed), build an array ans of the same length where…
A heap is a specialized tree-based data structure that satisfies the heap property. It is…
What is the Lowest Common Ancestor? In a tree, the lowest common ancestor (LCA) of…