Learning SQL: Part 3: INSERT

Learning SQL

Structured Query Language (SQL) is a declarative programming language used for accessing data storied in relational databases. It appears in or is a core part of many common software packages like MySQL, PostgreSQL, Microsoft SQL Server, and Oracle Database.


In SQL, there are four common operations: SELECT, INSERT, UPDATE, and DELETE. Each of these corresponds in order to a primary action in relation to data: getting, adding, changing, and removing.

INSERT

Adding new data to a table uses the keyword INSERT.

Table Name: People
IDName
1Dan
2Chad

INTO

Similar to the pattern of SELECT… FROM when using the SELECT keyword, the INSERT keyword also uses another, INTO.

INSERT INTO

Working like the FROM keyword did for using SELECT, the INTO keyword needs the name of a table. This is where the data will be inserted.

INSERT INTO 'People'

After the name of the table comes what columns to change. These go inside open and closing parentheses.

INSERT INTO 'People' ('ID', 'Name')

VALUES

After the name of the table to put the data and the columns comes the values to add to the table. In SQL, these come after the keyword VALUES.

Like the columns, these are also in open and closing parentheses.

INSERT INTOi 'People' ('ID', 'Name') VALUES ('3', 'Jeff')

Each new entry should match the order in which its column name also appears in the column listing.

Table Name: People
IDName
1Dan
2Chad
3Jeff

Quotations and Keywords

Depending on the software used with SQL, it may not use quotations around column and table names. Some allow for column and table names to appear as lowercase alongside the uppercase keywords. Nearly always, though, the keywords themselves appear as all-uppercase letters regardless of how the column and table names themselves appear.