Presentation is loading. Please wait.

Presentation is loading. Please wait.

1 Lecture 1 Introduction Based on

Similar presentations


Presentation on theme: "1 Lecture 1 Introduction Based on"— Presentation transcript:

1 1 Lecture 1 Introduction Based on http://infolab.stanford.edu/~ullman/fcdb/aut07/index.html#lecturehttp://infolab.stanford.edu/~ullman/fcdb/aut07/index.html#lecture CS4416 Database Systems CS5122 Development of IS 2

2 2 What is a Database? uCollection of information: wExists over a long period of time wStored on secondary storage in a structured way. wManaged by a computer program called Database Management System (DBMS) uPopular DBMSs: Oracle, IBM DB2, Microsoft SQL Server, Teradata, Sybase IQ, Microsoft Access, MySQL, PostgreSQL, SQLite, db4o

3 3 What is a Database? (contd.) DBMS DATA User (person/application)

4 4 What is a Database? (contd.) uDBMS is expected to: wAllow users to create new databases and specify their schemas, using a data-definition language (DDL). Schema – logical structure of the data wGive users the ability to query and modify the data using a data- manipulation/query language (DML). The most commonly used query language is SQL. wSupport the storage of very large amounts of data over a long period of time, allowing efficient access to the data for queries and database modifications. wEnable durability, the recovery of database in the face of failures, errors of many kinds, or intentional misuse. wControl access to data from many users at once without allowing unexpected interactions among the users – isolation without actions on the data to be performed partially but not completely - atomicity

5 5 What is a Database? (contd.) DBMS DATA User or application Database administrator queries, updates (DML) schema-altering commands (DDL)

6 6 DBMS Evolution uFile Systems uFirst important applications of DBMS’s: wBanking systems wAirline reservation systems wCorporate record keeping Employment and tax records Inventories Sales records, etc. uEarly DBMS’s required the programmer to visualize data as it is stored: wHierarchical data model wNetwork data model

7 7 DBMS Evolution (contd.) uRelational database systems wTed Codd, 1970: Database systems should present the user with a view of data organised as tables called relations wQueries could be expressed in a very high-level language wNorm by 1990 uSome of the largest databases are organised differently from those using the relational methodology. uObject (Object-oriented) database systems.

8 8 Interesting Stuff About Databases uIt used to be about boring stuff: employee records, bank records, etc. uToday, the field covers all the largest sources of data, with many new ideas. wWeb search. wData mining. wScientific and medical databases. wIntegrating information.

9 9 Module Outline uRelational Database Modelling wThe Relational Data Model wDesign Theory of Relational Databases uRelational Database Programming wSQL: The Database Language wConstraints and Triggers wViews and Indexes wSQL in Server Environment The SQL/Host Language Interface Stored Procedures JDBC, PHP & MySQL, Android & SQLite uLabs: Oracle, MySQL

10 10 Data Models

11 11 What is a Data Model? Notation for describing data or information: wStructure of the data. conceptual data model wOperations on data. Queries, modifications wConstraints.

12 12 What is a Database? (contd.) DBMS DATA User or application Database administrator queries, updates (DML) schema-altering commands (DDL) Conceptual Data Model Physical Data Model

13 13 Important Data Models uRelational model – including object- relational extensions uSemistructured-data model, including XML and related standards.

14 14 Relational Data Model

15 15 A Relation is a Table name manf WinterbrewPete’s Bud LiteAnheuser-Busch Beers Attributes (column headers) Tuples (rows) Relation name

16 16 Schemas uRelation schema = relation name and attribute list. wOptionally: types of attributes. wExample: Beers(name, manf) or Beers(name: string, manf: string) uDatabase = collection of relations. uDatabase schema = set of all relation schemas in the database.

17 17 Why Relations? uVery simple model. uOften matches how we think about data. uAbstract model that underlies SQL, the most important database language today.

18 18 Do You Know SQL? uExplain the difference between: SELECT b FROM R WHERE a =10; and SELECT b FROM R; ab 520 1030 2040 R

19 19 And How About These? SELECT a FROM R, S WHERE R.b = S.b; SELECT a FROM R WHERE b IN (SELECT b FROM S); ab 520 1030 2040 R cb 10201040 S

20 20 Our Running Example Beers(name, manf) Bars(name, addr, license) Drinkers(name, addr, phone) Likes(drinker, beer) Sells(bar, beer, price) Frequents(drinker, bar) uUnderline = key (tuples cannot have the same value in all key attributes). wExcellent example of a constraint.

21 21 Database Schemas in SQL uSQL is primarily a query language, for getting information from a database. uBut SQL also includes a data-definition component for describing database schemas.

22 22 Creating (Declaring) a Relation uSimplest form is: CREATE TABLE ( ); uTo delete a relation: DROP TABLE ;

23 23 Elements of Table Declarations uMost basic element: an attribute and its type. uThe most common types are: wINT or INTEGER (synonyms). wREAL or FLOAT (synonyms). wCHAR(n ) = fixed-length string of n characters. wVARCHAR(n ) = variable-length string of up to n characters.

24 24 Example: Create Table CREATE TABLE Sells ( barCHAR(20), beerVARCHAR(20), priceREAL );

25 25 SQL Values uIntegers and reals are represented as you would expect. uStrings are too, except they require single quotes.  Two single quotes = real quote, e.g., ’Joe’’s Bar’. uAny value can be NULL.

26 26 Dates and Times uDATE and TIME are types in SQL. uThe form of a date value is: DATE ’yyyy-mm-dd’  Example: DATE ’2007-09-30’ for Sept. 30, 2007.

27 27 Times as Values uThe 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.

28 28 Declaring Keys uAn attribute or list of attributes may be declared PRIMARY KEY or UNIQUE. uEither says that no two tuples of the relation may agree in all the attribute(s) on the list. uThere are a few distinctions to be mentioned later.

29 29 Declaring Single-Attribute Keys uPlace PRIMARY KEY or UNIQUE after the type in the declaration of the attribute. uExample: CREATE TABLE Beers ( nameCHAR(20) UNIQUE, manfCHAR(20) );

30 30 Declaring Multiattribute Keys uA key declaration can also be another element in the list of elements of a CREATE TABLE statement. uThis form is essential if the key consists of more than one attribute. wMay be used even for one-attribute keys.

31 31 Example: Multiattribute Key uThe bar and beer together are the key for Sells: CREATE TABLE Sells ( barCHAR(20), beerVARCHAR(20), priceREAL, PRIMARY KEY (bar, beer) );

32 32 PRIMARY KEY vs. UNIQUE 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.


Download ppt "1 Lecture 1 Introduction Based on"

Similar presentations


Ads by Google