Table Querying   «Prev  Next»

Lesson 9 Additional rows
Objective Test your new row and add additional ones.

SQL Additional Rows and Select Statement

Now that you have learned how to insert and select a row, try issuing the following command:
SELECT * FROM Customers 

What you get back should be the row you just inserted. An example of this is shown in the screen shot below.
CustomerID LastName FirstName Address1 Address2 City State Zip Code Phone
1 Sasser Sheila 9761 Vivian St Taylor MI 48180-3103 313-292-3778

All that remains is to add four more rows to the table. After you have completed the exercise, you will be ready for the next lesson, selecting information from the table.

(DML) Data Manipulation Language

DML statements are used to
  1. retrieve,
  2. add,
  3. modify, or
  4. delete data
stored in your database objects. The primary keywords associated with DML statements are
SELECT, INSERT, UPDATE, and DELETE, 

all of which represent the types of statements you will probably be using the most. For example, you can use a SELECT statement to retrieve data from a table and an INSERT statement to add data to a table.

Select Statement Example:
SELECT CD_TITLE, COPYRIGHT, IN_STOCK
FROM COMPACT_DISC_INVENTORY

The SELECT statement is one of the most common statements you will be using as an SQL programmer. It also one of the most extensive and flexible statements you will be using, allowing you to form intricate queries that can return exactly the type of data you want to retrieve from your database. The SELECT statement used in the COMPACT_DISCS_IN_STOCK view definition is a SELECT statement at its most basic. The statement is divided into two clauses: the
  1. SELECT clause and
  2. the FROM clause.
The SELECT clause identifies which columns to return (CD_TITLE, COPYRIGHT, and IN_STOCK), and the FROM clause identifies the table from which to pull the data (COMPACT_DISC_INVENTORY). When you invoke the COMPACT_DISCS_IN_STOCK view, you are essentially invoking the SELECT statement that is embedded in the view definition, which in turn pulls data from the applicable base table(s).
In the next example, the CREATE VIEW statement is nearly the same as the previous example, except that an additional clause has been added to the statement:
CREATE VIEW CDS_IN_STOCK_1990S
( COMPACT_DISC, COPYRIGHT, IN_STOCK ) AS
SELECT CD_TITLE, COPYRIGHT, IN_STOCK
FROM COMPACT_DISC_INVENTORY
WHERE COPYRIGHT > 1989 AND COPYRIGHT < 2000;

The WHERE clause defines a condition that must be met in order for data to be returned. As in the previous example, you are still pulling data from the CD_TITLE, COPYRIGHT, an IN_STOCK columns of the COMPACT_DISC_INVENTORY table, only this time you are limiting the data to those rows whose COPYRIGHT values are greater than 1989 but less than 2000 (COPYRIGHT > 1989 AND COPYRIGHT < 2000). You might recognize the comparison operators greater than (>) and less than (<) from previous modules in the discussion about CHECK constraints. They are used to limit which values will be included in the view.
Ad SQL Database Programming

Insert Additional Rows - Exercise

Click the Excercise link below to add four more rows of data to your table.
Insert Additional Rows - Exercise

SEMrush Software