lecture 2


Published on

1 Like
  • Be the first to comment

No Downloads
Total views
On SlideShare
From Embeds
Number of Embeds
Embeds 0
No embeds

No notes for slide
  • lecture 2

    1. 1. Lecture Outline <ul><li>File system vs. db system </li></ul><ul><li>Overview of database systems </li></ul><ul><li>Preliminary on SQL </li></ul>
    2. 2. What was it like before DBMS was available ? <ul><li>By storing the data in files: </li></ul><ul><li>customers.txt transaction.txt manufacture.txt </li></ul><ul><li>Now write C++ programs to implement specific tasks </li></ul>
    3. 3. Doing it without a DBMS... <ul><li>Record the fact that “Bill” bought “an Ford Explore” (let us further assume Bill is a new customer, and it is the first time for he to buy a car from the agency: </li></ul><ul><ul><li>Read ‘Customer.txt’ </li></ul></ul><ul><ul><li>Read ‘transaction.txt’ </li></ul></ul><ul><ul><li>Find&update or add bill to the record “Customer.txt” </li></ul></ul><ul><ul><li>Update ‘transaction.txt’ </li></ul></ul><ul><ul><li>Write “customer.txt” </li></ul></ul><ul><ul><li>Write “transaction.txt” </li></ul></ul>Write a C program to do the following:
    4. 4. Problems without an DBMS... <ul><li>Assume you use C++ language. </li></ul><ul><li>If data structure changes, you need to change C code. </li></ul><ul><li>If you want to record other information, you need define new data structure literally and write another set of new C++ programs to manipulate the modified data structure. You need recompile the source code. </li></ul>
    5. 5. Problems without an DBMS... <ul><li>You have to take everything into consideration in order to make your program robust and bullet proof. </li></ul><ul><ul><li>Read ‘customers.txt’ </li></ul></ul><ul><ul><li>Read ‘transactions.txt’ </li></ul></ul><ul><ul><li>Find&update or add the record “bill” </li></ul></ul><ul><ul><li>Find&update or add the record “bill bought a ford Explore” </li></ul></ul><ul><ul><li>Write “customers.txt” </li></ul></ul><ul><ul><li>Write “transactions.txt” </li></ul></ul>CRASH !
    6. 6. Problems without an DBMS <ul><li>Think about how many kinds of data manipulation needs? </li></ul><ul><ul><li>Sort </li></ul></ul><ul><ul><li>Summation </li></ul></ul><ul><ul><li>Count </li></ul></ul><ul><ul><li>Search </li></ul></ul><ul><ul><li>Modification </li></ul></ul><ul><ul><li>List could be very long Etc. </li></ul></ul><ul><li>Each of them could be needed for each table or even for questions regarding multiple tables. </li></ul><ul><li>Each of them need to be hard coded in C++. </li></ul>
    7. 7. <ul><li>Crash management </li></ul><ul><li>Concurrency control </li></ul><ul><li>Transaction management </li></ul><ul><li>Internal low level coding </li></ul><ul><li>Exception handling </li></ul><ul><li>User control </li></ul><ul><li>Disk space management </li></ul><ul><li>backup </li></ul><ul><li>List goes long … </li></ul>Many other Problems without an DBMS...
    8. 8. History of DBMS and RDBMS <ul><li>Read introduction chapter of the Textbook and any other RDBMS books. </li></ul>
    9. 9. Database and DBMS <ul><li>What is a database? </li></ul><ul><ul><li>A set of organized files or a collection of files that store the data. </li></ul></ul><ul><ul><li>A database is a collection of data that is saved and organized in files so that the data can easily be accessed, managed, and updated. </li></ul></ul><ul><ul><li>Data organized in some predefined ways usually saved in files. </li></ul></ul><ul><li>What is a database management system (stripped down)? </li></ul><ul><ul><li>A piece of software that </li></ul></ul><ul><ul><li>Database Management System = DBMS </li></ul></ul><ul><ul><li>A big piece of software (written by system software programmers in CC++) that accesses and updates those files for you, designed to make data storing and manipulation tasks easier. </li></ul></ul><ul><li>By storing data in a DBMS, rather than as a collection operating system files, we can use the DBMS’s features to manage the data in a robust and efficient manner. </li></ul>
    10. 10. Advantages of A DBMS <ul><li>Data indepence </li></ul><ul><li>Efficient data access </li></ul><ul><li>Powerful Query language </li></ul><ul><li>Data integrity and security </li></ul><ul><li>Data administration </li></ul><ul><li>Concurrent access and crash recovery </li></ul><ul><li>Reduced application development time </li></ul>
    11. 11. Data independence <ul><li>Application programs should be as independent as possible from details of data representation and storage. The DBMS can provide an abstract view of the data to insulate application code from such details. </li></ul>
    12. 12. Where are DBMS used ? <ul><li>DBMS is pervasive, used almost everywhere in your daily life. </li></ul><ul><li>You are actually living in a human being world that, is kept monitored, tracked by all kinds of DBMS in a digital world. </li></ul><ul><li>In other words, you and your behavior are a bunch of data in this digital era. </li></ul>
    13. 13. <ul><li>data model: </li></ul><ul><ul><li>relational / object-orieted / hierarchical / network / object-relational </li></ul></ul><ul><li>users: single-user / multi-user </li></ul><ul><li>location: distributed / centralized </li></ul><ul><li>cooperation: homogeneous / heterogeneous </li></ul><ul><li>OLTP: on-line transaction processing </li></ul><ul><ul><li>Used to run the day-to-day operations of a business </li></ul></ul><ul><ul><li>event-oriented: take an order, make a reservation, payment for goods, withdraw cash, ... </li></ul></ul>Classification of DBMSs
    14. 14. RDBMS <ul><li>We are interested in Relational Database system. </li></ul><ul><li>Relational DBMS = RDBMS </li></ul><ul><li>In relational model database, data files are structured as relations (tables) </li></ul>
    15. 15. Database Systems <ul><li>The giant commercial database vendors: </li></ul><ul><ul><li>Oracle </li></ul></ul><ul><ul><li>IBM (with DB2) </li></ul></ul><ul><ul><li>Microsoft (SQL Server) </li></ul></ul><ul><ul><li>Sybase </li></ul></ul><ul><li>Some free database systems (Unix) : </li></ul><ul><ul><li>Postgres </li></ul></ul><ul><ul><li>MySQL </li></ul></ul><ul><ul><li>Predator </li></ul></ul><ul><li>In CSCI242 we use Oracle QL Server. </li></ul><ul><ul><li>You can also choose MySQL, but less support! </li></ul></ul><ul><ul><li>If you are thinking about Access, try it later on your own. </li></ul></ul>
    16. 16. An Example of a Traditional Enterprise level Database Application <ul><li>Suppose we are building a system </li></ul><ul><li>to store the information about: </li></ul><ul><li>customers </li></ul><ul><li>products </li></ul><ul><li>manufactures </li></ul><ul><li>who buys what, who produces what </li></ul>
    17. 17. more examples of RDBMS <ul><ul><li>Backend for traditional “database” applications </li></ul></ul><ul><ul><ul><li>Registrar system at SUCO </li></ul></ul></ul><ul><ul><li>Backend for large Websites </li></ul></ul><ul><ul><ul><li>www.microsoft.com, msdn, Search engine </li></ul></ul></ul><ul><ul><li>Backend for online shopping </li></ul></ul><ul><ul><ul><li>ebay </li></ul></ul></ul>
    18. 18. Who interact with (R)DBMS <ul><ul><li>RDBMS providers implement them. </li></ul></ul><ul><ul><li>Advanced administrators install, maintain and tune-up them. </li></ul></ul><ul><ul><li>A good developer should develop value-added software using them </li></ul></ul><ul><ul><li>End users use software developed by developers </li></ul></ul>
    19. 19. Enters a DMBS Data files Database server (centralized by a third party ) Applications You will work here “ Two-tier system” or “client-server” <ul><li>developer </li></ul><ul><li>administrators </li></ul><ul><li>End users </li></ul>connection (ODBC, JDBC, dbprovider)
    20. 20. The language of RDBMS <ul><li>SQL (Structured query Language) </li></ul><ul><ul><li>Data Definition Language - DDL </li></ul></ul><ul><ul><li>Data Manipulation Language - DML </li></ul></ul><ul><ul><ul><li>query language </li></ul></ul></ul><ul><ul><li>Data Control Language - DCL </li></ul></ul>
    21. 21. SQL <ul><li>SQL is a declarative language, one in which you specify goal what you want and let the language processor engine figure out what steps to take to accomplish the goal. </li></ul><ul><li>In general, SQL statements instruct the relational database engine about the desired end-state condition, but do not have to give step by step instructions to the engine. </li></ul>
    22. 22. Transparent to SQL programmers <ul><li>For example, in handling a SELECT statement, the database engine program may flush buffers, dirty write caches, read sectors from disk, follow linked lists, etc., none of which the programmer has to know. But with most SQL engines, the programmer can add proprietary hints to adjust the way the query is processed. By the way, deletes, updates and inserts are also generically referred to as queries. </li></ul>
    23. 23. How the Programmer Sees the DBMS <ul><li>Start with DDL to create tables : </li></ul><ul><li>Continue with DML to populate tables: </li></ul>CREATE TABLE Students ( Name CHAR(30) NOT NULL, SSN CHAR(9) PRIMARY KEY, Category CHAR(20) ); INSERT INTO Students VALUES(‘Charles’, ‘123456789’, ‘undergraduate’) . . . .
    24. 24. How the Programmer Sees the RDBMS <ul><li>Tables: </li></ul><ul><li>Still implemented as files, but behind the scenes can be quite complex </li></ul>Students: Takes: Courses: “ data independence ” = separate logical view from physical implementation
    25. 25. Queries <ul><li>Find all courses that “Mary” takes </li></ul><ul><li>What happens behind the scene ? </li></ul><ul><ul><li>Query processor figures out how to answer the query efficiently. </li></ul></ul>SELECT C.name FROM Students S, Takes T, Courses C WHERE S.name=“Mary” and S.ssn = T.ssn and T.cid = C.cid
    26. 26. Queries, behind the scene Imperative query execution plan: SELECT C.name FROM Students S, Takes T, Courses C WHERE S.name=“Mary” and S.ssn = T.ssn and T.cid = C.cid Declarative SQL query The optimizer chooses the best execution plan for a query Students Takes sid=sid sname name=“Mary” cid=cid Courses
    27. 27. Transactions <ul><li>Enroll “Mary Johnson” in “CSCI242”: </li></ul>BEGIN TRANSACTION; INSERT INTO Takes SELECT Students.SSN, Courses.CID FROM Students, Courses WHERE Students.name = ‘Mary Johnson’ and Courses.name = ‘CSCI242’ -- More updates here.... IF everything-went-OK THEN COMMIT; ELSE ROLLBACK If system crashes, the transaction is still either committed or aborted
    28. 28. Transactions <ul><li>A transaction = sequence of statements that either all succeed, or all fail </li></ul><ul><li>Transactions have the ACID properties: </li></ul><ul><ul><li>A = atomicity </li></ul></ul><ul><ul><li>C = consistency </li></ul></ul><ul><ul><li>I = isolation </li></ul></ul><ul><ul><li>D = durability </li></ul></ul>
    29. 29. Databases and front-end application and Web application <ul><li>Accessing databases through web interfaces </li></ul><ul><ul><li>Java programming interface (JDBC) </li></ul></ul><ul><ul><li>Embedding into HTML pages (JSP, ASP) </li></ul></ul><ul><ul><li>Access through http protocol (Web Services) </li></ul></ul><ul><ul><li>ASP </li></ul></ul>
    30. 30. PL/SQL Additional proprietary extensions, such as Oracle's PL/SQL and Microsoft's T-SQL, add procedural constructs such as explicit looping, flow control, local variables and so forth the SQL. The idea is that some database maintenance, data cleaning, summary generation, and even business logic functionality can execute inside the database for speed and efficiency. In addition to that, these extensions allow business logics (business rules) to be implemented at server end.
    31. 31. SQL*Plus <ul><li>SQL*Plus is a command line SQL and PL/SQL language interface and reporting tool that ships with the Oracle Database Client and Server. </li></ul><ul><li>It can be used interactively or driven from scripts. SQL*Plus is frequently used by DBAs and Developers to interact with the Oracle database. </li></ul><ul><li>If you are familiar with other databases, sqlplus is equivalent to &quot;sql&quot; in Ingres, &quot;isql&quot; in Sybase and SQLServer, &quot;db2&quot; in IBM DB2, &quot;psql&quot; in PostgresQL, and &quot;mysql&quot; in MySQL. </li></ul>
    32. 32. Oracle SQL*Loader <ul><li>Oracle SQL*Loader is a batch utility for loading data into a target Oracle table. </li></ul><ul><li>The idea is rather simple. </li></ul><ul><li>We won’t use it. </li></ul>
    33. 33. PL/SQL Developer <ul><li>It is an Integrated Development Environment (IDE) for developing stored program units in an Oracle Database. Using PL/SQL Developer you can conveniently create the server-part of your client/server applications. </li></ul>
    34. 34. Forms Developer <ul><li>Form Developer is Oracle's productive Rapid Application Development (RAD) environment for building highly scalable, enterprise-class Internet database applications. It uses powerful declarative features so that business developers can instantly create fully functional applications from database definitions. </li></ul>
    35. 35. SQR <ul><li>A fourth generation language for the creation of reports from databases. SQR is interpreted to dynamically generate SQL queries and format the results. </li></ul><ul><li>Originally a Sybase product, it was then sold to MITI, who subsequently changed their name to SQRIBE. </li></ul><ul><li>SQR Server supports native database access for all major DBMS s and the use of platform independent Java code. </li></ul>
    36. 36. What are behind the scene of RDBMS? <ul><li>Functional components </li></ul><ul><ul><li>SQL language parser and processor </li></ul></ul><ul><ul><li>Query engine </li></ul></ul><ul><ul><li>Query optimizer </li></ul></ul><ul><ul><li>Storage management </li></ul></ul><ul><ul><li>Transaction Management (concurrency, recovery) </li></ul></ul><ul><ul><li>… </li></ul></ul>