Please note, this is a STATIC archive of website www.w3resource.com from 19 Jul 2022, cach3.com does not collect or store any user information, there is no "phishing" involved.
w3resource

SQL inserting NULL values

Inserting NULL values

The SQL INSERT statement can also be used to insert NULL value for a column.

Example:

Sample table: agents


To add values'A001','Jodi','London','.12','NULL' for a single row into the table 'agents' then, the following SQL statement can be used:

SQL Code:

INSERT INTO agents
VALUES ("A001","Jodi","London",.12,NULL);

SQL insert values in specific columns

The SQL INSERT INTO statement can also be used to insert one or more specific columns for a row. It is required to mention the column(s) name in the SQL query.

Example:

Sample table: agents


To add values'A001','Jodi', and ', 12' against the columns 'agent_code', 'agent_name' and 'commission' into the table 'agents', the following SQL statement can be used:

SQL Code:

INSERT INTO agents
(agent_code,agent_name,commission)
VALUES ("A001","Jodi",.12)

See our Model Database

Here is a new document which is a collection of questions with short and simple answers, useful for learning SQL as well as for interviews.

Practice SQL Exercises

Want to improve the above article? Contribute your Notes/Comments/Examples through Disqus.

Previous: Insert statement
Next: Inserting the result of a query in another table



SQL: Tips of the Day

SQL Server SELECT into existing table.

INSERT INTO dbo.TABLETWO
SELECT col1, col2
  FROM dbo.TABLEONE
 WHERE col3 LIKE @search_key

This assumes there's only two columns in dbo.TABLETWO - you need to specify the columns otherwise:

INSERT INTO dbo.TABLETWO
  (col1, col2)
SELECT col1, col2
  FROM dbo.TABLEONE
 WHERE col3 LIKE @search_key

Database: SQL Server

Ref: https://bit.ly/3y6tpA3