T-SQL INSERT STATEMENTIn T-SQL, INSERT statement is used to add new rows into the table.
Syntax:The following are the two syntaxes of Insert into a statement. Where column1, column2,.... are the columns name in the table. We cannot specify the column name in the SQL query when we add the values for the columns. The order of the values is used in the same order as specify below. The Syntax of INSERT Statement is given below:Example:Following statements will create six records in CUSTOMERS table - INSERT INTO CUSTOMERS (ID,NAME,AGE,ADDRESS,SALARY) VALUES (001, 'Rahul', 23, 'Kota', 20000.00 ); INSERT INTO CUSTOMERS (ID,NAME,AGE,ADDRESS,SALARY) VALUES (002, 'Klintan', 22, 'Mumbai', 15000.00 ); INSERT INTO CUSTOMERS (ID,NAME,AGE,ADDRESS,SALARY) VALUES (003, 'kamal', 31, 'Delhi', 25000.00 ); INSERT INTO CUSTOMERS (ID,NAME,AGE,ADDRESS,SALARY) VALUES (004, 'Chitra', 28, 'kanyakumari', 65000.00 ); INSERT INTO CUSTOMERS (ID,NAME,AGE,ADDRESS,SALARY) VALUES (005, 'Santanu', 26, 'Madhyapredesh', 38500.00 ); INSERT INTO CUSTOMERS (ID,NAME,AGE,ADDRESS,SALARY) VALUES (006, 'Savitri', 24, 'Bhopal', 4500.00 ); Syntax:We can create a record in CUSTOMERS table using the second syntax as follows - All the above statement will produce the following records in CUSTOMERS table-
Populate one table using another tableTo populate the data in one table we need to use SELECT statement over another table that has set of given fields, which are required to populate the first table. The syntax is: Next TopicT-SQL SELECT STATEMENT |