Presentation is loading. Please wait.

Presentation is loading. Please wait.

Database systems Lecture 3 – SQL + CRUD

Similar presentations


Presentation on theme: "Database systems Lecture 3 – SQL + CRUD"— Presentation transcript:

1 Database systems Lecture 3 – SQL + CRUD
Roman Danel 2016

2 SQL SQL = Structure Query Language Declarative language

3 Groups of SQL statements
DDL – Data Definition Language commands for creating, modifying or deleting database objects DML – Data Manipulation Language commands for database objects creation, alter or remove DIL – Data Integrity Language DCL – Data Control Language

4 DDL commands CREATE – create object (table, view, …)
DROP – remove object ALTER – modify object GRANT – add/remove/change user access right

5 DML commands SELECT – read data (records) UPDATE – modify data
INSERT – store new data DELETE – remove data = so called CRUD (create read update delete data)

6 SELECT SELECT * from Customers; SELECT list_of_columns FROM tabulka;
Display all columns and records from table Customers: SELECT * from Customers; Display selected columns from table Customers: SELECT list_of_columns FROM tabulka; Display selected columns from table Customers with condition SELECT Company, Country FROM Customers WHERE Country <> 'USA' ;

7 DML commands – syntax overview
SELECT [ DISTINCT ] * | LIST OF COLUMNS, FUNCTIONS, CONSTANTS    FROM LIST OF TABLES OR VIEWS    [ WHERE CONDITION(S) ]    [ ORDER BY ORDERING COLUMN(S) [ ASC | DESC ] ]    [ GROUP BY GROUPING COLUMN(S) ]    [ HAVING CONDITION(S) ] DELETE FROM TABLE NAME    [ WHERE CONDITION(S) ] INSERT INTO TABLE NAME    [ (COLUMN LIST) ]    VALUES (VALUE LIST) UPDATE TABLE NAME    SET COLUMN NAME = VALUE    [ WHERE CONDITION ]

8 SQL NULL – empty value Set operation
Usage in queries: „IS NULL“, „IS NOT NULL“ Set operation

9 Aggregate functions SUM Total of the values in a field.
AVG Average of the values in a field. MIN Lowest value in a field. MAX Highest value in a field. COUNT Number of values in a field, not counting Null (blank) values

10 Predicates BETWEEN ... AND Compares a value to a range formed by two values. IN Determines whether a value exists in a list of values or a table. LIKE Compares, in part or in whole, one value with another. JOIN Joins two tables EXISTS

11 Tables join WHERE JOIN

12 Inner join Inner join returns only records where exist record in the second table Right/Left Outer join returns all rows from (right) or (left) Example of inner join: SELECT column_name(s) FROM table_name1 INNER JOIN table_name2 ON table_name1.column_name=table_name2.column_name

13 SQL – versions (ISO norms)
SQL-92 – standard SQL:1999 SQL:2003 (SQL3) SQL:2008 Fetch first, Persistent Stored Modules,…

14 SQL-92 SQL Agent New data types defined: DATE, TIME, TIMESTAMP, INTERVAL, BIT string, VARCHAR strings, and NATIONAL CHARACTER strings. Support for additional character sets beyond the base requirement for representing SQL statements. New scalar operations such as string concatenation, date and time mathematics, and conditional statements. New set operations such as UNION JOIN, NATURAL JOIN, set differences, and set intersections. Support for alterations of schema definitions via ALTER and DROP. New integrity-checking functionality such as within a CHECK constraint Dynamic execution of queries (as opposed to prepared). Better support for remote database access. Temporary tables. Transaction isolation levels New operations for changing data types on the fly via CAST. Scrolling cursors. Compatibility flagging for backwards and forwards compatibility with other SQL standards.

15 SQL tutorials http://www.w3schools.com/sql/default.asp

16 SQL objects View Triggers Collation – for sorting the string values
Indexes Stored procedures Fuctions Events


Download ppt "Database systems Lecture 3 – SQL + CRUD"

Similar presentations


Ads by Google