DAT702. Standard Query Language Ability to access and manipulate databases ◦ Retrieve data ◦...
-
Upload
ross-eaton -
Category
Documents
-
view
212 -
download
0
Transcript of DAT702. Standard Query Language Ability to access and manipulate databases ◦ Retrieve data ◦...
![Page 1: DAT702. Standard Query Language Ability to access and manipulate databases ◦ Retrieve data ◦ Insert, delete, update records ◦ Create and set permissions.](https://reader036.fdocuments.in/reader036/viewer/2022072010/56649da95503460f94a968d5/html5/thumbnails/1.jpg)
INTRODUCTION TO SQLDAT702
![Page 2: DAT702. Standard Query Language Ability to access and manipulate databases ◦ Retrieve data ◦ Insert, delete, update records ◦ Create and set permissions.](https://reader036.fdocuments.in/reader036/viewer/2022072010/56649da95503460f94a968d5/html5/thumbnails/2.jpg)
Standard Query Language Ability to access and manipulate databases
◦ Retrieve data◦ Insert, delete, update records◦ Create and set permissions
databases, tables, procedures and views◦ Query databases
WHAT IS SQL
![Page 3: DAT702. Standard Query Language Ability to access and manipulate databases ◦ Retrieve data ◦ Insert, delete, update records ◦ Create and set permissions.](https://reader036.fdocuments.in/reader036/viewer/2022072010/56649da95503460f94a968d5/html5/thumbnails/3.jpg)
ULI101◦ HTML◦ Create a webpage
INT213◦ ASP◦ Connect to database to make webpage functional
DAT702 ◦ SQL◦ Manipulate data in database connected to
webpage
BUILDS ON PREVIOUS COURSES
![Page 4: DAT702. Standard Query Language Ability to access and manipulate databases ◦ Retrieve data ◦ Insert, delete, update records ◦ Create and set permissions.](https://reader036.fdocuments.in/reader036/viewer/2022072010/56649da95503460f94a968d5/html5/thumbnails/4.jpg)
Relational Database Management System◦ SQL, MS Access, Oracle, IBM DB2, SQL Server
Data is stored in database objects called tables
A table is a collection of related data organized into columns (fields) and rows (records)
RDBMS
![Page 5: DAT702. Standard Query Language Ability to access and manipulate databases ◦ Retrieve data ◦ Insert, delete, update records ◦ Create and set permissions.](https://reader036.fdocuments.in/reader036/viewer/2022072010/56649da95503460f94a968d5/html5/thumbnails/5.jpg)
Defined by SQL Many are mandatory, but most are optional
SELECT name FROM teams WHERE id = 9
SELECT and FROM are mandatory WHERE is optional
KEYWORDS
![Page 6: DAT702. Standard Query Language Ability to access and manipulate databases ◦ Retrieve data ◦ Insert, delete, update records ◦ Create and set permissions.](https://reader036.fdocuments.in/reader036/viewer/2022072010/56649da95503460f94a968d5/html5/thumbnails/6.jpg)
Names that are given to database objects such as tables and columns
“teams” is the table name “name” and “id” are column names
IDENTIFIERS
SELECT name FROM teams WHERE id = 9
![Page 7: DAT702. Standard Query Language Ability to access and manipulate databases ◦ Retrieve data ◦ Insert, delete, update records ◦ Create and set permissions.](https://reader036.fdocuments.in/reader036/viewer/2022072010/56649da95503460f94a968d5/html5/thumbnails/7.jpg)
Literals that represent fixed values
“9” is a numeric constant
CONSTANTS
SELECT name FROM teams WHERE id = 9
![Page 8: DAT702. Standard Query Language Ability to access and manipulate databases ◦ Retrieve data ◦ Insert, delete, update records ◦ Create and set permissions.](https://reader036.fdocuments.in/reader036/viewer/2022072010/56649da95503460f94a968d5/html5/thumbnails/8.jpg)
A portion of an SQL statement
The SELECT clause is “SELECT from” The FROM clause is “FROM teams” The WHERE clause is “WHERE id = 9”
CLAUSES
![Page 9: DAT702. Standard Query Language Ability to access and manipulate databases ◦ Retrieve data ◦ Insert, delete, update records ◦ Create and set permissions.](https://reader036.fdocuments.in/reader036/viewer/2022072010/56649da95503460f94a968d5/html5/thumbnails/9.jpg)
How the clause is put together
What keywords, identifiers and constants does it consist of
MOST IMPORTANTLY – are they in the correct order according to SQL
SYNTAX
![Page 10: DAT702. Standard Query Language Ability to access and manipulate databases ◦ Retrieve data ◦ Insert, delete, update records ◦ Create and set permissions.](https://reader036.fdocuments.in/reader036/viewer/2022072010/56649da95503460f94a968d5/html5/thumbnails/10.jpg)
Used to manage database objects such as tables and columns
CREATE, ALTER and DROP
mysql> create table teams (id int(5) not null primary key, name varchar(37) not null, division varchar(2)); Query OK, 0 rows affected (0.05 sec)
DDL COMMANDS
![Page 11: DAT702. Standard Query Language Ability to access and manipulate databases ◦ Retrieve data ◦ Insert, delete, update records ◦ Create and set permissions.](https://reader036.fdocuments.in/reader036/viewer/2022072010/56649da95503460f94a968d5/html5/thumbnails/11.jpg)
mysql> create table teams (id int(5) not null primary key, name varchar(37) not null, division varchar(2)); Query OK, 0 rows affected (0.05 sec)
CREATE
+------------+-------------+-----+------+---------+-------+ | Field | Type | Null | Key | Default | Extra |+------------+-------------+-----+------+---------+-------+ | id | int(5) | NO | PRI | NULL | | | name | varchar(37) | NO | | NULL | | | division | varchar(3) | YES | | NULL | |+------------+-------------+-----+------+---------+-------+3 rows in set (0.00 sec)
![Page 12: DAT702. Standard Query Language Ability to access and manipulate databases ◦ Retrieve data ◦ Insert, delete, update records ◦ Create and set permissions.](https://reader036.fdocuments.in/reader036/viewer/2022072010/56649da95503460f94a968d5/html5/thumbnails/12.jpg)
mysql> ALTER TABLE teams DROP COLUMN division;
Query OK, 0 rows affected (0.15 sec)Records: 0 Duplicates: 0 Warnings: 0
Check to make sure the column no longer exists
ALTER
![Page 13: DAT702. Standard Query Language Ability to access and manipulate databases ◦ Retrieve data ◦ Insert, delete, update records ◦ Create and set permissions.](https://reader036.fdocuments.in/reader036/viewer/2022072010/56649da95503460f94a968d5/html5/thumbnails/13.jpg)
mysql> DROP TABLE teams;Query OK, 0 rows affected (0.03 sec)
Check to make surethe table no longer exists
DROP
![Page 14: DAT702. Standard Query Language Ability to access and manipulate databases ◦ Retrieve data ◦ Insert, delete, update records ◦ Create and set permissions.](https://reader036.fdocuments.in/reader036/viewer/2022072010/56649da95503460f94a968d5/html5/thumbnails/14.jpg)
Used to manage data within tables and columns
INSERT, UPDATE and DELETE
(RE-CREATE THE TEAMS TABLE)
DML COMMANDS
![Page 15: DAT702. Standard Query Language Ability to access and manipulate databases ◦ Retrieve data ◦ Insert, delete, update records ◦ Create and set permissions.](https://reader036.fdocuments.in/reader036/viewer/2022072010/56649da95503460f94a968d5/html5/thumbnails/15.jpg)
mysql> insert into teams values (‘12345', ‘Toronto', ‘NE');
Query OK, 1 row affected (0.02 sec)
INSERT
![Page 16: DAT702. Standard Query Language Ability to access and manipulate databases ◦ Retrieve data ◦ Insert, delete, update records ◦ Create and set permissions.](https://reader036.fdocuments.in/reader036/viewer/2022072010/56649da95503460f94a968d5/html5/thumbnails/16.jpg)
UPDATE teams SET name = ‘TO‘ WHERE name = ‘Toronto';
Query OK, 1 row affected (0.02 sec)
UPDATE
![Page 17: DAT702. Standard Query Language Ability to access and manipulate databases ◦ Retrieve data ◦ Insert, delete, update records ◦ Create and set permissions.](https://reader036.fdocuments.in/reader036/viewer/2022072010/56649da95503460f94a968d5/html5/thumbnails/17.jpg)
DELETE FROM teams WHERE name = ‘TO';
Query OK, 1 row affected (0.02 sec)
DELETE
![Page 18: DAT702. Standard Query Language Ability to access and manipulate databases ◦ Retrieve data ◦ Insert, delete, update records ◦ Create and set permissions.](https://reader036.fdocuments.in/reader036/viewer/2022072010/56649da95503460f94a968d5/html5/thumbnails/18.jpg)
load data local infile 'test.txt' into table TEAMS lines terminated by '\r\n';
INSERT DATA FROM TEXT FILE