0
SQL <ul><li>This presentation will cover: </li></ul><ul><ul><li>A Brief History of DBMS  </li></ul></ul><ul><ul><li>View i...
SQL – DBMS History <ul><li>DBMS History </li></ul><ul><ul><li>The IBM’s System/R was not the first DBMS. The first to mark...
SQL - Standards <ul><li>SQL is a open language without corporate ownership. </li></ul><ul><li>The ANSI-SQL (American Natio...
SQL – Enhanced features <ul><li>Every DBMS vendor wants their products to be different. So most products offers extra feat...
What is a View? <ul><li>In SQL, a VIEW is a virtual relation based on the result-set of a SELECT statement. </li></ul><ul>...
SQL – Relations, Tables & Views <ul><li>When we say Relation, it could be a Table or a View. There are three kind of relat...
SQL – Create View <ul><li>Example: Create a view with title and year and made by Paramount studio. </li></ul><ul><ul><li>M...
SQL – Querying View <ul><li>A view could be used from inside a query, a stored procedure, or from inside another view. By ...
SQL - Querying View con’t <ul><li>Query involving both view and table </li></ul><ul><ul><li>SELECT   DISTINCT  starName </...
SQL - Querying View example <ul><li>Movie (title, year, length, inColor, studioName, producerC#) </li></ul><ul><li>MovieEx...
SQL - Renaming Attributes in View <ul><li>Sometime, we might want to distinguish attributes by giving the different name. ...
SQL - Modifying View <ul><li>When we modify a view, we actually modify a table through a view. Many views are not updateab...
SQL – Modifying View (INSERT) <ul><ul><li>INSERT INTO  ParamountMovie </li></ul></ul><ul><ul><li>VALUES  (‘Star Trek’, 197...
SQL - Modifying View (DELETE) <ul><li>Suppose we wish to delete all movies with “Trek” in their title from the updateable ...
SQL - Modifying View (UPDATE) <ul><li>UPDATE from an updateable view </li></ul><ul><ul><li>UPDATE  ParamountMovie </li></u...
SQL – View (DROP) <ul><li>DROP view: All views can be dropped, whether or not the view is updateable. </li></ul><ul><ul><l...
SQL - D ownload  MySQL <ul><li>Go to  http://dev.mysql.com/downloads/  and download: </li></ul><ul><li>MySQL (Windows User...
SQL – Install MySQL <ul><li>During the installation – </li></ul><ul><ul><li>you can <“Skip Sing-Up”> to fast installation ...
SQL - MySQL Administrator <ul><li>MySQL Administrator come with MySQL System Tray Monitor allow you to configure your serv...
SQL -  MySQL Query Browser <ul><li>Run MySQL Query Browser </li></ul><ul><ul><li>Give a name for the Default Schema </li><...
SQL - Bibliography <ul><li>First Course In Database Systems,  Jeffery D. Ullman and Jennifer Widom,1997 Prentice Hall, Inc...
Upcoming SlideShare
Loading in...5
×

SQL

293

Published on

0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
293
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
5
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Transcript of "SQL"

  1. 1. SQL <ul><li>This presentation will cover: </li></ul><ul><ul><li>A Brief History of DBMS </li></ul></ul><ul><ul><li>View in database </li></ul></ul><ul><ul><li>MySQL installation </li></ul></ul>
  2. 2. SQL – DBMS History <ul><li>DBMS History </li></ul><ul><ul><li>The IBM’s System/R was not the first DBMS. The first to market was Relational Software's product named Oracle </li></ul></ul><ul><ul><li>The second was Relational Technology's Ingres. </li></ul></ul><ul><ul><li>IBM then released improved products in 1982 named SQL/DS and DB2. Oracle and DB2 in nth generation forms while the Ingres technology was bought by Computer Associates. </li></ul></ul>
  3. 3. SQL - Standards <ul><li>SQL is a open language without corporate ownership. </li></ul><ul><li>The ANSI-SQL (American National Standards Institute) group has published three standards over the years: </li></ul><ul><ul><li>SQL89 (SQL1) </li></ul></ul><ul><ul><li>SQL92 (SQL2) </li></ul></ul><ul><ul><li>SQL99 (SQL3) </li></ul></ul><ul><li>The majority of the language has not changed through these updates. </li></ul><ul><li>The SQL standard from ANSI is considered the &quot;pure&quot; SQL and called ANSI-SQL. </li></ul>
  4. 4. SQL – Enhanced features <ul><li>Every DBMS vendor wants their products to be different. So most products offers extra features, these additions are generally not compatible with competitor's SQL products. </li></ul><ul><li>It is always safest to stick with pure SQL </li></ul><ul><li>The enhancements are not all bad because these extensions are very useful. </li></ul><ul><ul><li>For example, most DBMS sold today have an automatic way to assign a serial number feature since serial numbering is so common. However, the method of implementation is not uniform. </li></ul></ul>
  5. 5. What is a View? <ul><li>In SQL, a VIEW is a virtual relation based on the result-set of a SELECT statement. </li></ul><ul><li>A view contains rows and columns, just like a real table. The fields in a view are fields from one or more real tables in the database. In some cases, we can modify a view and present the data as if the data were coming from a single table. </li></ul><ul><li>Syntax : </li></ul><ul><ul><ul><li>CREATE VIEW view_name AS </li></ul></ul></ul><ul><ul><ul><li>SELECT column_name(s) </li></ul></ul></ul><ul><ul><ul><li>FROM table_name </li></ul></ul></ul><ul><ul><ul><li>WHERE condition </li></ul></ul></ul>
  6. 6. SQL – Relations, Tables & Views <ul><li>When we say Relation, it could be a Table or a View. There are three kind of relations: </li></ul><ul><li>Stored relations tables </li></ul><ul><ul><li>We sometimes use the term “base relation” or “base table” </li></ul></ul><ul><li>Virtual relations views </li></ul><ul><li>Temporary results </li></ul>
  7. 7. SQL – Create View <ul><li>Example: Create a view with title and year and made by Paramount studio. </li></ul><ul><ul><li>Movie (title, year, length, inColor, studioName, producerC#) </li></ul></ul><ul><ul><li>CREATE VIEW ParamountMovie AS </li></ul></ul><ul><ul><li>SELECT title,year </li></ul></ul><ul><ul><li>FROM Movie </li></ul></ul><ul><ul><li>WHERE studioName = ‘Paramount’; </li></ul></ul>
  8. 8. SQL – Querying View <ul><li>A view could be used from inside a query, a stored procedure, or from inside another view. By adding functions, joins, etc., to a view, it allows us to present exactly the data we want to the user. </li></ul><ul><ul><ul><li>SELECT title </li></ul></ul></ul><ul><ul><ul><li>FROM ParamountMovie </li></ul></ul></ul><ul><ul><ul><li>WHERE year = ‘1979’; </li></ul></ul></ul><ul><li>Have same result as </li></ul><ul><ul><ul><li>SELECT title </li></ul></ul></ul><ul><ul><ul><li>FROM Movie </li></ul></ul></ul><ul><ul><ul><li>WHERE studioName = ‘Paramount’ AND year = ‘1979’; </li></ul></ul></ul>View Table
  9. 9. SQL - Querying View con’t <ul><li>Query involving both view and table </li></ul><ul><ul><li>SELECT DISTINCT starName </li></ul></ul><ul><ul><li>FROM ParamountMovie, StarsIn </li></ul></ul><ul><ul><li>WHERE title = movieTitle AND year = movieYear; </li></ul></ul>Table View
  10. 10. SQL - Querying View example <ul><li>Movie (title, year, length, inColor, studioName, producerC#) </li></ul><ul><li>MovieExec (name, address, cert#, netWorth) </li></ul><ul><ul><li>CREATE VIEW MovieProd AS </li></ul></ul><ul><ul><ul><li>SELECT title, name </li></ul></ul></ul><ul><ul><ul><li>FROM Movie, MovieExec </li></ul></ul></ul><ul><ul><ul><li>WHERE producerC# = cert#; </li></ul></ul></ul><ul><ul><li>SELECT name </li></ul></ul><ul><ul><li>FROM MovieProd </li></ul></ul><ul><ul><li>WHERE title = ‘Gone With the Wind’; </li></ul></ul><ul><li>Same result as query from tables </li></ul><ul><ul><li>SELECT name </li></ul></ul><ul><ul><li>FROM Movie, MovieExec </li></ul></ul><ul><ul><li>WHERE producerC# = cert# AND title = ‘The War Of the World’; </li></ul></ul>
  11. 11. SQL - Renaming Attributes in View <ul><li>Sometime, we might want to distinguish attributes by giving the different name. </li></ul><ul><li>CREATE VIEW MovieProd (movieTitle, prodName) AS </li></ul><ul><ul><li>SELECT title, name </li></ul></ul><ul><ul><li>FROM Movie, MovieExec </li></ul></ul><ul><ul><li>WHERE producerC# = cert#; </li></ul></ul>
  12. 12. SQL - Modifying View <ul><li>When we modify a view, we actually modify a table through a view. Many views are not updateable. Here are rules have been defined in SQL for updateable views: </li></ul><ul><li>selecting ( SELECT not SELECT DISTINCT ) some attributes from one relation R (which may itself be an updateable view) </li></ul><ul><ul><li>The WHERE clause must not involve R in a subquery. </li></ul></ul><ul><ul><li>The list in the SELECT clause must include enough attributes that will allow us to insert tuples into the view as well as table. All other attributes will be filled out with NULL or the proper default values. </li></ul></ul>
  13. 13. SQL – Modifying View (INSERT) <ul><ul><li>INSERT INTO ParamountMovie </li></ul></ul><ul><ul><li>VALUES (‘Star Trek’, 1979); </li></ul></ul><ul><ul><li>To make the view ParamountMovie updateable, we need to add attribute studioName to it’s SELECT clause because it makes more sense if the studioName is Paramount instead of NULL. </li></ul></ul><ul><ul><li>CREATE VIEW ParamountMovie AS </li></ul></ul><ul><ul><ul><li>SELECT studioName, title, year </li></ul></ul></ul><ul><ul><ul><li>FROM Movie </li></ul></ul></ul><ul><ul><ul><li>WHERE studioName = ‘Paramount’; </li></ul></ul></ul><ul><li>Then </li></ul><ul><ul><ul><li>INSERT INTO ParamountMovie </li></ul></ul></ul><ul><ul><ul><li>VALUES (‘Paramount’, ‘Star Trek’, 1979); </li></ul></ul></ul><ul><ul><ul><li>Title year length inColor studioName producerC# </li></ul></ul></ul><ul><ul><ul><li>‘ Star Trek’ 1979 0 NULL ‘Paramount’ NULL </li></ul></ul></ul>
  14. 14. SQL - Modifying View (DELETE) <ul><li>Suppose we wish to delete all movies with “Trek” in their title from the updateable view ParamountMovie. </li></ul><ul><ul><li>DELETE FROM ParamountMovie </li></ul></ul><ul><ul><li>WHERE title LIKE ‘%Trek%’; </li></ul></ul><ul><li>It is turned into the base table delete </li></ul><ul><ul><li>DELETE FROM Movie </li></ul></ul><ul><ul><li>WHERE title LIKE ‘%Trek%’ AND studioName = ‘Paramount’; </li></ul></ul>
  15. 15. SQL - Modifying View (UPDATE) <ul><li>UPDATE from an updateable view </li></ul><ul><ul><li>UPDATE ParamountMovie </li></ul></ul><ul><ul><li>SET year = 1979 </li></ul></ul><ul><ul><li>WHERE title = ‘Star Trek the Movie’; </li></ul></ul><ul><li>It is turned into the base table update </li></ul><ul><ul><li>UPDATE Movie </li></ul></ul><ul><ul><li>SET year = 1979 </li></ul></ul><ul><ul><li>WHERE title = ‘Star Trek the Movie’ AND studioName = ‘Paramount’; </li></ul></ul>
  16. 16. SQL – View (DROP) <ul><li>DROP view: All views can be dropped, whether or not the view is updateable. </li></ul><ul><ul><li>DROP VIEW ParamountMovie; </li></ul></ul><ul><li>DROP VIEW does not affect any tuples of the underlying relation (table) Movie. </li></ul><ul><li>However, DROP TABLE will delete the table and also make the view ParamountMovie unusable. </li></ul><ul><ul><li>DROP TABLE Movie </li></ul></ul>
  17. 17. SQL - D ownload MySQL <ul><li>Go to http://dev.mysql.com/downloads/ and download: </li></ul><ul><li>MySQL (Windows User / version 4.1.10a, 5.0.2-alpha has bug that keep shutting down the service) </li></ul><ul><li>MySQL Administrator </li></ul><ul><li>MySQL Query Browser </li></ul>
  18. 18. SQL – Install MySQL <ul><li>During the installation – </li></ul><ul><ul><li>you can <“Skip Sing-Up”> to fast installation </li></ul></ul><ul><ul><li>Will run Configuration Wizard right after installation automatically </li></ul></ul><ul><ul><li>If the service won’t start, press <cancel>, then run Configuration Wizard manually again </li></ul></ul><ul><li>Run MySQL Server Instance Config Wizard from windows menu – </li></ul><ul><ul><li>use default setting unless you know what you are doing </li></ul></ul><ul><ul><li>Modify Security Setting (option: you can start service without doing this) </li></ul></ul><ul><ul><li>Execute </li></ul></ul><ul><ul><ul><li>If there is an error, try press <back> to go back, then press <next> to <execute> again </li></ul></ul></ul><ul><ul><li>TCP / IP Networking – </li></ul></ul><ul><ul><ul><li>Try different port number if you are using networking. </li></ul></ul></ul>
  19. 19. SQL - MySQL Administrator <ul><li>MySQL Administrator come with MySQL System Tray Monitor allow you to configure your server </li></ul><ul><li>Run MySQL Administrator – </li></ul><ul><ul><li>For the first time, you may not have “Stored connection,” you can <Add new Connection> and give the Connection name. </li></ul></ul><ul><ul><li>Server Host: type “localhost” If you don’t use networking </li></ul></ul>
  20. 20. SQL - MySQL Query Browser <ul><li>Run MySQL Query Browser </li></ul><ul><ul><li>Give a name for the Default Schema </li></ul></ul><ul><ul><ul><li>Schema means Database instance </li></ul></ul></ul><ul><ul><li>You can type command line into the top box or right Click on schemata to create new table </li></ul></ul>
  21. 21. SQL - Bibliography <ul><li>First Course In Database Systems, Jeffery D. Ullman and Jennifer Widom,1997 Prentice Hall, Inc. </li></ul><ul><li>http://mysql.com </li></ul>
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×