Presentation is loading. Please wait.

Presentation is loading. Please wait.

5.3. Querying a Database SQL -> DDL, DML. SQL Structured Query Language – industry standard supported by all significant relational databases. First SQL.

Similar presentations


Presentation on theme: "5.3. Querying a Database SQL -> DDL, DML. SQL Structured Query Language – industry standard supported by all significant relational databases. First SQL."— Presentation transcript:

1 5.3. Querying a Database SQL -> DDL, DML

2 SQL Structured Query Language – industry standard supported by all significant relational databases. First SQL version developed at IBM by Chamberlin and Boyce in early 1970s Declarative language concerned with ‘what’ rather than ‘how’. Mainly used to query a database but also used to create tables

3 DML Data Manipulation Language Part of SQL concerned with asking questions of a database Eg. SELECT.. FROM.. DDL Data Definition Language A language to define the structure and instances of a database E.g. CREATE TABLE employee (EmpID INT, NameVARCHAR (10), HiredDate DATE, Salary CURRENCY);

4 Data Manipulation Language (DML) Exercises are based on the Orders database in chapter 5.3. Make a copy of the database in your N drive.

5 tblsoftware Licence no Customer id Packageversionprice Service agreement Date of purchase 1000RentAPayroll4.0£550.00Yes18/02/1999 1123SeymourAccounts6.1£475.00No01/07/1999 2111RentAStock2.0£700.00Yes13/07/1999 3456SeymourStock2.0£770.00Yes06/11/1999 4870RedcabsPayroll5.0£620.00Yes05/12/1999 5268Supagstock6.2£900.00No14/02/2000 5381RedcabsAccounts6.2£520.00Yes14/02/2000 6001PradeshPayroll5.0£620.00Yes 7114RentaAccounts6.2£500.00Yes17/03/2000 Customers Customer IDCompany NameContact Last NamePhone Number Pradeshpradesh&Co LtdKarl Pradesh(0176) 3396018 RedcabsRedcabs ltdFred Gordon(0181) 8799655 RentaRent-A-ToolMark Wong(0147) 3212777 SeymourSeymour GlassJames Bolan(0135) 4543666 SupagSupa-goodMavis Hunt(0120) 2888557

6 SELECT.. FROM.. WHERE SELECT field1, field2 FROM tablename; SELECT DISTINCT FROM tablename; SELECT Package,version FROM tblsoftware WHERE Package='Payroll';

7 GROUP BY.. SELECT SUM(price) AS SumOfPrice FROM tblSoftware WHERE CustomerID = “REDCABS”;

8 Extract data from more than one table SELECT tblname1.fieldname, tblname2.field2 FROM tblname1, tblname2 WHERE tblname1.field1 = tblname2.field1;

9 DATA DEFINITION LANGUAGE Defines the logical structure and files within the database. Example: CREATE TABLE staff (StaffId INT NOT NULL, StaffName VARCHAR(10), Dept VARCHAR(5), PRIMARY KEY (StaffID), FOREIGN KEY (Dept) REFERENCES Department(DeptId));

10 CREATE DATABASE studentsDB; ALTER TABLE tblSoftware ADD StaffId INT; CREATE INDEX NamePackage ON tblSoftware(Package);

11 GRANT all PRIVILEGES ON studentsDB.* TO ‘username’@’172.16.%.%’ IDENTIFIED BY ‘password’;

12 Exercise Resources To practice SQL queries http://sqlzoo.net/


Download ppt "5.3. Querying a Database SQL -> DDL, DML. SQL Structured Query Language – industry standard supported by all significant relational databases. First SQL."

Similar presentations


Ads by Google