Part I: Introduction. Outline. Introduction to Databases & SQL. Motivating Example Flat Files. Relational Databases. Problems with Flat Files
|
|
- Peter Hancock
- 5 years ago
- Views:
Transcription
1 Outline Introduction to Databases & SQL Dr. Christopher M. Bourke 1. Introduction 2. Creating Tables 3. Manipulating Data 4. Querying Data 5. Extended Demonstration 6. Designing Databases 7. Extended Demonstration Motivating Example Flat Files Consider the following data, stored in a flat file: Part I: Introduction Course Course Name Student NUID waits, tom tomwaits@hotmail.com CSCE 156 Intro to CSII Lou Reed reed@gmail.com CSCE 156 Intro to CSII Tom Waits twaits@ .com CSCE 230 Computer Hardware Student, J jstudent@geocities.com CSCE 156 Intro to CSII Student, John jstudent@geocities.com CSCE 230 Computer Hardware John Student jstudent@geocities.com CSCE 235 Discrete Math Student, John jstudent@geocities.com CSCE 235 Discrete Math Tom Waits twaits@ .com NONE Null Tom Waits twaits@ .com Table: Course Enrollment Data Problems with Flat Files Relational Databases Problems: Formatting Issues Repetition of data Incomplete data Integrity of data Organizational problems: any aggregation requires processing all records Updating information is difficult (must enumerate all possible changes, side effects so that information is not lost) Concurrency Issues Solution: Relational Database Management System (RDBMS) Represents data as tuples (pairs, triples, etc.) Data is grouped into relations E. F. Codd (IBM, 1970)
2 Key Aspects I Key Aspects II Data is stored in tables Tables have columns (or fields) that have a unique name and type (integer, string) Each column stores a single piece of data Each row represents a single record Each row may have a unique primary key (PK) which uniquely identifies each record Records in different tables are related to each other through foreign keys (FK) Order of rows/columns is meaningless Key Aspects III Key Aspects IV studentid firstname lastname nuid courseid name description CSCE Computer Science 1 Tom Waits II CSCE 230 Computer Hardware 2 Lou Reed CSCE 235 Discrete Mathematics 5 John Student id studentid address 8 2 reed@gmail.com 10 1 tomwaits@hotmail.com enrollmentid studentid courseid semester Fall twaits@ .com Fall jstudent@geocities.com Fall Fall Spring Fall 2011 Supports Transactions: an interaction or batch of interactions treated as one unit Constraints Allowing or disallowing NULL Disallowing bad values (ranges) Enforcing formatting (capitalization, precision) Limiting combinations of data fields ACID Principles I RDBMS s Atomicity Data transactions must be an all-or-nothing process Atomic operation: not divisible or decomposable Consistency Transactions will retain a state of consistency All constraints, triggers, cascades preserve a valid state after the transaction has completed Isolation No transaction interferes or is even aware of another; state transitions are equivalent to serial transactions Durability Once committed, a transaction remains so Data is to be protected from catastrophic error (power loss/crash) Commercial Systems: MS Access, MySQL (Oracle), MariaDB, PostgreSQL, Informix, DB2 SQLServer, Oracle, SQLite NoSQL (non relational databases) Key-value databases: MongoDB, Cassandra, Spanner Graph-based: Neo4j, OrientDB Redis Database SaaS: Amazon Web Services (Dynamo)
3 Advantages I Advantages II Data is structured instead of just there Better organization Duplication is minimized (with proper normalization) Updating information is easier Organization of data allows easy access Organization allows aggregation and more complex information Data integrity can be enforced (data types and user defined constraints) Faster Scalable Security Portability Concurrency Structured Query Language Structured Query Language CRUD We interact with RDBMs using Structured Query Language (SQL) Common language/interface to most databases Developed by Chamberlin & Boyce, IBM 1974 Implementations may violate standards: portability issues Comments: # Keywords are case insensitive Create & manage tables: create, alter, drop Basic SQL functionality: CRUD: Create insert new records into existing tables ( insert ) Retrieve get a (subset) of data from specific rows/columns ( select ) Update modify data in fields in specified rows ( update ) Destroy delete specific rows from table(s) ( delete ) MySQL Getting Started Part II: Creating a Database Need access to a database server Need to use a client to connect to the server CLI: mysql MySQL Workbench 1 use databasename; 2 show tables; 3 describe TableName;
4 MySQL CSCE Students Creating Tables Syntax You only have access to a database with the same name as your login Host: cse.unl.edu Port: 3306 User: your CSE login ID Password: go to Do not use the same password as your login More: 1 create table TableName ( 2 columnname columntype [options], ); Options: primary key auto_increment (for primary keys) not null default (value) Column Types Creating Tables Example varchar(n) variable character field of up to n characters integer (or int ) decimal(65,30), float, double Others: aliases, vendor-specific keywords, date/time, other data formats (JSON) 1 create table Book ( 2 bookid integer primary key auto_increment not null, 3 title varchar(255) not null, 4 author varchar(255), 5 isbn varchar(255) not null default, 6 dewey float, 7 numcopies integer default 0 8 ); Primary Keys Keys A primary key gives each record a unique identity At most one primary key per table No two rows can have the same primary key value Must be able to uniquely identify all records (not just those that exist) PKs can be one or more columns (composite key) Should not use/allow NULL values Can/should External identifiers should not be used Should use integers, not varchars or floats Tables can have multiple (non-primary) keys May be a combination of columns (composite key) May be declared non-unique in which case it serves as an index (allows database lookup optimization) Syntax: key(column1, column2,...)
5 Indices and Unique Constraints Foreign Keys I The keyword index can also be used We can make them unique by using unique Syntax: constraint constraintname unique index(columnname) Multiple columns:... index(c1, c2) Relations between records in different tables can be made with foreign keys A foreign key is a column that references a key (PK or regular key) in another table Inserts cannot occur if the referenced record does not exist Foreign keys establish relationships between tables: One-to-one (avoid) One-to-many relations Many-to-one Many-to-Many relations: requires a Join Table Syntax: foreign key (columnname) references tablename(columnname) Demonstration I Write SQL to define two tables: one for authors and one for books. Simplify the book table, but include an ISBN as well as a constraint to keep it unique. Model the fact that an author may write more than one book. Demonstration I Solution 1 create table Author ( 2 authorid integer primary key not null auto_increment, 3 firstname varchar(255), 4 lastname varchar(255) not null 5 ); 6 7 create table Book ( 8 bookid integer primary key not null auto_increment, 9 authorid integer not null, 10 title varchar(255), 11 isbn varchar(255) not null, 12 numcopies integer default 0, 13 foreign key (authorid) references Author(authorId), 14 constraint uniqueisbn UNIQUE INDEX(isbn) 15 ); Demonstration II Solution Part III: Manipulating Data Figure: Entity-Relation Diagram for the Book/Author tables
6 Inserting Data Inserting Data I Examples Creating data involves inserting new records into a table Values are specified with literals Numerical literals String literals: use single quote characters Syntax: insert into tablename (c1, c2,...) values (v1, v2,...); 1 insert into Author (firstname, lastname) values 2 ( Normal, Mailer ); 3 --or 4 insert into Author (authorid, firstname, lastname) values 5 (1234, Normal, Mailer ); 6 7 insert into Book (title, authorid, isbn) values 8 ( The Naked and the Dead, 1234, ); 9 insert into Book (title, authorid, isbn) values 10 ( The Naked and the Dead, 11 (select authorid from Author where lastname = Mailer ), ); Inserting Data II Examples Updating Data 1 --Errors: 2 /* 3 insert into Book (title, authorid, isbn) values 4 ( The Executioner s Song, 1234, ); 5 */ 6 7 insert into Book (title, authorid, isbn) values 8 ( The Executioner\ s Song, 1234, ); Existing data can be modified using an update statement Should be used in conjunction with clauses Syntax: 1 update tablename set c1 = v1, c2 = v2,... 2 where [condition]; Updating Data Examples Deleting Data 1 --dangerous: 2 update Author set firstname = Norman ; correct: 5 update Author set firstname = Norman 6 where authorid = 1234; Records can be deleted using a delete statement Should be used in conjunction with clauses Unless you really want to delete everything Syntax: delete from tablename where [condition]
7 Deleting Data Examples 1 --we cannot delete norman: 2 delete from Author where lastname = Mailer ; 3 delete from Author where authorid = 1234; 4 5 delete from Book where bookid = 1; 6 delete from Book where title = The Naked and the Dead ; deletes all of Norman s book entries: 9 delete from Book where authorid = 1234; 10 --now we could delete norman Part IV: Querying Data Querying Data Querying Data Examples Data can be retrieved using the select statement Syntax: select c1, c2,... from tablename where [condition]; Can select all columns by using the * wildcard: select * from Book; 1 select * from Book; 2 select * from Book where authorid = 1234; 3 select * from Book where isbn = ; 4 5 select lastname, firstname from Author; 6 select lastname, firstname from Author where authorid = 1234; Querying Data Aliasing Complex where Clause Names of the columns are part of the database SQL allows us to rename them in result of our query using aliasing Syntax: columnname as columnalias Sometimes necessary if column has no name (aggregates) 1 select title as booktitle, 2 numcopies as numberofcopies 3 from Book; Queries can be quantified using the where clause Only records matching the condition will be affected (updated, deleted, selected) Compound conditions can be composed using parentheses and the and and or keywords 1 select * from Book 2 where numcopies > 10 AND 3 (title!= The Naked and the Dead 4 OR authorid = 1234); To check nullity: where title is null, where title is not null
8 distinct Clause like Clause Many records may have the same column value To query only unique values you may use the distinct keyword 1 select distinct lastname from Author; 2 select distinct authorid from Book; String ( varchar ) values can be searched/partially matched using the like clause Used in conjunction with the string wildcard, % 1 select * from Book where isbn like 123% ; 2 select * from Author where lastname like %ailer% ; in Clause order by Clause The in clause allows you to do conditionals on a set of values May be used in conjunction with a nested query 1 select * from Book where isbn in ( , , ); 3 4 select * from Book where authorid in 5 (select authorid from Author where lastname like M% ); In general, the order of the results of a select clause is nondeterministic To impose an order, you can use order by Can order along multiple columns Can order descending ( desc ) or ascending ( asc ) order 1 select * from Book order by title; 2 select * from Book order by authorid, title desc; Aggregate Functions Aggregate Functions Examples Aggregate functions allow us to compute data in the database without processing all the data in code count provides a mechanism to count the number of records Other aggregate functions: max, min, avg, sum null values are ignored/treated as zero 1 --number of Book records: 2 select count(*) as numberoftitles from Book; 3 --most common book: 4 select max(numcopies) from Book; nested queries: 7 select * from Book 8 where numcopies = (select max(numcopies) from Book);
9 GROUP BY clause group by clause Example Illustrated The group by clause allows you to project data with common values into a smaller set of rows Used in conjunction with aggregate functions to do more complicated aggregates Example: find total copies of all books grouped by their author 1 select author, sum(numcopies) as totalcopies 2 from Book group by author; Table content: title author numcopies Naked and the Dead Norman Mailer 10 Dirk Gently s Holistic Detective Agency Douglas Adams 4 Barbary Shore Norman Mailer 3 The Hitchhiker s Guide to the Galaxy Douglas Adams 2 The Long Dark Tea-Time of the Soul Douglas Adams 1 Ender s Game Orson Scott Card 7 GROUP BY clause Example Illustrated group by clause Example Illustrated Grouping: title author numcopies Naked and the Dead Norman Mailer 10 Barbary Shore Norman Mailer 3 Dirk Gently s Holistic Detective Agency Douglas Adams 4 The Hitchhiker s Guide to the Galaxy Douglas Adams 2 The Long Dark Tea-Time of the Soul Douglas Adams 1 Ender s Game Orson Scott Card 7 Projection & aggregation: author totalcopies Norman Mailer 13 Douglas Adams 7 Orson Scott Card 7 having clause Joins A join is a clause that combines records from two or more tables. Projected data can be further filtered using the having clause having is evaluated after group by which is evaluated after any where clause 1 select author, sum(numcopies) as totalcopies 2 from Book where isbn like %9 3 group by author 4 having totalcopies > 10; Result is a set of columns/rows (a table ) Results from tables A, B are joined by shared values in specified columns Common to join via foreign keys Table names can be aliased for convenience Types of joins we ll look at: (inner) join left (outer) join Other types of joins: Self-join, cross join (cartesian product), right outer joins, full outer joins
10 Inner Join I Inner Join II Inner Join: Most common type of join Combines rows of table A with rows of table B for all records that satisfy some predicate Predicate provided by the on clause Common to omit inner and simply use the join keyword 1 select * from Book b 2 join Author a on b.authorid = a.authorid; 3 4 select * from Author a 5 join Book b on a.authorid = b.authorid; 6 7 select * from Book b 8 join Author a on b.authorid = b.authorid 9 where a.title like The% ; select a.firstname as firstname, 12 a.lastname as lastname, 13 b.title as booktitle 14 from Book b 15 join Author a on b.authorid = b.authorid; Inner Join Example Illustrated Inner Join Example Illustrated 1 select s.studentid, s.lastname, e.address 2 from student s 3 join e on s.studentid = e.studentid; studentid lastname firstname 1234 Castro Starlin 5678 Rizzo Anthony 1122 Sveum Dale 9988 Sandberg Ryne (a) Student Table id studentid address rsandberg@cubbies.net rsberg@unl.edu rizzo@cubs.com number13@cubs.com (b) Table studentid lastname address 1234 Castro number13@cubs.com 5678 Rizzo rizzo@cubs.com 9988 Sandberg rsandberg@cubbies.net 9988 Sandberg rsberg@unl.edu Table: Joined tables Left (Outer) Join I Left (Outer) Join II A Left Outer Join joins table A to table B, preserving all records in table A Records in A with no matching records in B will have null values for columns in B Syntax: omit outer and use left join 1 --no difference as a book cannot exist without an author: 2 select * from Book b 3 left join Author a on b.authorid = a.authorid; includes authors even if they have no book records: 6 select * from Author a 7 left join Book b on a.authorid = b.authorid; 8 9 select s.studentid, s.lastname, e.address 10 from student s 11 left join e on s.studentid = e.studentid;
11 Left (Outer) Join III Other Joins Nice tutorial: student id last name adddress 1234 Castro 5678 Rizzo 9988 Sandberg 9988 Sandberg 1122 Sveum null Table: Left-Joined Tables Figure: Types of Joins SQL Query Demonstrations Part V: Extended Demonstration Figure: Video Game Database Database Design Table Design Identify all entities in different tables Part VI: Designing a Database Ask what defines an entity to determine the columns and their types Properly define whether or not a column should be allowed to be null and/or defaults Each table should have a primary key Relations between tables should be identified and defined with foreign keys Security concerns: don t store sensitive information (passwords) in plaintext
12 Normalization I Normalization II Normalizing a database is the process of separating data into different tables to reduce or eliminate data redundancy and reduce anomolies (preserve integrity) when data is changed. It also reduces the amount of book keeping necessary to make such changes. 1 Normal Form: the domain of each attribute in each table has only atomic values: each column value represents a single value Example: Allowing multiple records for one Person Storing these as (say) a CSV in one column is a violation of 1NF Hardcoding a fixed number of columns ( 1, 2, 3) for multiple values is a violation of 1NF Separating records out into another table and associating them via a FK conforms to 1NF 2 Normal Form: 1NF and no non-prime attribute is dependent on any proper subset of prime attributes Mostly relevant for tables with composite PKs (multiple columns) If another, non-prime column is dependent only on a subset of these, its not 2NF Must split it out groups of data into multiple tables and relate them through FKs so that non-prime column is dependent only on the subset of prime columns Example: a purchase record may contain: customerid, storeid, storelocation Using an auto-generated primary key gives you 2NF automatically Normalization III Normalization IV 3 Normal Form: 2NF and no non-prime column is transitively dependent on the key No non-prime column may depend on another non-prime column Example: Storing a price-per-unit, quantity, and total (total can be derived from the other two) Example: OrderId-CustomerId-CustomerName (OrderId is the PK, CustomerId is FK, CustomerName should be derivable from CustomerId) Bottom line: 3NF is common sense; design your database to be normalized to begin with Every non-key attribute must provide a fact about the key (1NF), the whole key (2NF), and nothing but the key (3NF), so help me Codd 1 1 Edgar Codd, inventor of the relational model, Best Practice Tip 1 Primary Keys Good Practice Tip 2 Use consistent naming conventions Primary Keys Should be integers (not varchars nor floats) Best to allow the database to do key management (auto increment) Should not be based on external identifiers that are not controlled by the database (SSNs, ISBNs, etc.) Be consistent in naming conventions ( tablenameid ) Short, simple, descriptive names Limit abbreviations, acronyms Use consistent styling Tables: UpperCamelCase Columns: lowercamelcase Use singular forms, avoid pluralizations Primary key field: tablenameid Foreign key fields should match the fields they refer to End goal: unambiguous, consistent, self-documenting
13 Good Practice Tip 3 Ensure Good Data Integrity Good Practice Tip 4 Keep Business Logic Out! Data can break code, code should not break data. Data/databases are a service to code Different code, different modules can access the same data The database does not use the code! Should do everything you can to prevent bad code from harming data (constraints, foreign & primary keys, etc). Database is your last line of defense against bad code Databases offer programming functionality Triggers, cascades, stored procedures, etc. Use them sparingly!!! RDMSs are for the management and storage of data, not business logic Demarcation of responsibility DBAs should not have to be Application Programmers, and vice versa Good Practice Tip 5 Hard vs Soft Deletes delete removes records entirely ( hard delete) May not want the data to be permanently deleted Tables may be given an active/inactive flag (boolean) Deleting a record: set the flag to inactive ( soft delete) Application is responsible for only querying for active records Extra care must be taken Part VII: Database Design Demonstration Designing A Database Demonstration Designing A Database Design a database to support a course roster system for the University of Nebraska Lincoln system. The database design should be able to model students (with their unique NUIDs), courses, and their relation (ability of students to enroll in courses). The system will also need to students about updates in enrollment, so be sure your model is able to incorporate this functionality. Figure: A normalized database design.
14 End Result Data from flat file Pieces of data are now organized and have a specific type No duplication of data Entities are represented by IDs, ensuring identity (Tom Waits is now the same as t. Waits) Data integrity is enforced (only one NUID per Student) Relations are well-defined A student has (s) A course has student(s) and a student has course(s) studentid firstname lastname nuid courseid name description CSCE Computer Science 1 Tom Waits II CSCE 230 Computer Hardware 2 Lou Reed CSCE 235 Discrete Mathematics 5 John Student id studentid address 8 2 reed@gmail.com 10 1 tomwaits@hotmail.com enrollmentid studentid courseid semester Fall twaits@ .com Fall jstudent@geocities.com Fall Fall Spring Fall 2011
Database Systems: Design, Implementation, and Management Tenth Edition. Chapter 7 Introduction to Structured Query Language (SQL)
Database Systems: Design, Implementation, and Management Tenth Edition Chapter 7 Introduction to Structured Query Language (SQL) Objectives In this chapter, students will learn: The basic commands and
More informationSQL Interview Questions
SQL Interview Questions SQL stands for Structured Query Language. It is used as a programming language for querying Relational Database Management Systems. In this tutorial, we shall go through the basic
More informationSQL functions fit into two broad categories: Data definition language Data manipulation language
Database Principles: Fundamentals of Design, Implementation, and Management Tenth Edition Chapter 7 Beginning Structured Query Language (SQL) MDM NUR RAZIA BINTI MOHD SURADI 019-3932846 razia@unisel.edu.my
More informationCSC Web Programming. Introduction to SQL
CSC 242 - Web Programming Introduction to SQL SQL Statements Data Definition Language CREATE ALTER DROP Data Manipulation Language INSERT UPDATE DELETE Data Query Language SELECT SQL statements end with
More information618 Index. BIT data type, 108, 109 BIT_LENGTH, 595f BIT VARYING data type, 108 BLOB data type, 108 Boolean data type, 109
Index A abbreviations in field names, 22 in table names, 31 Access. See under Microsoft acronyms in field names, 22 in table names, 31 aggregate functions, 74, 375 377, 416 428. See also AVG; COUNT; COUNT(*);
More informationtablename ORDER BY column ASC tablename ORDER BY column DESC sortingorder, } The WHERE and ORDER BY clauses can be combined in one
} The result of a query can be sorted in ascending or descending order using the optional ORDER BY clause. The simplest form of an ORDER BY clause is SELECT columnname1, columnname2, FROM tablename ORDER
More informationCGS 3066: Spring 2017 SQL Reference
CGS 3066: Spring 2017 SQL Reference Can also be used as a study guide. Only covers topics discussed in class. This is by no means a complete guide to SQL. Database accounts are being set up for all students
More informationChapter 7. Introduction to Structured Query Language (SQL) Database Systems: Design, Implementation, and Management, Seventh Edition, Rob and Coronel
Chapter 7 Introduction to Structured Query Language (SQL) Database Systems: Design, Implementation, and Management, Seventh Edition, Rob and Coronel 1 In this chapter, you will learn: The basic commands
More informationTopics. History. Architecture. MongoDB, Mongoose - RDBMS - SQL. - NoSQL
Databases Topics History - RDBMS - SQL Architecture - SQL - NoSQL MongoDB, Mongoose Persistent Data Storage What features do we want in a persistent data storage system? We have been using text files to
More informationDATABASES SQL INFOTEK SOLUTIONS TEAM
DATABASES SQL INFOTEK SOLUTIONS TEAM TRAINING@INFOTEK-SOLUTIONS.COM Databases 1. Introduction in databases 2. Relational databases (SQL databases) 3. Database management system (DBMS) 4. Database design
More informationThe SQL data-definition language (DDL) allows defining :
Introduction to SQL Introduction to SQL Overview of the SQL Query Language Data Definition Basic Query Structure Additional Basic Operations Set Operations Null Values Aggregate Functions Nested Subqueries
More informationEE221 Databases Practicals Manual
EE221 Databases Practicals Manual Lab 1 An Introduction to SQL Lab 2 Database Creation and Querying using SQL Assignment Data Analysis, Database Design, Implementation and Relation Normalisation School
More informationE-R diagrams and database schemas. Functional dependencies. Definition (tuple, attribute, value). A tuple has the form
E-R diagrams and database schemas Functional dependencies Definition (tuple, attribute, value). A tuple has the form {A 1 = v 1,..., A n = v n } where A 1,..., A n are attributes and v 1,..., v n are their
More informationChapter 3: Introduction to SQL. Chapter 3: Introduction to SQL
Chapter 3: Introduction to SQL Database System Concepts, 6 th Ed. See www.db-book.com for conditions on re-use Chapter 3: Introduction to SQL Overview of The SQL Query Language Data Definition Basic Query
More informationWHAT IS SQL. Database query language, which can also: Define structure of data Modify data Specify security constraints
SQL KEREM GURBEY WHAT IS SQL Database query language, which can also: Define structure of data Modify data Specify security constraints DATA DEFINITION Data-definition language (DDL) provides commands
More informationUsing a DBMS. Shan-Hung Wu & DataLab CS, NTHU
Using a DBMS Shan-Hung Wu & DataLab CS, NTHU DBMS Database A database is a collection of your data stored in a computer A DBMS (DataBase Management System) is a software that manages databases 2 Outline
More informationSQL language. Jaroslav Porubän, Miroslav Biňas, Milan Nosáľ (c)
SQL language Jaroslav Porubän, Miroslav Biňas, Milan Nosáľ (c) 2011-2016 SQL - Structured Query Language SQL is a computer language for communicating with DBSM Nonprocedural (declarative) language What
More informationChapter # 7 Introduction to Structured Query Language (SQL) Part II
Chapter # 7 Introduction to Structured Query Language (SQL) Part II Updating Table Rows UPDATE Modify data in a table Basic Syntax: UPDATE tablename SET columnname = expression [, columnname = expression]
More information30. Structured Query Language (SQL)
30. Structured Query Language (SQL) Java Fall 2009 Instructor: Dr. Masoud Yaghini Outline SQL query keywords Basic SELECT Query WHERE Clause ORDER BY Clause INNER JOIN Clause INSERT Statement UPDATE Statement
More informationCSC 453 Database Technologies. Tanu Malik DePaul University
CSC 453 Database Technologies Tanu Malik DePaul University A Data Model A notation for describing data or information. Consists of mostly 3 parts: Structure of the data Data structures and relationships
More informationT-SQL Training: T-SQL for SQL Server for Developers
Duration: 3 days T-SQL Training Overview T-SQL for SQL Server for Developers training teaches developers all the Transact-SQL skills they need to develop queries and views, and manipulate data in a SQL
More informationSQL Commands & Mongo DB New Syllabus
Chapter 15 : Computer Science Class XI ( As per CBSE Board) SQL Commands & Mongo DB New Syllabus 2018-19 SQL SQL is an acronym of Structured Query Language.It is a standard language developed and used
More informationPrinciples of Data Management
Principles of Data Management Alvin Lin August 2018 - December 2018 Structured Query Language Structured Query Language (SQL) was created at IBM in the 80s: SQL-86 (first standard) SQL-89 SQL-92 (what
More informationChapter 3: Introduction to SQL
Chapter 3: Introduction to SQL Database System Concepts, 6 th Ed. See www.db-book.com for conditions on re-use Chapter 3: Introduction to SQL Overview of the SQL Query Language Data Definition Basic Query
More informationQQ Group
QQ Group: 617230453 1 Extended Relational-Algebra-Operations Generalized Projection Aggregate Functions Outer Join 2 Generalized Projection Extends the projection operation by allowing arithmetic functions
More informationMySQL. A practical introduction to database design
MySQL A practical introduction to database design Dr. Chris Tomlinson Bioinformatics Data Science Group, Room 126, Sir Alexander Fleming Building chris.tomlinson@imperial.ac.uk Database Classes 24/09/18
More informationCMPT 354: Database System I. Lecture 3. SQL Basics
CMPT 354: Database System I Lecture 3. SQL Basics 1 Announcements! About Piazza 97 enrolled (as of today) Posts are anonymous to classmates You should have started doing A1 Please come to office hours
More informationStructured Query Language (SQL)
Structured Query Language (SQL) SQL Chapters 6 & 7 (7 th edition) Chapters 4 & 5 (6 th edition) PostgreSQL on acsmysql1.acs.uwinnipeg.ca Each student has a userid and initial password acs!
More informationJarek Szlichta
Jarek Szlichta http://data.science.uoit.ca/ SQL is a standard language for accessing and manipulating databases What is SQL? SQL stands for Structured Query Language SQL lets you gain access and control
More informationDatabases (MariaDB/MySQL) CS401, Fall 2015
Databases (MariaDB/MySQL) CS401, Fall 2015 Database Basics Relational Database Method of structuring data as tables associated to each other by shared attributes. Tables (kind of like a Java class) have
More informationComputer Science & Engineering 120 Learning to Code
Computer Science & Engineering 120 Learning to Code Introduction to Data Christopher M. Bourke cbourke@cse.unl.edu Part I: Working With Data Topic Overview Data Data Formats Data Operations Introduction
More informationCOSC 304 Introduction to Database Systems SQL DDL. Dr. Ramon Lawrence University of British Columbia Okanagan
COSC 304 Introduction to Database Systems SQL DDL Dr. Ramon Lawrence University of British Columbia Okanagan ramon.lawrence@ubc.ca SQL Overview Structured Query Language or SQL is the standard query language
More informationSQL Fundamentals. Chapter 3. Class 03: SQL Fundamentals 1
SQL Fundamentals Chapter 3 Class 03: SQL Fundamentals 1 Class 03: SQL Fundamentals 2 SQL SQL (Structured Query Language): A language that is used in relational databases to build and query tables. Earlier
More informationA practical introduction to database design
A practical introduction to database design Dr. Chris Tomlinson Bioinformatics Data Science Group, Room 126, Sir Alexander Fleming Building chris.tomlinson@imperial.ac.uk Computer Skills Classes 17/01/19
More informationStructured Query Language
University College of Southeast Norway Structured Query Language Hans-Petter Halvorsen, 2016.01.08 The Tutorial is available Online: http://home.hit.no/~hansha/?tutorial=sql http://home.hit.no/~hansha
More informationChapter 3: Introduction to SQL
Chapter 3: Introduction to SQL Database System Concepts, 6 th Ed. See www.db-book.com for conditions on re-use Chapter 3: Introduction to SQL Overview of the SQL Query Language Data Definition Basic Query
More informationSession 6: Relational Databases
INFM 603: Information Technology and Organizational Context Session 6: Relational Databases Jimmy Lin The ischool University of Maryland Thursday, October 16, 2014 Databases Yesterday Databases Today What
More informationThe SELECT-FROM-WHERE Structure
SQL Queries 1 / 28 The SELECT-FROM-WHERE Structure SELECT FROM WHERE From relational algebra: SELECT corresponds to projection FROM specifies
More informationConsistency The DBMS must ensure the database will always be in a consistent state. Whenever data is modified, the database will change from one
Data Management We start our studies of Computer Science with the problem of data storage and organization. Nowadays, we are inundated by data from all over. To name a few data sources in our lives, we
More informationIntroduction to SQL Part 1 By Michael Hahsler based on slides for CS145 Introduction to Databases (Stanford)
Introduction to SQL Part 1 By Michael Hahsler based on slides for CS145 Introduction to Databases (Stanford) Lecture 2 Lecture Overview 1. SQL introduction & schema definitions 2. Basic single-table queries
More informationOral Questions and Answers (DBMS LAB) Questions & Answers- DBMS
Questions & Answers- DBMS https://career.guru99.com/top-50-database-interview-questions/ 1) Define Database. A prearranged collection of figures known as data is called database. 2) What is DBMS? Database
More informationRelational Algebra and SQL
Relational Algebra and SQL Computer Science E-66 Harvard University David G. Sullivan, Ph.D. Example Domain: a University We ll use relations from a university database. four relations that store info.
More informationWHAT IS A DATABASE? There are at least six commonly known database types: flat, hierarchical, network, relational, dimensional, and object.
1 WHAT IS A DATABASE? A database is any organized collection of data that fulfills some purpose. As weather researchers, you will often have to access and evaluate large amounts of weather data, and this
More informationCS 2340 Objects and Design
CS 2340 Objects and Design SQL Christopher Simpkins chris.simpkins@gatech.edu Chris Simpkins (Georgia Tech) CS 2340 Objects and Design SQL 1 / 26 1 1 The material in this lecture is taken from, Using SQLite3,
More informationSQL Server and SQL Structured Query Language
SQL Server and SQL Structured Query Language Step by step Exercises Hans-Petter Halvorsen Database Systems Hans-Petter Halvorsen, M.Sc. Database Systems A Database is a structured way to store lots of
More informationThe SELECT-FROM-WHERE Structure
SQL Queries 1 / 28 The SELECT-FROM-WHERE Structure SELECT FROM WHERE From relational algebra: SELECT corresponds to projection FROM specifies
More informationSql Server Syllabus. Overview
Sql Server Syllabus Overview This SQL Server training teaches developers all the Transact-SQL skills they need to create database objects like Tables, Views, Stored procedures & Functions and triggers
More informationCopyright 2016 Ramez Elmasri and Shamkant B. Navathe
CHAPTER 6 Basic SQL Slide 6-2 Chapter 6 Outline SQL Data Definition and Data Types Specifying Constraints in SQL Basic Retrieval Queries in SQL INSERT, DELETE, and UPDATE Statements in SQL Additional Features
More informationNCSS: Databases and SQL
NCSS: Databases and SQL Tim Dawborn Lecture 1, January, 2016 Motivation SQLite SELECT WHERE JOIN Tips 2 Outline 1 Motivation 2 SQLite 3 Searching for Data 4 Filtering Results 5 Joining multiple tables
More informationReview. Objec,ves. Example Students Table. Database Overview 3/8/17. PostgreSQL DB Elas,csearch. Databases
Objec,ves PostgreSQL DB Elas,csearch Review Databases Ø What language do we use to query databases? March 8, 2017 Sprenkle - CSCI397 1 March 8, 2017 Sprenkle - CSCI397 2 Database Overview Store data in
More informationDSE 203 DAY 1: REVIEW OF DBMS CONCEPTS
DSE 203 DAY 1: REVIEW OF DBMS CONCEPTS Data Models A specification that precisely defines The structure of the data The fundamental operations on the data The logical language to specify queries on the
More informationInterview Questions on DBMS and SQL [Compiled by M V Kamal, Associate Professor, CSE Dept]
Interview Questions on DBMS and SQL [Compiled by M V Kamal, Associate Professor, CSE Dept] 1. What is DBMS? A Database Management System (DBMS) is a program that controls creation, maintenance and use
More informationAnnouncements (September 14) SQL: Part I SQL. Creating and dropping tables. Basic queries: SFW statement. Example: reading a table
Announcements (September 14) 2 SQL: Part I Books should have arrived by now Homework #1 due next Tuesday Project milestone #1 due in 4 weeks CPS 116 Introduction to Database Systems SQL 3 Creating and
More informationII (The Sequel) We will use the following database as an example throughout this lab, found in students.db.
2 SQL II (The Sequel) Lab Objective: Since SQL databases contain multiple tables, retrieving information about the data can be complicated. In this lab we discuss joins, grouping, and other advanced SQL
More informationLanguage. f SQL. Larry Rockoff COURSE TECHNOLOGY. Kingdom United States. Course Technology PTR. A part ofcenqaqe Learninq
Language f SQL Larry Rockoff Course Technology PTR A part ofcenqaqe Learninq *, COURSE TECHNOLOGY!» CENGAGE Learning- Australia Brazil Japan Korea Mexico Singapore Spain United Kingdom United States '
More informationData about data is database Select correct option: True False Partially True None of the Above
Within a table, each primary key value. is a minimal super key is always the first field in each table must be numeric must be unique Foreign Key is A field in a table that matches a key field in another
More informationExact Numeric Data Types
SQL Server Notes for FYP SQL data type is an attribute that specifies type of data of any object. Each column, variable and expression has related data type in SQL. You would use these data types while
More informationLecture 2: Introduction to SQL
Lecture 2: Introduction to SQL Lecture 2 Announcements! 1. If you still have Jupyter trouble, let us know! 2. Enroll to Piazza!!! 3. People are looking for groups. Team up! 4. Enrollment should be finalized
More informationRelational Database Systems Part 01. Karine Reis Ferreira
Relational Database Systems Part 01 Karine Reis Ferreira karine@dpi.inpe.br Aula da disciplina Computação Aplicada I (CAP 241) 2016 Database System Database: is a collection of related data. represents
More informationAccess Intermediate
Access 2010 - Intermediate 103-134 Advanced Queries Quick Links Overview Pages AC116 AC117 Selecting Fields Pages AC118 AC119 AC122 Sorting Results Pages AC125 AC126 Specifying Criteria Pages AC132 AC134
More informationCHAPTER4 CONSTRAINTS
CHAPTER4 CONSTRAINTS LEARNING OBJECTIVES After completing this chapter, you should be able to do the following: Explain the purpose of constraints in a table Distinguish among PRIMARY KEY, FOREIGN KEY,
More informationReview -Chapter 4. Review -Chapter 5
Review -Chapter 4 Entity relationship (ER) model Steps for building a formal ERD Uses ER diagrams to represent conceptual database as viewed by the end user Three main components Entities Relationships
More information1) Introduction to SQL
1) Introduction to SQL a) Database language enables users to: i) Create the database and relation structure; ii) Perform insertion, modification and deletion of data from the relationship; and iii) Perform
More informationOperating systems fundamentals - B07
Operating systems fundamentals - B07 David Kendall Northumbria University David Kendall (Northumbria University) Operating systems fundamentals - B07 1 / 33 What is SQL? Structured Query Language Used
More informationRelational Database Management Systems for Epidemiologists: SQL Part I
Relational Database Management Systems for Epidemiologists: SQL Part I Outline SQL Basics Retrieving Data from a Table Operators and Functions What is SQL? SQL is the standard programming language to create,
More informationDS Introduction to SQL Part 1 Single-Table Queries. By Michael Hahsler based on slides for CS145 Introduction to Databases (Stanford)
DS 1300 - Introduction to SQL Part 1 Single-Table Queries By Michael Hahsler based on slides for CS145 Introduction to Databases (Stanford) Overview 1. SQL introduction & schema definitions 2. Basic single-table
More informationTable of Contents. PDF created with FinePrint pdffactory Pro trial version
Table of Contents Course Description The SQL Course covers relational database principles and Oracle concepts, writing basic SQL statements, restricting and sorting data, and using single-row functions.
More informationChapter-14 SQL COMMANDS
Chapter-14 SQL COMMANDS What is SQL? Structured Query Language and it helps to make practice on SQL commands which provides immediate results. SQL is Structured Query Language, which is a computer language
More informationA Flat file database. Problems with a flat file database (data redundancy)
Data capture Before you can create a database, you need to collect data. This is known as data capture. One of the most common ways is to use and optical mark reader (OMR). An OMR sensor is used for marking
More informationUNIT-IV (Relational Database Language, PL/SQL)
UNIT-IV (Relational Database Language, PL/SQL) Section-A (2 Marks) Important questions 1. Define (i) Primary Key (ii) Foreign Key (iii) unique key. (i)primary key:a primary key can consist of one or more
More informationThe Structured Query Language Get Started
The Structured Query Language Get Started Himadri Barman 0. Prerequisites: A database is an organized collection of related data that can easily be retrieved and used. By data, we mean known facts that
More informationMariaDB Crash Course. A Addison-Wesley. Ben Forta. Upper Saddle River, NJ Boston. Indianapolis. Singapore Mexico City. Cape Town Sydney.
MariaDB Crash Course Ben Forta A Addison-Wesley Upper Saddle River, NJ Boston Indianapolis San Francisco New York Toronto Montreal London Munich Paris Madrid Cape Town Sydney Tokyo Singapore Mexico City
More informationChapter 9: MySQL for Server-Side Data Storage
Chapter 9: MySQL for Server-Side Data Storage General Notes on the Slides for This Chapter In many slides you will see webbook as a database name. That was the orginal name of our database. For this second
More informationLecture 3 SQL. Shuigeng Zhou. September 23, 2008 School of Computer Science Fudan University
Lecture 3 SQL Shuigeng Zhou September 23, 2008 School of Computer Science Fudan University Outline Basic Structure Set Operations Aggregate Functions Null Values Nested Subqueries Derived Relations Views
More informationMySQL. Prof.Sushila Aghav
MySQL Prof.Sushila Aghav Introduction SQL is a standard language for storing, manipulating and retrieving data in databases. SQL is a part of many relational database management systems like: MySQL, SQL
More information3/3/2008. Announcements. A Table with a View (continued) Fields (Attributes) and Primary Keys. Video. Keys Primary & Foreign Primary/Foreign Key
Announcements Quiz will cover chapter 16 in Fluency Nothing in QuickStart Read Chapter 17 for Wednesday Project 3 3A due Friday before 11pm 3B due Monday, March 17 before 11pm A Table with a View (continued)
More informationToday Learning outcomes LO2
2015 2016 Phil Smith Today Learning outcomes LO2 On successful completion of this unit you will: 1. Be able to design and implement relational database systems. 2. Requirements. 3. User Interface. I am
More informationMySQL. Rheinisch-Westfälische Technische Hochschule Aachen Data Management and Data Exploration Group Univ.-Prof. Dr. rer. nat.
Rheinisch-Westfälische Technische Hochschule Aachen Data Management and Data Exploration Group Univ.-Prof. Dr. rer. nat. Thomas Seidl Pro Seminar MySQL Student: Mohamed El Sherif June 2012 Supervision:
More informationBasic SQL. Dr Fawaz Alarfaj. ACKNOWLEDGEMENT Slides are adopted from: Elmasri & Navathe, Fundamentals of Database Systems MySQL Documentation
Basic SQL Dr Fawaz Alarfaj Al Imam Mohammed Ibn Saud Islamic University ACKNOWLEDGEMENT Slides are adopted from: Elmasri & Navathe, Fundamentals of Database Systems MySQL Documentation MIDTERM EXAM 2 Basic
More informationChapter 13 : Informatics Practices. Class XI ( As per CBSE Board) SQL Commands. New Syllabus Visit : python.mykvs.in for regular updates
Chapter 13 : Informatics Practices Class XI ( As per CBSE Board) SQL Commands New Syllabus 2018-19 SQL SQL is an acronym of Structured Query Language.It is a standard language developed and used for accessing
More informationChapter 4. Basic SQL. Copyright 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley
Chapter 4 Basic SQL Copyright 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 4 Outline SQL Data Definition and Data Types Specifying Constraints in SQL Basic Retrieval Queries
More information8) A top-to-bottom relationship among the items in a database is established by a
MULTIPLE CHOICE QUESTIONS IN DBMS (unit-1 to unit-4) 1) ER model is used in phase a) conceptual database b) schema refinement c) physical refinement d) applications and security 2) The ER model is relevant
More informationPhysical Design of Relational Databases
Physical Design of Relational Databases Chapter 8 Class 06: Physical Design of Relational Databases 1 Physical Database Design After completion of logical database design, the next phase is the design
More informationDatabase Systems. S. Adams. Dilbert. Available: Hans-Petter Halvorsen
Database Systems S. Adams. Dilbert. Available: http://dilbert.com Hans-Petter Halvorsen Old fashion Database (Data-storage) Systems Not too long ago, this was the only data-storage device most companies
More informationINTRODUCTION TO MYSQL MySQL : It is an Open Source RDBMS Software that uses Structured Query Language. It is available free of cost. Key Features of MySQL : MySQL Data Types: 1. High Speed. 2. Ease of
More informationEGCI 321: Database Systems. Dr. Tanasanee Phienthrakul
1 EGCI 321: Database Systems Dr. Tanasanee Phienthrakul 2 Chapter 10 Data Definition Language (DDL) 3 Basic SQL SQL language Considered one of the major reasons for the commercial success of relational
More informationLecture 6 - More SQL
CMSC 461, Database Management Systems Spring 2018 Lecture 6 - More SQL These slides are based on Database System Concepts book and slides, 6, and the 2009/2012 CMSC 461 slides by Dr. Kalpakis Dr. Jennifer
More informationRelational Database Languages
Relational Database Languages Tuple relational calculus ALPHA (Codd, 1970s) QUEL (based on ALPHA) Datalog (rule-based, like PROLOG) Domain relational calculus QBE (used in Access) History of SQL Standards:
More informationIndex. Bitmap Heap Scan, 156 Bitmap Index Scan, 156. Rahul Batra 2018 R. Batra, SQL Primer,
A Access control, 165 granting privileges to users general syntax, GRANT, 170 multiple privileges, 171 PostgreSQL, 166 169 relational databases, 165 REVOKE command, 172 173 SQLite, 166 Aggregate functions
More informationHistory of SQL. Relational Database Languages. Tuple relational calculus ALPHA (Codd, 1970s) QUEL (based on ALPHA) Datalog (rule-based, like PROLOG)
Relational Database Languages Tuple relational calculus ALPHA (Codd, 1970s) QUEL (based on ALPHA) Datalog (rule-based, like PROLOG) Domain relational calculus QBE (used in Access) History of SQL Standards:
More informationDOWNLOAD PDF INSIDE RELATIONAL DATABASES
Chapter 1 : Inside Microsoft's Cosmos DB ZDNet Inside Relational Databases is an excellent introduction to the topic and a very good resource. I read the book cover to cover and found the authors' insights
More informationMTA Database Administrator Fundamentals Course
MTA Database Administrator Fundamentals Course Session 1 Section A: Database Tables Tables Representing Data with Tables SQL Server Management Studio Section B: Database Relationships Flat File Databases
More informationAccess Intermediate
Access 2013 - Intermediate 103-134 Advanced Queries Quick Links Overview Pages AC124 AC125 Selecting Fields Pages AC125 AC128 AC129 AC131 AC238 Sorting Results Pages AC131 AC136 Specifying Criteria Pages
More informationSQL Data Manipulation Language. Lecture 5. Introduction to SQL language. Last updated: December 10, 2014
Lecture 5 Last updated: December 10, 2014 Throrought this lecture we will use the following database diagram Inserting rows I The INSERT INTO statement enables inserting new rows into a table. The basic
More informationAdvanced SQL Tribal Data Workshop Joe Nowinski
Advanced SQL 2018 Tribal Data Workshop Joe Nowinski The Plan Live demo 1:00 PM 3:30 PM Follow along on GoToMeeting Optional practice session 3:45 PM 5:00 PM Laptops available What is SQL? Structured Query
More informationSilberschatz, Korth and Sudarshan See for conditions on re-use
Chapter 3: SQL Database System Concepts, 5th Ed. See www.db-book.com for conditions on re-use Chapter 3: SQL Data Definition Basic Query Structure Set Operations Aggregate Functions Null Values Nested
More informationSlides by: Ms. Shree Jaswal
Slides by: Ms. Shree Jaswal Overview of SQL, Data Definition Commands, Set operations, aggregate function, null values, Data Manipulation commands, Data Control commands, Views in SQL, Complex Retrieval
More informationSQL DATA DEFINITION: KEY CONSTRAINTS. CS121: Relational Databases Fall 2017 Lecture 7
SQL DATA DEFINITION: KEY CONSTRAINTS CS121: Relational Databases Fall 2017 Lecture 7 Data Definition 2 Covered most of SQL data manipulation operations Continue exploration of SQL data definition features
More informationTHE RELATIONAL DATABASE MODEL
THE RELATIONAL DATABASE MODEL Introduction to relational DB Basic Objects of relational model Properties of relation Representation of ER model to relation Keys Relational Integrity Rules Functional Dependencies
More informationCS121 MIDTERM REVIEW. CS121: Relational Databases Fall 2017 Lecture 13
CS121 MIDTERM REVIEW CS121: Relational Databases Fall 2017 Lecture 13 2 Before We Start Midterm Overview 3 6 hours, multiple sittings Open book, open notes, open lecture slides No collaboration Possible
More information