SQL Insert Statements

SQL INSERT statements allow you to add data to your tables.  You can do this in do ways.

  1. Provide data by value
  2. Provide data by SELECTing from another table(s)

I will show you how to add data by value.  The second method is through combining the syntax from the SELECT lesson with the INSERT statement syntax. 

Lets say we want to add the following data to our table

nID

nLegs

strColor

strSize

strType

nWeight

 

          5                    4                  Purple             Medium           Kitchen              20

To do this we will use an INSERT command.  Again, once we have completed, we will want to execute a COMMIT;  If you have not reviewed the commit, head over to the UPDATE page.

INSERT INTO <Table Name>

(<Column Name>, <Column Name>,<Column Name>,<Column Name>,<Column Name>,<Column Name>)

VALUES( <Value>, <Value>,<Value>,<Value>,<Value>,<Value>);

COMMIT;

INSERT INTO tblChair

(nID, nLegs, strColor, strSize, strType, nWeight)

VALUES (5, 4, ‘Purple’, ‘Medium’, ‘Kitchen’, 20);

COMMIT;

Do not forget the quotes when dealing with text.  The result is shown below.

nID

nLegs

strColor

strSize

strType

nWeight

1

0

Black

Big

Lounger

250

2

4

Brown

Little

Kitchen

50

3

3

Red

Medium

Kitchen

100

4

4

Blue

Huge

Stool

75

5

4

Purple

Medium

Kitchen

20

Now that you have a handle on adding data, lets move on to removing data.

FreeBSD Logo
Bouncing Badger Logo
NOF Logo