Sybase

SQL INSERT INTO

Fadıl

In the previous sections, we have seen how to retrieve information from tables. But how do these rows of data get into these tables in the first place? This is what this section, covering the INSERT statement, and the next section, covering the UPDATE statement, are about.

There are essentially basically two ways to INSERT data into a table. One is to insert it one row at a time, and the other is to insert multiple rows at a time. Let’s first look at how we may INSERT data one row at a time:

SQL UPDATE

Fadıl

Once we have the information in the table, we might find that there is a need to modify the data. To do so, we can use the UPDATE command. The syntax for this is

UPDATE “table_name”
SET “column_1” = [new value]
WHERE {condition}

It is easiest to use an example. Say we currently have a table as below:

Table Store_Information

store_nameSalesDate
Los Angeles$1500Jan-05-1999
San Diego$250Jan-07-1999
Los Angeles$300Jan-08-1999
Boston$700Jan-08-1999

We find that the sales for Los Angeles on 01/08/1999 is actually $500 instead of $300, and we need to update that particular entry. To do so, we use the following SQL:

SQL DELETE

Fadıl

Sometimes rather than updating, we wish to get rid of records from the table. To do so, we can use the DELETE FROM command. The syntax for this is

DELETE FROM "table_name"WHERE {condition}

It is easiest to use an example. Say we currently have a table as below:

Table Store_Information

store_nameSalesDate
Los Angeles$1500Jan-05-1999
San Diego$250Jan-07-1999
Los Angeles$300Jan-08-1999
Boston$700Jan-08-1999

and we decide not to keep any information on Los Angeles in this table. We type the following SQL: