Базы данных, осень 2016: Краткое введение в базы данных и SQL программирование

Embed Size (px)

Text of Базы данных, осень 2016: Краткое введение в базы данных и...

  • SQL

    13 2016 .

    Computer Science Center

  • Creative CommonsAttribution - Share Alike 3.0

    http://creativecommons.org/licenses/by-sa/3.0/us/deed.ru

    LATEX

    P

    a

    peeriapapeeria.com

    http://creativecommons.org/licenses/by-sa/3.0/us/deed.ruhttp://papeeria.com

  • SQL

    3/25

  • -

    4/25

  • :plaintext/json/XML/CSV , ,

    , : /

    : , -

    : ,

    5/25

  • ,

    6/25

  • : ( )

    ,

    7/25

  • ,

    8/25

  • 9/25

  • -

    10/25

  • : MySQL, PostgreSQL, SQLite : Oracle, IBM DB2, Microsoft SQLServer

    PostgreSQL

    https://en.wikipedia.org/wiki/Comparison_of_relational_database_management_systems

    11/25

    https://en.wikipedia.org/wiki/Comparison_of_relational_database_management_systemshttps://en.wikipedia.org/wiki/Comparison_of_relational_database_management_systems

  • sudo apt-get install postgresql Windows :https://hub.docker.com/_/postgres/

    12/25

    https://hub.docker.com/_/postgres/

  • PostgreSQL

    13/25

  • SQL

    14/25

  • , (SQL-2011 )

    SQL , - . , boolean

    15/25

  • SQL

    16/25

  • : INTEGER, BIGINT, SMALLINT :NUMERIC, DECIMAL

    : FLOAT,REAL, DOUBLE PRECISION

    : CHARACTER, CHARACTER VARYING,CLOB

    : DATE, TIME, TIMESTAMP : BOOLEAN

    17/25

  • .

    CREATE TABLE table_name ();

    column_list := [, ...]

    column_def :=column_name []

    data_type := INTEGER | BIGINT | FLOAT | ...

    DROP TABLE table_name;

    https://www.postgresql.org/docs/current/static/sql-createtable.html 18/25

    https://www.postgresql.org/docs/current/static/sql-createtable.htmlhttps://www.postgresql.org/docs/current/static/sql-createtable.html

  • 1 CREATE TABLE Foo();2 CREATE TABLE FooBar(INTEGER);3 CREATE TABLE Baz(id INTEGER, value FLOAT,);

    19/25

  • 20/25

  • 1 INSERT INTO Foo(id, value) VALUES (1, 100);2 INSERT INTO Foo(value, id) VALUES (200, 2), (300, 3);

    21/25

  • SQL-:SELECT-FROM-WHERE

    1 SELECT * FROM Foo WHERE id=1;2 SELECT id FROM Foo WHERE value

  • , -

    1 CREATE TABLE Student(id INT, name TEXT, age INT);2 INSERT INTO Student(id, name, age)3 VALUES (1, Bob, 21), (2, Alice, NULL);4 SELECT * FROM Student WHERE age21;5

    23/25

  • 1 SELECT NULL=1;2 SELECT NULL!=1;3 SELECT NULL=NULL;4 SELECT NULL != NULL;

    24/25

  • 1 SELECT NULL IS NULL;

    25/25

    SQL