Difference between revisions of "INSERT"

From braindump
Jump to navigation Jump to search
Line 3: Line 3:
{{#set:Related SQL command=UPDATE|Related SQL command=DELETE|Related SQL command=SELECT}}
{{#set:Related SQL command=UPDATE|Related SQL command=DELETE|Related SQL command=SELECT}}


INSERT is referring to the SQL command '''INSERT'''.
INSERT is refers to the SQL command '''INSERT'''.


== Summary ==
The INSERT command is used to add or insert data into a table. Syntax may vary between certain types of databases but is generally uniform across multiple vendors.
The INSERT command is used to add or insert data into a table. Syntax may vary between certain types of databases but is generally uniform across multiple vendors.

== Syntax ==
<pre>
<pre>
INSERT INTO <table> [ ( <column> [, <column> [, <column>] [, ... ]]] ) ]
INSERT INTO <table> [ ( <column> [, <column> [, <column>] [, ... ]]] ) ]
VALUES ( <value> [, <value> [, <value>, [, ...]]] )
VALUES ( <value> [, <value> [, <value>, [, ...]]] )
</pre>
</pre>

== Examples ==
For example to insert the value "foo" into a column called "bar" into a table with name "baz" do the following:
<pre>
INSERT INTO baz ( bar ) VALUES( "foo" )
</pre>
Note: The foo is encased in double quotes this is required for values other than numeric values.

Using the same example as above but use a numeric value of 400 we will not use the qouting.
<pre>
INSERT INTO baz ( bar ) VALUES( 400 )
</pre>

== Excersises ==
# Use the [[sample database]] and insert and populate it with the data from the [[File::/etc/passwd]].

Revision as of 02:01, 18 January 2011

{{#set:Related SQL command=UPDATE|Related SQL command=DELETE|Related SQL command=SELECT}}

INSERT is refers to the SQL command INSERT.

Summary

The INSERT command is used to add or insert data into a table. Syntax may vary between certain types of databases but is generally uniform across multiple vendors.

Syntax

 INSERT INTO <table> [ ( <column> [, <column> [, <column>] [, ... ]]] ) ]
   VALUES ( <value> [, <value> [, <value>, [, ...]]] )

Examples

For example to insert the value "foo" into a column called "bar" into a table with name "baz" do the following:

  INSERT INTO baz ( bar ) VALUES( "foo" )

Note: The foo is encased in double quotes this is required for values other than numeric values.

Using the same example as above but use a numeric value of 400 we will not use the qouting.

  INSERT INTO baz ( bar ) VALUES( 400 )

Excersises

  1. Use the sample database and insert and populate it with the data from the [[File::/etc/passwd]].