SQL INSERT INTO Statement

previous next


The INSERT INTO Statement

The INSERT INTO statement is used to insert new rows into a table.

Syntax

INSERT INTO tableName VALUES (value1, value2, ...);

You can also specify the columns for which you want to insert data:

INSERT INTO tableName (columnName1, columnName2, ...) VALUES (value1, value2, ...);

 


Insert a New Row

This "Books" table:

Title

Author

Publisher

Year

الدورة الدموية

إبن النفيس

دار العلم

1650

Java 2

L. Johnston

Fast Press

2002

Linux and Unix

J. Sam

Fast Press

2004

Linux Distributions

J. Sam

Fast Press

2003

Operating Systems

M. Stone

Coriolis

2005

And this SQL statement:

INSERT INTO Books VALUES ('Web Programming', 'K. Yariv', 'East Edition', 2006);

Will give this result:

Title

Author

Publisher

Year

الدورة الدموية

إبن النفيس

دار العلم

1650

Java 2

L. Johnston

Fast Press

2002

Linux and Unix

J. Sam

Fast Press

2004

Linux Distributions

J. Sam

Fast Press

2003

Operating Systems

M. Stone

Coriolis

2005

Web Programming

K. Yariv

East Edition

2006

 


Insert Data in Specified Columns

The last table and this SQL statement:

INSERT INTO Books (Title, Publisher) VALUES ('XML Language', 'Science Edition');

Will give this result:

Title

Author

Publisher

Year

الدورة الدموية

إبن النفيس

دار العلم

1650

Java 2

L. Johnston

Fast Press

2002

Linux and Unix

J. Sam

Fast Press

2004

Linux Distributions

J. Sam

Fast Press

2003

Operating Systems

M. Stone

Coriolis

2005

Web Programming

K. Yariv

East Edition

2006

XML Language

null

Science Edition

null

 


Test your SQL Skills

To test your SQL skills click here.


previous next