Presentation is loading. Please wait.

Presentation is loading. Please wait.

CREATE, INSERT, SELECT.

Similar presentations


Presentation on theme: "CREATE, INSERT, SELECT."— Presentation transcript:

1 CREATE, INSERT, SELECT

2 Creating (Declaring) a Relation
Simplest form is: CREATE TABLE <name> ( <list of elements> );

3 Elements of Table Declarations
Most basic element: an attribute and its type. The SQLite types are: INTEGER REAL TEXT BLOB (Binary Large Object)

4 Example: Create Table CREATE TABLE show ( name TEXT, FavoriteShow TEXT
);

5 SQL Values Integers and real values (floating point numbers) are represented as you would expect. Strings are too, except they require single quotes. Two single quotes = one real quote, e.g., ’Joe’’s Bar’. Any value can be NULL.

6 Insertion To insert a single tuple: INSERT INTO <relation>
VALUES ( <list of values> ); Example: add to shows(name, FavoriteShow) the fact that Samuel-Hunter likes Star Trek. INSERT INTO shows VALUES('Samuel-Hunter', 'Star Trek');

7 Select Using shows(name, FavoriteShow), what are FavoriteShows of the class? SELECT FavoriteShow FROM shows;

8 Select and order by Using shows(name, FavoriteShow), what are FavoriteShows of the class ordering by FavoriteShow? SELECT FavoriteShow FROM shows ORDER BY FavoriteShow;

9 Select Multiple Attributes
Using shows(name, FavoriteShow), what are names and FavoriteShows of the class ordering by FavoriteShow? SELECT name, FavoriteShow FROM shows ORDER BY FavoriteShow;

10 Select * Using shows(name, FavoriteShow), what are all of the attributes of the relation? SELECT * FROM shows ORDER BY FavoriteShow;

11 What order should the Tuples be returned (if there is no "order by"?
Value Ascending (e.g. alphabetical for text) Value Descending (e.g. reverse alphabetical) Insertion Order Ascending (first inserted, first outputted) Insertion Order Descending (last inserted, first outputted)

12 ORDER BY name, FavoriteShow;
Ascending by name (Ascending by FavoriteShow for ties) Descending by name (Descending by FavoriteShow for ties) Ascending by FavoriteShow (Ascending by name for ties) Descending by FavoriteShow (Descending by name for ties) SELECT * FROM shows ORDER BY name, FavoriteShow; What should the order of the rows be?


Download ppt "CREATE, INSERT, SELECT."

Similar presentations


Ads by Google