Resources‎ > ‎SQL‎ > ‎DML Statements‎ > ‎

INSERT Statements

The insert statement is used, obviously, to add new rows to a table

The comma-delimited list of values must match the table structure exactly in the number of attributes and the data type of each attribute. Character type values are always enclosed in single quotes; number values are never in quotes; date values are often (but not always) in the format in the format that the database vendor defaults.


DB Vendor
Code Example
Oracle
Basic Insert:

INSERT INTO Target_Table
(
    Column_01
  , Column_02
  , ...
) VALUES (
    Number Data Type
  , 'Varchar Data Type'
  , ...
)

Select Into:

INSERT INTO Target_Table

(
    Column_01
  , Column_02
  , ...
)
SELECT Column_01
     , Column_02
     , ...
  FROM Source_Table
 WHERE <Desired Filter>

SQL Server
Basic Insert:

INSERT INTO Target_Table
(
    Column_01
  , Column_02
  , ...
) VALUES (
    Number Data Type
  , 'Varchar Data Type'
  , ...
)

Select Into:

SELECT Column_01
     , Column_02
     , ...
  INTO Target_Table
   FROM Source_Table
 WHERE <Desired Filter>


Note: Need to make sure that if you are inserting records into a pre-existing table, that you have a one to one column mapping with the source columns and the target columns.


Comments