SQL CMSC 461 Michael Wilson. Finally, some code  This is where the theory and practice actually come together  Basically taking the relational algebra.

Slides:



Advertisements
Similar presentations
CIT 613: Relational Database Development using SQL Revision of Tables and Data Types.
Advertisements

Session 2Introduction to Database Technology Data Types and Table Creation.
SQL This presentation will cover: A Brief History of DBMS View in database MySQL installation.
Database Basics I101 Summer 2006 Copyright 2004, Matt Hottell.
Week 2: Primitive Data Types 1.  Programming in Java  Everything goes inside a class  The main() method is the starting point for executing instructions.
19-Jun-15 SQL. SQL is Structured Query Language Some people pronounce SQL as “sequel” Other people insist that only “ess-cue-ell” is the only correct.
A Guide to SQL, Seventh Edition. Objectives Understand the concepts and terminology associated with relational databases Create and run SQL commands in.
DT211 Stage 2 Databases Lab 1. Get to know SQL Server SQL server has 2 parts: –A client, running on your machine, in the lab. You access the database.
1 Design patterns Lecture 4. 2 Three Important skills Understanding OO methodology Mastering Java language constructs Recognizing common problems and.
30-Jun-15 SQL A Brief Introduction. SQL SQL is Structured Query Language Some people pronounce SQL as “sequel” Other people insist that only “ess-cue-ell”
Creating Database Tables CS 320. Review: Levels of data models 1. Conceptual: describes WHAT data the system contains 2. Logical: describes HOW the database.
Structured Query Language. Brief History Developed in early 1970 for relational data model: –Structured English Query Language (SEQUEL) –Implemented with.
Introduction To Databases IDIA 618 Fall 2014 Bridget M. Blodgett.
Oracle Data Definition Language (DDL)
MySql In Action Step by step method to create your own database.
Copyright © Curt Hill SQL The Data Definition Language.
Session 5: Working with MySQL iNET Academy Open Source Web Development.
Chapter 5 Introduction to SQL. Structured Query Language = the “programming language” for relational databases SQL is a nonprocedural language = the user.
ASP.NET Programming with C# and SQL Server First Edition
PHP Programming with MySQL Slide 8-1 CHAPTER 8 Working with Databases and MySQL.
Concepts of Database Management Seventh Edition
Database Design lecture 3_1 1 Database Design Lecture 3_1 Data definition in SQL.
Structured Query Language. Brief History Developed in early 1970 for relational data model: –Structured English Query Language (SEQUEL) –Implemented with.
HAP 709 – Healthcare Databases SQL Data Manipulation Language (DML) Updated Fall, 2009.
Guofeng Cao CyberInfrastructure and Geospatial Information Laboratory Department of Geography National Center for Supercomputing Applications (NCSA) University.
NMED 3850 A Advanced Online Design January 12, 2010 V. Mahadevan.
SQL SQL Server : Overview SQL : Overview Types of SQL Database : Creation Tables : Creation & Manipulation Data : Creation & Manipulation Data : Retrieving.
1 Structured Query Language (SQL). 2 Contents SQL – I SQL – II SQL – III SQL – IV.
Chapter 10: The Data Tier We discuss back-end data storage for Web applications, relational data, and using the MySQL database server for back-end storage.
SQL continued CMSC 461 Michael Wilson. Right back into it  Recap:  Learned how to log in to PostgreSQL  Learned about PostgreSQL data types  Learned.
SQL Fundamentals  SQL: Structured Query Language is a simple and powerful language used to create, access, and manipulate data and structure in the database.
Tables and Constraints Oracle PL/SQL. Datatypes The SQL Data Definition Language Commands (or DDL) enable us to create, modify and remove database data.
Visual Programing SQL Overview Section 1.
Sql DDL queries CS 260 Database Systems.
CMPT 258 Database Systems The Relationship Model (Chapter 3)
>> Introduction to MySQL. Introduction Structured Query Language (SQL) – Standard Database Language – Manage Data in a DBMS (Database Management System)
CS 111 – Nov. 8 Databases Database Management Systems (DBMS) Structured Query Language (SQL) Commitment –Please review sections 9.1 – 9.2.
ECMM6018 Enterprise Networking For Electronic Commerce Tutorial 6 CGI/Perl and databases.
Database: SQL, MySQL, LINQ and Java DB © by Pearson Education, Inc. All Rights Reserved.
IS6146 Databases for Management Information Systems Lecture 3: SQL III – The DDL Rob Gleasure robgleasure.com.
Physical Model Lecture 11. Physical Data Model The last step is the physical design phase, In this phase data is – Store – Organized and – Access.
Programming for the Web MySQL Command Line Using PHP with MySQL Dónal Mulligan BSc MA
1 Designing Tables for a Database System. 2 Where we were, and where we’re going The Entity-Relationship model: Used to model the world The Relational.
Instructor: Craig Duckett Lecture 06: Thursday, October 15 th, 2015 Indexes, Aliases, Distinct, SQL 1 BIT275: Database Design (Fall 2015)
SQL Introduction SQL stands for “Structured Query Language” and can be pronounced as “SQL” or “sequel – (Structured English.
Creating Database Objects
Rob Gleasure robgleasure.com
Web Systems & Technologies
Chapter 5 Introduction to SQL.
Rob Gleasure robgleasure.com
CS320 Web and Internet Programming SQL and MySQL
SQL and SQL*Plus Interaction
Insert, Update and the rest…
Other Kinds of Arrays Chapter 11
Database Construction and Usage
Designing Tables for a Database System
ORACLE SQL Developer & SQLPLUS Statements
Designing Tables for a postgreSQL Database System
Introduction to Primitive Data types
CS122 Using Relational Databases and SQL
Session - 6 Sequence - 1 SQL: The Structured Query Language:
CS3220 Web and Internet Programming SQL and MySQL
CS1222 Using Relational Databases and SQL
Data Definition Language
MIS2502: Data Analytics SQL 4– Putting Information Into a Database
MySQL Database System Installation Overview SQL summary
CS3220 Web and Internet Programming SQL and MySQL
Creating Database Objects
CS122 Using Relational Databases and SQL
Introduction to Primitive Data types
Presentation transcript:

SQL CMSC 461 Michael Wilson

Finally, some code  This is where the theory and practice actually come together  Basically taking the relational algebra and mapping it all to a query language  The concepts are very close to what we’ve already seen, but there are some nuances

One true SQL?  There are ISO/ANSI SQL standards  In my experience, different DBMSes have different/proprietary extensions that can make raw SQL queries pretty DBMS specific  The extensions aren’t exactly frequent  Invariably, it affects whatever thing you’re working on

DBMS to focus on?  I firmly believe that PostgreSQL is going to be a big deal  MySQL is getting mired in some drama relating to being owned by Oracle  Forked off into MariaDB  Therefore, I’m going to focus on Postgres  Also, AWS RDS supports Postgres now  You are welcome to use whatever you wish for projects  RDS supports MySQL and PostgreSQL, but you’re not limited to AWS

Before we get started  PostgreSQL’s SQL language documentation  ml ml  Use it!  PostgreSQL is case insensitive and insensitive to whitespace between commands  Can spread a command across multiple lines or type it all on one line

Getting started  Most DBMSes can have multiple databases  Each database can consist of many tables  If we configure PostgreSQL using AWS RDS, then we don’t have to create the database ourselves  This can be a little complex in Postgres  We’re going to assume the database is created

Connecting to your database using psql  psql –h -d -U  Command line PostgreSQL client  On success, this will drop you to a prompt

Connecting to your database using psql

Table creation  Before you can do anything, you need to create a table  Basic syntax:  CREATE TABLE table_name ( column_name data_type, column_name data_type, …. );

Table creation  This is effectively creating a new relation  We’ll be referencing this a lot  We’ll also be building on it, so expect to learn new features about table creation as we go  This syntax will create a basic table with columns

Data types  Some basic ones to know  Integer (signed 4 byte integer)  Numeric (numbers with high precision)  Kind of like a double, but has EXACT calculations  Boolean (true/false)  Varchar (character strings of variable lengths)  Text (unlimited length strings)  Not part of SQL standard

Data types  Databases support TONS of data types  Numbers, dates, booleans, money, geometric shapes, JSON, etc.  Some are part of the SQL standard, some aren’t  Best to refer to the PostgreSQL documentation for guidance on data types  Lots of nuances, recommendations, etc.

Table creation example address daysSinceContact contactPhoneNumber numberTypecontactName 111 Great Street CellPhil 8 Get Out of Here Way WorkBob 7 RUN! Drive CellOctavio

Table creation example  CREATE TABLE AddressBook (address varchar(256), daysSinceContact integer, contactPhoneNumber varchar(64), numberType varchar(16), contactName varchar(256));

Table insertion  Figure it might be handy to actually add data to our table  This is like adding a tuple to the relation  Basic syntax:  INSERT INTO (column_name1, column_name2, … column_name_n) values (value_1, value_2, …, value_n)

Table insertion  You can specify the columns in any order you want  As long as you specify the values in the corresponding order

Table insertion  A note  If you recall, tuples are explicitly unique in databases  This is not the case in tables  They can be made this way, but this is not the default behavior

Table insertion example  INSERT INTO AddressBook (address, daysSinceContact, contactPhoneNumber, numberType, contactName) VALUES (’21 Jump Street’, 40, ‘ ’, ‘Cell’, ‘Johnny’)

Table insertion example address daysSinceContact contactPhoneNumber numberTypecontactName 111 Great Street CellPhil 8 Get Out of Here Way WorkBob 7 RUN! Drive CellOctavio 21 Jump Street CellJohnny

Enough for today  See you next class!