The Sql Insert Into Statement – Query Examples

The Sql Insert Into Statement

The Sql Insert Into Statement

  • The INSERT INTO statement is used to insert new data(row) in a table.
  • We can insert one or more record one time.
  • We can insert record from another  table with select statement
  • If There is autoincrement column we don’t write data for that column

Syntax

The general use:

  • If there are two or more colums then column names are separated by commas.
  • If you are writing data to all column, you do not need to write column names like below

This situation we must write values table’s column order

TO DOWNLOAD THE SAMPLE LİBRARY DATABASE CLICK

SQL INSERT INTO Examples on Library Database

Sample 1: Add record to autors table that autor name = John surname=Hawk autor_id auto increment

1. Method

2. Method (with column Names)

3. Method (with column Names rewerse)

If autor_id don’t become auto increment, we must write data because it’s primary key.

Sample 2: Add record to autors that autor name Jenny;

Not: Surname column must be null able.

1. Method

2. Method

Sample 3: Insert three records to autors table one query

1.Method

2.Method(unless column names)

Sample 4: Insert into autors table, Random selected five students

Notes about this sample:

  • “Value” word should not be written to the query.
  • Insert into statement’s column count and select statement’s column count must be the same
  • The column’s Data types must be same at same order

YOU MAY WANT TO SEE OUR ALL EXAMPLES PAGE, THEN CLICK HERE

About the author

admin

Leave a Comment

%d bloggers like this: