INSERT Statement

Access SQL
  • Syntax
  • Examples
  • Advanced

Syntax:

INSERT INTO TableName (Column, Column)
VALUES(NewValue, NewValue);


What does it do?
The INSERT statement adds a new row to a table. Inside the parenthesis after the TableName you can explicitly state which Columns to add data into, then inside the parenthesis after the Values, the data for the new row is entered.

Note: if the table has an auto number column, leave that column out of the statement, an incremented value will automatically be entered for the row.




Syntax - Inserting other table rows:

This method will select all the rows from one table and insert them into another one. For this version of this method work the destianation table must be an exact duplicate(column names and types).


INSERT INTO TableName1
SELECT * FROM TableName2;




Syntax - Inserting partial column/row data:

This method will insert paritial column or row data, depending upon the where restriction, if the where is omitted the whole column data will be inserted


INSERT INTO TableName1(Column)
SELECT Column FROM TableName2
WHERE TableName2.Column = Value;

Example - Adding new row:

INSERT INTO Customers (FirstName, LastName)
VALUES('Kelly', 'Davis');


Results:


CustomerID FirstName LastName
1 John Doe
2 Jane Doe
3 Jack Jackson
4 Jill Brown
5 Kelly Davis

Legend

Blue - Is used to identify reserved keywords/characters that are used by the SQL engine, i.e. SELECT, FROM, or WHERE.


Purple - Is used to identify portions of the SQL statement that are defined by the user, i.e. Column Names, Table Names, Inputed Values.