Presentation is loading. Please wait.

Presentation is loading. Please wait.

1. 2 Design of databases. E/R model (entity-relationship model) Relational model (tables) UML (unified modeling language) Database programming. SQL, Relational.

Similar presentations


Presentation on theme: "1. 2 Design of databases. E/R model (entity-relationship model) Relational model (tables) UML (unified modeling language) Database programming. SQL, Relational."— Presentation transcript:

1 1

2 2 Design of databases. E/R model (entity-relationship model) Relational model (tables) UML (unified modeling language) Database programming. SQL, Relational algebra Interface from Java and.NET framework Data security.

3 3 Database Systems: The Complete Book, 2/E ISBN-13: 9780131873254 NOTE: THE BOOK IS A MUST Some handouts given by the instructor Power point presentations (not sure!)

4 4 Test1: 15% Midterm: 20% Final: 35% Project: 20%. Any project supported by a database is acceptable. Individual Assignments: 10%. Exercises from the book in addition to some challenging ones. Individual – No late policy

5 5 SOE rules and regulation Important dates Absences and late policy Email usage SP courses policy Labs Office hours

6 6 Do not come to lectures Do not do assignments or start late Do not ask questions in class Do not come to see me during office hours Cheating is also an option

7 7 In the LAB we will use: Microsoft SQL server 2008 Oracle database 11g Visual studio Java JDK 6 Each of you should duplicate this environment on his home computer. It is needed for assignments and practices. An 8GB flash memory is required to exchange data

8 8 name mark CorollaToyota CR-VHonda Cars Attributes (column headers) Tuples (rows) Relation name

9 9 Relation schema = relation name and attribute list. Optionally: types of attributes. Example: Cars(name, mark) or Cars(name: string, mark: string) Database = collection of relations. Database schema = set of all relation schemas in the database.

10 10 Very simple model. Often matches how we think about data. Abstract model that underlies SQL, the most important database language today.

11 11 Underline indicates key attributes. Cars(name, mark) Garage( name, addr, license) Customers(name, addr, phone) Drives(customer, car) Serves (garage, car, service, price) Frequents( customer, garage)

12 12 SQL is primarily a query language, for getting information from a database. But SQL also includes a data-definition component for describing database schemas.

13 13 Simplest form is: CREATE TABLE ( ); To delete a relation: DROP TABLE ;

14 14 Most basic element: an attribute and its type. The most common types are: INT or INTEGER (synonyms). REAL or FLOAT (synonyms). CHAR(n ) = fixed-length string of n characters. VARCHAR(n ) = variable-length string of up to n characters.

15 15 CREATE TABLE Serves ( garageCHAR(20), carVARCHAR(20), serviceVARCHAR(20), priceREAL );

16 16 Integers and reals are represented as you would expect. Strings are too, except they require single quotes. Two single quotes = real quote, e.g., ’Tools’’ garage’. Any value can be NULL.

17 17 DATE and TIME are types in SQL. The form of a date value is: DATE ’yyyy-mm-dd’ Example: DATE ’2007-09-30’ for Sept. 30, 2007.

18 18 The form of a time value is: TIME ’hh:mm:ss’ with an optional decimal point and fractions of a second following. Example: TIME ’15:30:02.5’ = two and a half seconds after 3:30PM.

19 19 An attribute or list of attributes may be declared PRIMARY KEY or UNIQUE. Either says that no two tuples of the relation may agree in all the attribute(s) on the list. There are a few distinctions to be mentioned later.

20 20 Place PRIMARY KEY or UNIQUE after the type in the declaration of the attribute. Example: CREATE TABLE Cars ( nameCHAR(20) UNIQUE, markCHAR(20) );

21 21 A key declaration can also be another element in the list of elements of a CREATE TABLE statement. This form is essential if the key consists of more than one attribute. May be used even for one-attribute keys

22 22 The garage, car and service together are the key for Serves: CREATE TABLE Serves( garageCHAR(20), carVARCHAR(20), serviceVARCHAR(20), priceREAL, PRIMARY KEY (garage,car,service) );

23 23 1.There can be only one PRIMARY KEY for a relation, but several UNIQUE attributes. 2.No attribute of a PRIMARY KEY can ever be NULL in any tuple. But attributes declared UNIQUE may have NULL’s, and there may be several tuples with NULL.

24 24 Another data model, based on trees. Motivation: flexible representation of data. Motivation: sharing of documents among systems and databases.

25 25 Nodes = objects. Labels on arcs (like attribute names). Atomic values at leaf nodes (nodes with no arcs out). Flexibility: no restriction on: Labels out of a node. Number of successors with a given label.

26 26 Tiida A.B. Gold1995 Bchamoun Tools Tiida car garage mark servedAt name addr prize yearaward root The garage object for Tools’ garage The car object for Tiida Notice a new kind of data.

27 27 From the start menu, select SQL Server Management Studio In the connect to server window select Connect You are now connected to the SQL server.

28 28 From the main menu, select New Query You are now ready to create your first database Write the following query create database [CarService] GO Now click on Execute to run the query

29 29 In the object explorer window, expand the databases Notice the creation of your database Expand the CarService database

30 30 We need now to create the following tables: Cars(name(20), mark(20)) Garage( name(20), addr(40), license(10)) Customers(name(40), addr(40), phone(9)) Drives(customer(40), car(10)) Serves (garage(20), car(20), service(10), price()) Frequents( customer(40), garage(20)) Underlined attributes are primary keys

31 31 Let’s start with the Cars table Cars(name(20), mark(20)) use [CarService] create table Cars ( name CHAR(20), mark CHAR(20), primary key (name) ); Similarly create the other tables Garage( name(20), addr(40), license(10)) Customers(name(40), addr(40), phone(9)) Drives(customer(40), car(10)) Serves (garage(20), car(20), service(10), price()) Frequents( customer(40), garage(20))


Download ppt "1. 2 Design of databases. E/R model (entity-relationship model) Relational model (tables) UML (unified modeling language) Database programming. SQL, Relational."

Similar presentations


Ads by Google