Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống
1
/ 242 trang
THÔNG TIN TÀI LIỆU
Thông tin cơ bản
Định dạng
Số trang
242
Dung lượng
1,93 MB
Nội dung
84136 - Week 6 Slide 1 Week 6 - SQL Week 6 - SQL an Introduction an Introduction unit: 84136 by Kathy Egea 84136 - Week 6 Slide 2 Text Text Edmond: Chapter 5,6 Acknowledgments: ideas and some diagrams are based on this texts . 84136 - Week 6 Slide 3 Overview Overview ● What is SQL? What is SQL? ● Database Definition Database Definition ● Creating a database for SQL Creating a database for SQL ● Sets and SQL statements Sets and SQL statements ● Database retrieval: an introduction Database retrieval: an introduction – simple queries simple queries – statistical queries statistical queries – join queries join queries – ‘ ‘ group by’ queries group by’ queries – pattern matching pattern matching 84136 - Week 6 Slide 4 What is SQL? What is SQL? ● SQL = SQL = Structured Query Language Structured Query Language ● Computer language Computer language to query the database to query the database ● Language deals with Language deals with sets of relations sets of relations ● Presents views of the database through Presents views of the database through select, select, project, product and join project, product and join ● Able to update and delete portions of database Able to update and delete portions of database 84136 - Week 6 Slide 5 SQL databases SQL databases Deals with a set of relations known as a Deals with a set of relations known as a relational database relational database Common Terminology attribute column relation row table tuple 84136 - Week 6 Slide 6 SQL databases SQL databases Deals with a set of relations known as a Deals with a set of relations known as a relational database relational database Terminology Standard term SQL term attribute attribute column column relation relation row row table table tuple tuple C o m p l e t e t h e t a b l e 84136 - Week 6 Slide 7 SQL databases SQL databases Deals with a set of relations known as a Deals with a set of relations known as a relational database relational database Terminology Standard term SQL term relation table attribute column tuple row 84136 - Week 6 Slide 8 Id First Last 871 Hans Zupp 862 Bill Board 869 Rip Orff 854 Ann Dover 831 Hans Orff 872 Betty Kahn 868 Will Gambol row row column column A Table A Table 84136 - Week 6 Slide 9 Organisation Organisation An SQL database is a collection of interlocking An SQL database is a collection of interlocking tables. The make-up reflects the following tables. The make-up reflects the following organisation: organisation: ● a set of base tables a set of base tables ● a set of system tables a set of system tables 84136 - Week 6 Slide 10 ● Base tables Base tables are defined in a database are defined in a database using the SQL code CREATE TABLE using the SQL code CREATE TABLE ● These These tables can be altered tables can be altered by adding a by adding a new column (in VIEW mode) or dropping new column (in VIEW mode) or dropping an entire table from the database. an entire table from the database. ● The rows in the tables may be modified The rows in the tables may be modified using SQL functions using SQL functions – INSERT INSERT – UPDATE UPDATE – DELETE DELETE Database Definition Database Definition [...]... Features of a line of SQL code: CREATE TABLE Students ( Id INTEGER NOT NULL, First CHAR (6) NOT NULL, Last CHAR (10) NOT NULL ) ; ( ) Slide 20 brackets start and finish of table 84136 - Week 6 Features of a line of SQL code: CREATE TABLE Students ( Id INTEGER NOT NULL, First CHAR (6) NOT NULL, Last CHAR (10) NOT NULL ) ; ( ) ; Slide 21 brackets semi-colon start and finish of table end of a SQL statement 84136... of table end of a SQL statement 84136 - Week 6 Features of a line of SQL code: CREATE TABLE Students ( Id INTEGER NOT NULL, First CHAR (6) NOT NULL, Last CHAR (10) NOT NULL ) ; ( ) ; , Slide 22 brackets semi-colon comma start and finish of table end of a SQL statement end of a column definition 84136 - Week 6 Features of a line of SQL code: CREATE TABLE Students ( Id INTEGER NOT NULL, First CHAR (6)... semi-colon comma hyphen start and finish of table end of a SQL statement end of a column definition line connecter 84136 - Week 6 Features of a line of SQL code: CREATE TABLE Students ( Id INTEGER NOT NULL, First CHAR (6) NOT NULL, Last CHAR (10) NOT NULL ) ; This presentation style is suitable an external text file This file is then read in ISQL Slide 24 84136 - Week 6 Database Definition CREATE TABLE... INSERT INTO Results(Item, Id, Mark) VALUES (3,871,60) ; INSERT INTO Results(Item, Id, Mark) VALUES (3,854,65) ; Slide 13 84136 - Week 6 Database Definition q Base tables are created in a database using the SQL code CREATE TABLE An example Slide 14 CREATE TABLE Students ( Id INTEGER NOT NULL, First CHAR (6) NOT NULL, Last CHAR (10) NOT NULL ) ; 84136 - Week 6 CREATE TABLE Students ( Id INTEGER NOT NULL, First... 84136 - Week 6 Inserting Data INSERTINTO Students (Id,First,Last) VALUES (854,’Ann’,’Dover’); or INSERTINTO Students VALUES (854,’Ann’,’Dover’); Slide 34 It is not necessary to include column names in SQL statement 84136 - Week 6 Inserting values into StudentsTable INSERT INTO Students (Id,First,Last) VALUES (854,’Ann’,’Dover’); Students Id First 854 Slide 35 Ann Last Dover 84136 - Week 6 Creating Assess . 3 Overview Overview ● What is SQL? What is SQL? ● Database Definition Database Definition ● Creating a database for SQL Creating a database for SQL ● Sets and SQL statements Sets and SQL statements ● Database. queries group by’ queries – pattern matching pattern matching 84136 - Week 6 Slide 4 What is SQL? What is SQL? ● SQL = SQL = Structured Query Language Structured Query Language ● Computer language Computer. 6 Slide 6 SQL databases SQL databases Deals with a set of relations known as a Deals with a set of relations known as a relational database relational database Terminology Standard term SQL term