Introduction to SQL on GRAHAM ED ARMSTRONG SHARCNET AUGUST 2018

Similar documents
Lab # 2 Hands-On. DDL Basic SQL Statements Institute of Computer Science, University of Tartu, Estonia

Data Types in MySQL CSCU9Q5. MySQL. Data Types. Consequences of Data Types. Common Data Types. Storage size Character String Date and Time.

The M in LAMP: MySQL CSCI 470: Web Science Keith Vertanen Copyright 2014

Chapter 8 How to work with data types

TINYINT[(M)] [UNSIGNED] [ZEROFILL] A very small integer. The signed range is -128 to 127. The unsigned range is 0 to 255.

Programming and Database Fundamentals for Data Scientists

Basis Data Terapan. Yoannita

More MySQL ELEVEN Walkthrough examples Walkthrough 1: Bulk loading SESSION

Overview of MySQL Structure and Syntax [2]

Basic SQL. Basic SQL. Basic SQL

SQL: Data Definition Language

SQL Data Definition Language: Create and Change the Database Ray Lockwood

MySQL: an application

SQL. Often times, in order for us to build the most functional website we can, we depend on a database to store information.

Information Systems Engineering. SQL Structured Query Language DDL Data Definition (sub)language

Data Definition Language with mysql. By Kautsar

Data and Tables. Bok, Jong Soon

Acknowledgments About the Authors

SQL Data Definition and Data Manipulation Languages (DDL and DML)

1 INTRODUCTION TO EASIK 2 TABLE OF CONTENTS

Basic SQL. Dr Fawaz Alarfaj. ACKNOWLEDGEMENT Slides are adopted from: Elmasri & Navathe, Fundamentals of Database Systems MySQL Documentation

Department of Computer Science University of Cyprus. EPL342 Databases. Lab 2

MySQL Creating a Database Lecture 3

Simple Quesries in SQL & Table Creation and Data Manipulation

SQL Functionality SQL. Creating Relation Schemas. Creating Relation Schemas

CSCI-UA: Database Design & Web Implementation. Professor Evan Sandhaus

Advanced SQL. Nov 21, CS445 Pacific University 1

Create Basic Databases and Integrate with a Website Lesson 1

EGCI 321: Database Systems. Dr. Tanasanee Phienthrakul

Tool/Web URL Features phpmyadmin. More on phpmyadmin under User Intefaces. MySQL Query Browser

CSCI-UA: Database Design & Web Implementation. Professor Evan Sandhaus

The Top 20 Design Tips

This lab will introduce you to MySQL. Begin by logging into the class web server via SSH Secure Shell Client

sqoop Automatic database import Aaron Kimball Cloudera Inc. June 18, 2009

Department of Computer Science University of Cyprus. EPL342 Databases. Lab 1. Introduction to SQL Server Panayiotis Andreou

Databases (MariaDB/MySQL) CS401, Fall 2015

Careerarm.com. 1. What is MySQL? MySQL is an open source DBMS which is built, supported and distributed by MySQL AB (now acquired by Oracle)

General References on SQL (structured query language) SQL tutorial.

*this is a guide that was created from lecture videos and is used to help you gain an understanding of what is mysql used for.

SQL Commands & Mongo DB New Syllabus

Oracle 1Z MySQL 5.6 Developer.

CIS 363 MySQL. Chapter 4 MySQL Connectors Chapter 5 Data Types Chapter 6 Identifiers

Chapter 3 Introduction to relational databases and MySQL

GridDB Advanced Edition SQL reference

Database Management Systems,

MTAT Introduction to Databases

Database. Ed Milne. Theme An introduction to databases Using the Base component of LibreOffice

Introduction to IBM DB2

SQL: Concepts. Todd Bacastow IST 210: Organization of Data 2/17/ IST 210

SQL Introduction. CS 377: Database Systems

HOW TO CREATE AND MAINTAIN DATABASES AND TABLES. By S. Sabraz Nawaz Senior Lecturer in MIT FMC, SEUSL

user specifies what is wanted, not how to find it

sqoop Easy, parallel database import/export Aaron Kimball Cloudera Inc. June 8, 2010

SQL OVERVIEW. CS121: Relational Databases Fall 2017 Lecture 4

Constraints. Primary Key Foreign Key General table constraints Domain constraints Assertions Triggers. John Edgar 2

Relational databases and SQL

Documentation Accessibility. Access to Oracle Support. Supported Browsers

Lab 4: Tables and Constraints

Chapter 13 : Informatics Practices. Class XI ( As per CBSE Board) SQL Commands. New Syllabus Visit : python.mykvs.in for regular updates

Oracle SQL Developer. Supplementary Information for MySQL Migrations Release 2.1 E

COGS 121 HCI Programming Studio. Week 03 - Tech Lecture

MySQL. A practical introduction to database design

What is MySQL? [Document provides the fundamental operations of PHP-MySQL connectivity]

MariaDB ColumnStore Python API Usage Documentation

Information Systems for Engineers Fall Data Definition with SQL

varchar(30), Primary Key (name))engine=innodb; bigint not null auto_increment, Primary Key (accountid))engine=innodb;

SQL: Data De ni on. B0B36DBS, BD6B36DBS: Database Systems. h p:// Lecture 3

Principles of Data Management

SQL language. Jaroslav Porubän, Miroslav Biňas, Milan Nosáľ (c)

SQL DATA DEFINITION LANGUAGE

SAS/ACCESS Supplement for MySQL. SAS/ACCESS for Relational Databases

SQL (and MySQL) Useful things I have learnt, borrowed and stolen

Functional Logic Programming with Databases

SQL DATA DEFINITION LANGUAGE

SQL Fundamentals. Chapter 3. Class 03: SQL Fundamentals 1

Data Definition and Data Manipulation. Lecture 5: SQL s Data Definition Language CS1106/CS5021/CS6503 Introduction to Relational Databases

Databases and MySQL: The Basics

Lecture 5: SQL s Data Definition Language

Model Question Paper. Credits: 4 Marks: 140

Introduction to MySQL /MariaDB and SQL Basics. Read Chapter 3!

DATABASE MANAGEMENT SYSTEMS

The URL of the whole system is:

Data types String data types Numeric data types Date, time, and timestamp data types XML data type Large object data types ROWID data type

Private Institute of Aga NETWORK DATABASE LECTURER NIYAZ M. SALIH

Operating systems fundamentals - B07

PERSİSTENCE OBJECT RELATİON MAPPİNG

Working with Databases and Java

Chapter 4. Basic SQL. Copyright 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley

Introduction to Databases and SQL

Introduction to SQL Server 2005/2008 and Transact SQL

Database Applications and Web-Enabled Databases. University of California, Berkeley School of Information IS 257: Database Management

DB Programming. Database Systems

EE 495M - Lecture 3. Overview

EDB Postgres Hadoop Data Adapter Guide

How to use SQL to create a database

SQL DATA DEFINITION LANGUAGE

Lecture 1. Monday, August 25, 2014

Data Storage and Query Answering. Data Storage and Disk Structure (4)

Creating Tables, Defining Constraints. Rose-Hulman Institute of Technology Curt Clifton

BASIC SQL CHAPTER 4 (6/E) CHAPTER 8 (5/E)

Transcription:

Introduction to SQL on GRAHAM ED ARMSTRONG SHARCNET AUGUST 2018

Background Information 2

Background Information What is a (Relational) Database 3 Dynamic collection of information. Organized into tables, rows, and columns. Often indexed to improve access time. They exist in a variety of flavours.

Background Information Types of Databases 4 Distributed Dynamic collection / NoSQL of information. Object Organized Oriented into tables, / PostgreSQL rows, and columns. Relational Often indexed / MySQL, to improve MariaDB access time. They exist in a variety of flavours.

Background Information What is SQL 5 Structured Query Language The standard for accessing & manipulating relational databases. There is a standard for how SQL works.

Requesting a Database 6 Send a request to support@computecanada.ca with the following information: Your Compute Canada username. Amount of database space needed for your project. The system you would like an account on (Graham / Cedar). We will create an account with a randomly generated password. The necessary information will be stored in a '.my.cnf' file in your home directory.

MySQL Configuration 7 [client] ssl ssl-cipher=dhe-rsa-aes256-sha:aes128-sha user=your_username password=yyg1zjyrxkmdfv0u database=your_username host=199.241.163.99

8 Create, Use, Delete Databases

Create, Use, Delete Databases 9 $ ssh graham@computecanada.ca $ mysql (with.my.cnf) $ mysql -h hostname -u username (w/o.my.cnf) $ mysql --local-infile=1 CREATE DATABASE my_database; SHOW DATABASES; USE my_database; DROP DATABASE my_database; * You won t receive a warning

Tables 10

Tables 11 A database is a collection of tables. TABLE TABLE TABLE DATABASE

Tables 12 A database is a collection of tables. A table is a collection of data entries (tuples). TABLE

Tables 13 A database is a collection of tables. A table is a collection of data entries (tuples). An entry is a row. TABLE

Tables 14 A database is a collection of tables. A table is a collection of data entries (tuples). An entry is a row. A data point (type) is a column. TABLE

Table Schema 15 The table schema describes the contents of a table. NAME AGE BREED COLOR DOGS

Table Schema 16 The table schema describes the contents of a table. NAME: STRING AGE: NUMBER BREED: STRING COLOR: STRING DOGS

SQL Data Types 17

SQL Data Types 18 Text Data Types CHAR VARCHAR TINYTEXT BLOB MEDIUMTEXT LONGTEXT LONGBLOB ENUM SET Number Data Types TINYINT SMALLINT MEDIUMINT INT BIGINT FLOT DOUBLE DECIMAL Date Data Types DATE DATETIME TIMESTAMP TIME YEAR

SQL Data Types 19 Text Data Types CHAR VARCHAR TINYTEXT BLOB MEDIUMTEXT LONGTEXT LONGBLOB ENUM SET Number Data Types TINYINT SMALLINT MEDIUMINT INT BIGINT FLOT DOUBLE DECIMAL Date Data Types DATE DATETIME TIMESTAMP TIME YEAR

SQL Data Types 20 CHAR VARCHAR INT DOUBLE DATE

If your content is a fixed size, you'll get better performance with CHAR. SQL Data Types 21 CHAR / VARCHAR INT DOUBLE DATE Variables in CHAR are fixed length string up to 255 characters in length. Variable in VARCHAR are variable length strings up to 65,535* characters in length. *Shared across all columns.

SQL Data Types 22 CHAR/VARCHAR INT DOUBLE DATE Type Storage (Bytes) Minimum Value Signed Minimum Value Unsigned Maximum Value Signed Maximum Value Unsigned TINYINT 1-128 0 127 255 SMALLINT 2-32768 0 32767 65535 MEDIUMINT 3-8388608 0 8388607 16777215 INT 4-2147483648 0 2147483647 4294967295 BIGINT 8-2 63 0 2 63-1 2 64-1 Required Storage and Range for Integer Types Supported by MySQL https://dev.mysql.com/doc/refman/8.0/en/integer-types.html

SQL Data Types 23 CHAR/VARCHAR INT DOUBLE DATE The FLOAT and DOUBLE data types are APPROXIMATE. If you require and exact decimal value, such as for currency, use DECIMAL.

SQL Data Types 24 VARCHAR INT DOUBLE DATE The DATE data type represents a calendar value. There are a number of interpretation rules that MySQL uses, as such you should stick to the SQL standard format (YYYY-MM-DD).

Creating a Table 25

Creating a Table 26 CREATE TABLE employees ( name varchar(64), id int, start date ); SQL command Table name Column names Column data types

Setting and Getting Values 27 - A PREVIEW INSERT INTO employees VALUES( 'Adam', 1, '2018-07-07' ); SELECT * FROM employees; INSERT INTO employees (name) VALUES ( Adam );

Creating a Table: Unsigned Integer 28 Table name Table column names Table column data types CREATE TABLE employees ( name varchar(64), id int UNSIGNED, start date );

Creating a Table: 29 - Reserved Keywords & Spaces CREATE TABLE employees ( `first name` varchar(64), `index` int UNSIGNED, start date );

Creating a Table: 30 - Reserved Keywords CREATE TABLE employees ( `first name` varchar(64), `index` int UNSIGNED, start date );

Inserting Data Into a Table 31

Inserting Data Into a Table 32 INSERT INTO employees (name, id, start) values ('Adam', 1, '2018-07-07');

Inserting Data Into a Table 33 INSERT INTO employees( name, id, start )VALUES( 'Adam', 1, '2018-07-07' );

Inserting Multiple Data 34 INSERT INTO employees(name, id, start) VALUES( Adam, 1, 2018-07-07 ),( Steve, 2, 2016-06-04 ),( Craig, 3, 2016-06-04 );

35 Retrieving Your Data SELECT

Retrieving Your Data 36 SELECT * FROM employees;

Retrieving Your Data 37 SELECT * FROM employees; SQL Keywords

Retrieving Your Data 38 SELECT * FROM employees; Column Selector * means all Table Selector * means all

Retrieving Your Data 39 SELECT * FROM employees; SELECT name FROM employees; SELECT name, id FROM employees; SELECT name, id, start FROM employees; SELECT id, start, name FROM employees;

40 Terminating a Command \c

41 Selecting Rows by Content WHERE

Selecting Rows by Content 42 SELECT * FROM employees WHERE id = 3; SELECT * FROM employees WHERE name = Adam ; SELECT * FROM employees WHERE name = ADAM ; SELECT * FROM employees WHERE name = A% ; SELECT * FROM employees WHERE binary name= Adam ; SELECT * FROM employees WHERE name= Adam AND id = 7;

43 Change Existing Data UPDATE

Change Existing Data 44 UPDATE employees SET name= Chris WHERE name= Adam ; UPDATE employees SET start= 2018-05-09 WHERE id= 1 ; UPDATE employees SET start= 2000-01-01 WHERE start IS null;

45 Removing Data DELETE

Removing Data 46 DELETE FROM employees WHERE name= Adam ; DELETE FROM employees WHERE start=end; DELETE FROM employees;

47 Executing SQL Files SOURCE

Running SQL Files 48 $ mysql < instructions.sql $ mysql --verbose < instructions.sql $ mysql -e < select * from table mysql> source instructions.sql

49 Importing Data LOAD DATA

Load Data 50 LOAD DATA LOCAL INFILE file INTO TABLE table

Load Data 51 LOAD DATA LOCAL INFILE file INTO TABLE table fields terminated by \t enclosed by escaped by \\ lines terminated by \n starting by ;

Load Data 52 LOAD DATA LOCAL INFILE file INTO TABLE table fields terminated by \t, enclosed by escaped by \\ lines terminated by \n starting by ;

Load Data 53 CREATE TABLE employees( first_name VARCHAR(64), last_name VARCHAR(64), id int AUTO_INCREMENT, start DATE, finish DATE, PRIMARY KEY(id) ) LOAD DATA LOCAL INFILE 'employeedata.tab INTO TABLE employees (first_name, last_name, @ignore, start, finish);

Save Data 54 mysql -ss -e "select * from employees" > data.tab