Introduction to SQL for Data Scientists
|
|
|
- Jayson Pearson
- 10 years ago
- Views:
Transcription
1 Introduction to SQL for Data Scientists Ben O. Smith College of Business Administration University of Nebraska at Omaha Learning Objectives By the end of this document you will learn: 1. How to perform basic SQL commands 2. Understand the difference between left, right and full joins 3. Understand groupings and how they connect to aggregation functions 4. Understand data type basics 5. How to perform basic subqueries 1 Introduction In the information sciences, we commonly have data spread across multiple data sets or database sources. Thankfully, most database servers have an agreed upon a standard format to interact, merge and answer questions with that data: SQL (Structured Query Language). While subtle distinctions exists between database systems (SQL Server, SQLite, MySQL, Oracle and others), SQL is (mostly) a portable skill across server platforms. 1.1 Tables and Data Types In most cases, you will be interacting with or creating tables of data. Each column in a table has a specific data type. These types not only indicate how the data is stored, but how queries (questions you ask) are executed. Let s suppose you are examining student data with three simple tables. [email protected] 1
2 student data table term gpa data table degrees data table Column Name Data Type Column Name Data Type Column Name Data Type id* name Integer Text id* term* gpa Integer Integer Float id* term degree* Integer Integer Char(5) * Indicates primary key of the table Amongst the seven columns there are four different data types: integer, float, char and text. Integer is arguably the simplest form of data a computer can store (ignoring booleans and tiny storage methods which are just variations on the integer). Integers are stored by simply translating the number to binary. This means that a 32 bit unsigned integer can store any number between 0 and 4, 294, 967, 295 (2 32 1). Because of its very efficient method of storage, searching, ordering and grouping integers is almost always the best option (assuming you have an option). A float is simply an integer with some part of the number indicating a position of the decimal place. For instance, traditionally in a 32 bit float, 24 bits are dedicated to the number itself (i.e. the integer) while the remaining bits are used to describe the position of the decimal place. For the purposes of database use, one should understand two basic ideas about floating points: they are an efficient form of storage, but not as good as integers and if you perform mathematical operations using both integers and floats all of the data will be converted to floats to execute the task. Chars are a fixed-length string of text. For instance, char(5) would store 5 characters. Computers can t actually store characters directly, so something called a character map is used. So, suppose you have 256 different characters in an alphabet (which is generally considered the minimum), you could have a stream of ones and zeros stored somewhere where the stream is divided into groups of 8 (this would be an 8 bit character set). Under these conditions, each letter you store would take 8 bits of storage (so a char(5) would take 40 bits per row). In a fixed length text stream environment, the entire fixed length is stored even if only part of it is used. While the text datatype stores each character the same way a char does, it doesn t have a predefined fixed length. So, there is two options: each row could be of differing lengths (this is what varchar does), or the data in this column is stored separate from the table (which is what text does). Both have bad performance results. If each row is of varying length, then aggregation 2
3 functions and groupings are far slower. But storing the data away from table isn t good either as that means searching involves a bunch of redirection operations. It is obviously important to store text data in databases, but you should always be clear on what the performance implications are, especially as you start performing joins and subqueries Primary Keys Every row should have a unique value that identifies it known as a primary key (which is a type of index). Often times this is a single, non-repeating integer (as is the case with the student data table), but it doesn t have to be: as long as the combination of columns describe a unique value. In general, accessing a row by its primary key is the fastest method. 1.2 Data To assist with our exploration of the SQL language we will define our data: id student name 1 Edith Warton 2 Dorian Gray 3 Ophelia 4 Henry James 5 Harper Lee term gpa id term gpa degrees id term degree EconS MathS CompS EngLT While your datasets will likely be very large, in the process of learning the language it is usually good to start with something that you can visually see the answer. 2 Select A select statement (which is a form of query) has three basic parts: what do want, where is it from and under what conditions. So an extremely basic command might be: 1 SELECT s. i d AS id, s. name AS name 3
4 3 WHERE s. i d =1; Which results in a single row: id name 1 Edith Warton So what s happening here? We re grabbing the id and name data (SELECT s.id AS id, s.name AS name) from the student table (which we are renaming s using the AS statement FROM student AS s) where the id column equals one (WHERE s.id=1 ). The condition (WHERE s.id=1 ) is actually executed first. Because id is the primary key, the database simply looks up the location of the row and pulls a single value (the rest of the rows are not examined). Now, let s suppose you want to attach the GPA of a specific term to these results. 1 SELECT s. i d AS id, s. name AS name, t. gpa AS gpa 3 JOIN term gpa AS t ON s. i d=t. i d 4 WHERE s. i d=1 AND t. term =2012; Which results in a single row: id name gpa 1 Edith Warton 3.51 Let s break this apart: there are actually two result sets that are then merged. The conditions on each table can be thought to be executed separately then joined on the on condition (the exact execution order is up the database optimizer). What happens if I do this? 1 SELECT s. i d AS id, s. name AS name, t. gpa AS gpa 3 JOIN term gpa AS t ON s. i d=t. i d 4 WHERE s. i d =1; Which results in a two rows: Now that s interesting, you might expect to get a single result, but because the results from term gpa result in two rows, both of which match the same row in student, when the two result 4
5 id name gpa 1 Edith Warton Edith Warton 3.51 sets are merged it results in a repeat of the student information. What if we remove the where condition entirely? What happens then: 1 SELECT s. i d AS id, s. name AS name, t. gpa AS gpa 3 JOIN term gpa AS t ON s. i d=t. i d ; id name gpa 1 Edith Warton Edith Warton Dorian Gray Dorian Gray Ophelia Henry James Henry James Henry James Harper Lee 2.99 As you can see, each record is repeated for each combination of rows that meet the criteria of the join. However, let s add another table, in this case degrees, where the id must mach the id in the student table and the term must mach the term gpa table. 1 SELECT s. i d AS id, s. name AS name, t. gpa AS gpa 3 JOIN term gpa AS t ON s. i d=t. i d 4 JOIN d e g r e e s AS d ON d. i d=s. i d AND t. term=d. term ; id name gpa 1 Edith Warton Ophelia Ophelia Henry James
6 That resulted in a lot less rows! But it makes sense: any student who didn t also exist in the degrees table (i.e. they didn t graduate), couldn t be merged with the results from the student and term gpa table. Also note that the fact that we aren t actually displaying information from the degrees table is not relevant to the merge process. 2.1 Left and Right Joins But sometimes you don t want to eliminate un-merged rows, instead you would prefer blanks when row can not be matched. This is where left and right joins come in. Consider: 1 SELECT s. i d AS id, s. name AS name, t. gpa AS gpa, d. d egree AS d egree 3 JOIN term gpa AS t ON s. i d=t. i d 4 LEFT JOIN d e g r e e s AS d ON d. i d=s. i d AND t. term=d. term ; id name gpa degree 1 Edith Warton Edith Warton 3.51 EconS 2 Dorian Gray Dorian Gray Ophelia 3.70 CompS 3 Ophelia 3.70 MathS 4 Henry James Henry James 3.21 EngLT 4 Henry James Harper Lee 2.99 This is seemingly the same criteria as before, but this time if it can t find something in the degrees table it simply attaches null values (instead of eliminating the row). The left part of the left join indicates that every row found on the left side of the join (proceeding the join) should be shown. A right join is simply the opposite 1. Often times you actually care about which values have null when you attempt to join. For instance, let s say you wanted to find all students who didn t graduate as well as their GPA: 1 SELECT s. i d AS id, s. name AS name, t. gpa AS gpa 1 While left and right joins are both in the SQL syntax, right joins are not included in all databases. Given they do the same thing (it is just a matter of code arrangement), you should use left joins. 6
7 3 JOIN term gpa AS t ON s. i d=t. i d 4 LEFT JOIN d e g r e e s AS d ON d. i d=s. i d AND t. term<=d. term 5 WHERE d. i d IS NULL; id name gpa 2 Dorian Gray Dorian Gray Henry James Harper Lee 2.99 So, what we ve got here is people that are enrolled, but have not graduated, by term. Note how Henry James is still listed because he has enrolled in a semester after his last degree. 2.2 Grouping Let s try to clean this last result up. Maybe I don t want each students GPA by term, maybe I want an average. I also might want one row to represent one student. 1 SELECT s. i d AS id, MAX( s. name ) AS name, AVG( t. gpa ) AS gpa 3 JOIN term gpa AS t ON s. i d=t. i d 4 LEFT JOIN d e g r e e s AS d ON d. i d=s. i d AND t. term<=d. term 5 WHERE d. i d IS NULL 6 GROUP BY s. i d ; id name gpa 2 Dorian Gray Henry James Harper Lee 2.99 The concept of grouping is that you have a result and you are going to group it on some criteria. Aggregation functions (e.g. AVG, MAX, SUM, COUNT ) work in conjunction with the group. So, when you use an aggregation function, it is giving you the average, sum, whatever that are rolled-up for that particular row. It also of note that you must use an aggregation function on any column in your select list that you are not grouping on. This makes sense: you don t need to use aggregation on a column where 7
8 you are grouping because they are all the same for each row (that s why they are grouped), but without the aggregation function on a non-grouped row, the database won t know which of the results for a given column/row to show. Admittedly, sometimes it looks a bit silly (as is the case with the MAX function, in the example, run on a string), but it is very consistent, which is what you want from a language. 2.3 Subquery Suppose for a moment that you wanted to get the inflation adjusted GPA of each student in the graduation term (we re assuming that GPA is inflated by 0.04 points per year) 2 : 1 SELECT s. i d AS id, MAX( s. name ) AS name, MIN(mGPA. gpa ) AS gpa 3 JOIN term gpa AS t ON s. i d=t. i d 4 JOIN d e g r e e s AS d ON d. i d=s. i d AND t. term<=d. term 5 JOIN ( 6 SELECT id, ( gpa (.04 ( term 2011) ) ) AS gpa, term 7 FROM term gpa 8 ) AS mgpa ON s. i d=mgpa. i d AND mgpa. term=d. term 9 GROUP BY s. i d ; id name gpa 1 Edith Warton Ophelia Henry James 3.17 This query involves a subquery, which is a query in its own right that is executed as a part of the larger query. In this case, the subquery is executed and produces a set of results that are then merged through the join process (much like if that data existed as a separate table). Subqueries don t have to be in any specific part of the main query. Let s say you you want to get the average GPA of each student and place it along with the students name: 1 SELECT id, name, ( 2 SELECT AVG( gpa ) 3 FROM term gpa 2 I m aware that this query could be constructed using a standard join, I ve constructed it in this form to demonstrate the use of a subquery 8
9 4 WHERE i d=s. i d 5 ) AS avg gpa 6 FROM student AS s 7 ORDER BY name ASC; id name avg gpa 2 Dorian Gray Edith Warton Harper Lee Henry James Ophelia 3.70 And you can have subqueries of subqueries. Let s suppose you are trying categorize the students based on their average GPAs: 1 SELECT id, name, ( 2 SELECT 3 CASE 4 WHEN avg gpa >=3.5 THEN 2 5 WHEN avg gpa <3.5 AND avg gpa >=3.0 THEN 1 6 ELSE 0 7 END AS gpa type FROM 8 ( 9 SELECT AVG( gpa ) AS avg gpa 10 FROM term gpa 11 WHERE i d=s. i d 12 ) AS a v g g p a t a b l e 13 ) AS gpa type 14 FROM student AS s 15 ORDER BY name ASC; id name gpa type 2 Dorian Gray 0 1 Edith Warton 1 5 Harper Lee 0 4 Henry James 1 3 Ophelia 2 So, subqueries are executed as if they are mathematical operations (from inside of the parentheticals out). So in the inner subquery we get the average GPA for that particular row, then we 9
10 classify it using as CASE statement which is returned to the main query. 2.4 Like and more complicated conditions Sometimes we would like to match part of a string. While this is a relatively slow operation, it is sometimes necessary. Suppose I m looking for a particular person in the data, but I only have their first name: 1 SELECT id, name 3 WHERE name LIKE Dorian% ; The character % states match anything of any length (and Like statements are not case sensitive in general). It is often useful to simply specify part of a string that can be different. 1 SELECT id, name 3 WHERE name LIKE Dor n% ; In this context, means match any one character (suppose you don t know the spelling of a name). You can use like conditions in very complicated settings. Let s say you want a list of graduating students with a high GPA or are in a science (assuming all of the science majors end in S ). 1 SELECT s. i d AS id, MAX( s. name ) AS name 3 JOIN d e g r e e s AS d ON d. i d=s. i d 4 WHERE ( 5 ( 6 SELECT AVG( gpa ) AS gpa 7 FROM term gpa WHERE s. i d=i d AND term<=d. term 8 ) >= OR 10 d. degree LIKE %S 11 ) 12 GROUP BY s. i d ; Henry James would appear in these results if the GPA requirement was adjusted down to something like
11 id name 1 Edith Warton 3 Ophelia 3 Indexes Indexes are a copy of a subset of a particular object s (e.g. table) data that is stored in a particular order. Indexes are commonly something called a b-tree, which is a generalization of the binomial search tree but allows for multiple child nodes. In the context of this document, we ll focus on how to think about indexes instead of how they exactly work. Imagine a library with a card catalogue containing small amounts of information about each book (namely the book name and the authors). They are also in a specific order and reference the location of the real data in the books. A database index can be thought of much in this way. An index can be on any one or more columns. This includes text columns (though you generally index a few characters per row instead of the entire column; which is what you do on numeric columns if it is not obvious to you why, please reread section 1.1). Let s suppose their is a multicolumn index on (term, gpa, id) in the term gpa table and we run the following query: 1 SELECT t. i d AS id, t. gpa AS gpa 2 FROM term gpa AS t 3 WHERE t. term=2011 AND t. gpa > GROUP BY t. i d ; Ok, so the database is able to use the first two columns of the index to satisfy the where condition and use the third to satisfy the group by. Note that the order is important: the where condition is executed first, so those columns must be the first items in the index (followed by group by and order by). So, if the multicolumn index was (term, id, gpa), it would still be used to satisfy the term condition but the database would resort to scanning the remaining rows to examine the gpa and group the results. However, (term, id, gpa) would be perfect for something like this: 11
12 1 SELECT t. i d AS id, t. gpa AS gpa 2 FROM term gpa AS t 3 WHERE t. term > GROUP BY t. id, t. gpa ; Or something like this: 1 SELECT t. i d AS id, t. gpa AS gpa 2 FROM term gpa AS t 3 WHERE t. term > ORDER BY t. i d ASC, t. gpa DESC; That is, as long as the order of the columns matches the order of execution, the index will be of some use to the database. However, consider text content. Suppose we have an index on (name, id) in the student table and we execute the following from our discussion of like: 1 SELECT id, name 3 WHERE name LIKE Dorian% ; So, in this scenario, the index on name would be helpful to at least reduce the rows that would have to be examined by the database. However, consider this query: 1 SELECT id, name 3 WHERE name LIKE %Gray ; Now, the index becomes completely useless (the database will have to examine all rows). This is because the index is ordered by the text at the beginning of the column and % can match anything. 4 Creating Reusable Code Creating code that is reusable is extremely important, especially if you work with other people. Complete reusable code files allows other users, who may not understand your logic, to run your code while modifying one important aspect of the code. 12
13 Unfortunately, this is an area that the database providers have been less-good about providing a consistent interface across systems. Nonetheless, these concepts are similar and the syntax for MySQL and MS SQL are very similar, thus we will follow their syntax. Remember this example? 1 SELECT id, name, ( 2 SELECT 3 CASE 4 WHEN avg gpa >=3.5 THEN 2 5 WHEN avg gpa <3.5 AND avg gpa >=3.0 THEN 1 6 ELSE 0 7 END AS gpa type FROM 8 ( 9 SELECT AVG( gpa ) AS avg gpa 10 FROM term gpa 11 WHERE i d=s. i d 12 ) AS a v g g p a t a b l e 13 ) AS gpa type 14 FROM student AS s 15 ORDER BY name ASC; Now, I want you to suppose that you don t want every student, but just those enrolled in a specific semester. I m going to do this by joining the student table to the term gpa table. 1 SELECT s. i d AS id, s. name AS name, ( 2 SELECT 3 CASE 4 WHEN avg gpa >=3.5 THEN 2 5 WHEN avg gpa <3.5 AND avg gpa >=3.0 THEN 1 6 ELSE 0 7 END AS gpa type FROM 8 ( 9 SELECT AVG( gpa ) AS avg gpa 10 FROM term gpa 11 WHERE i d=s. i d AND term <= ) AS a v g g p a t a b l e 13 ) AS gpa type 14 FROM student AS s 15 JOIN term gpa AS t ON s. i d=t. i d 16 WHERE t. term=
14 17 ORDER BY s. name ASC; Great! But maybe this information has to be run every year. This is how you would solve that problem in MS SQL. Listing 1: Term Report.sql 1 INT; 2 3 = ; 4 5 / L i s t o f a c t i v e s t u d e n t s by GPA type / 6 7 SELECT s. i d AS id, s. name AS name, ( 8 SELECT 9 CASE 10 WHEN avg gpa >=3.5 THEN 2 11 WHEN avg gpa <3.5 AND avg gpa >=3.0 THEN 1 12 ELSE 0 13 END AS gpa type FROM 14 ( 15 SELECT AVG( gpa ) AS avg gpa 16 FROM term gpa 17 WHERE i d=s. i d AND term<=@term 18 ) AS a v g g p a t a b l e 19 ) AS gpa type 20 FROM student AS s 21 JOIN term gpa AS t ON s. i d=t. i d 22 WHERE t. term=@term 23 ORDER BY s. name ASC; Now, what s important to to see here is that we ve declared a variable (@term) at the top, defined its type and set it to a particular value. Then in the query we just type in that variable. This entire query can be saved as a some name.sql file (as noted by the title) that some other person can run. Further, you aren t limited to a single query. Suppose, in addition to students by GPA type, you want to get a list of students who are active in the next term and another list of students who are both not active in the next term and didn t graduate. 14
15 Listing 2: Complete Term Report.sql 1 INT; 2 3 = ; 4 5 / L i s t o f a c t i v e s t u d e n t s by GPA type / 6 7 SELECT s. i d AS id, s. name AS name, ( 8 SELECT 9 CASE 10 WHEN avg gpa >=3.5 THEN 2 11 WHEN avg gpa <3.5 AND avg gpa >=3.0 THEN 1 12 ELSE 0 13 END AS gpa type FROM 14 ( 15 SELECT AVG( gpa ) AS avg gpa 16 FROM term gpa 17 WHERE i d=s. i d AND term<=@term 18 ) AS a v g g p a t a b l e 19 ) AS gpa type 20 FROM student AS s 21 JOIN term gpa AS t ON s. i d=t. i d 22 WHERE t. term=@term 23 ORDER BY s. name ASC; / L i s t o f a c t i v e s t u d e n t s who are a c t i v e i n the next term / SELECT s. i d AS id, s. name AS name 28 FROM student AS s 29 JOIN term gpa AS t ON s. i d=t. i d AND t. term=@term 30 JOIN term gpa AS t t ON s. i d=t t. i d AND t t. term=(@term+1) 31 ORDER BY s. name ASC; / L i s t o f a c t i v e s t u d e n t s who are not a c t i v e i n the next term and didn t graduate / SELECT s. i d AS id, s. name AS name 36 FROM student AS s 37 JOIN term gpa AS t ON s. i d=t. i d AND t. term=@term 38 LEFT JOIN term gpa AS t t ON s. i d=t t. i d AND t t. term=(@term+1) 15
16 39 LEFT JOIN d e g r e e s AS d ON s. i d=d. i d AND d. term=@term 40 WHERE t t. i d IS NULL AND d. i d IS NULL 41 ORDER BY s. name ASC; Now, what s really handy about this is that another person can simply change the value and rerun this report (and the comments tell the person what each query does). 5 Further Reading 5.1 Online Resources 1. SQL Quick Reference ( quickref.asp) 2. MySQL Reference Manuals ( 3. MS SQL Reference ( 5.2 Books 1. SQL Pocket Guide ( 2. Learning SQL ( 3. High Performance MySQL ( Ben Smith, 2013: Licensed under Creative Commons Attribution
Microsoft Access 3: Understanding and Creating Queries
Microsoft Access 3: Understanding and Creating Queries In Access Level 2, we learned how to perform basic data retrievals by using Search & Replace functions and Sort & Filter functions. For more complex
COMP 5138 Relational Database Management Systems. Week 5 : Basic SQL. Today s Agenda. Overview. Basic SQL Queries. Joins Queries
COMP 5138 Relational Database Management Systems Week 5 : Basic COMP5138 "Relational Database Managment Systems" J. Davis 2006 5-1 Today s Agenda Overview Basic Queries Joins Queries Aggregate Functions
Financial Data Access with SQL, Excel & VBA
Computational Finance and Risk Management Financial Data Access with SQL, Excel & VBA Guy Yollin Instructor, Applied Mathematics University of Washington Guy Yollin (Copyright 2012) Data Access with SQL,
2874CD1EssentialSQL.qxd 6/25/01 3:06 PM Page 1 Essential SQL Copyright 2001 SYBEX, Inc., Alameda, CA www.sybex.com
Essential SQL 2 Essential SQL This bonus chapter is provided with Mastering Delphi 6. It is a basic introduction to SQL to accompany Chapter 14, Client/Server Programming. RDBMS packages are generally
SQL - QUICK GUIDE. Allows users to access data in relational database management systems.
http://www.tutorialspoint.com/sql/sql-quick-guide.htm SQL - QUICK GUIDE Copyright tutorialspoint.com What is SQL? SQL is Structured Query Language, which is a computer language for storing, manipulating
3.GETTING STARTED WITH ORACLE8i
Oracle For Beginners Page : 1 3.GETTING STARTED WITH ORACLE8i Creating a table Datatypes Displaying table definition using DESCRIBE Inserting rows into a table Selecting rows from a table Editing SQL buffer
SQL DATA DEFINITION: KEY CONSTRAINTS. CS121: Introduction to Relational Database Systems Fall 2015 Lecture 7
SQL DATA DEFINITION: KEY CONSTRAINTS CS121: Introduction to Relational Database Systems Fall 2015 Lecture 7 Data Definition 2 Covered most of SQL data manipulation operations Continue exploration of SQL
Cal Answers Analysis Training Part I. Creating Analyses in OBIEE
Cal Answers Analysis Training Part I Creating Analyses in OBIEE University of California, Berkeley March 2012 Table of Contents Table of Contents... 1 Overview... 2 Getting Around OBIEE... 2 Cal Answers
Database Administration with MySQL
Database Administration with MySQL Suitable For: Database administrators and system administrators who need to manage MySQL based services. Prerequisites: Practical knowledge of SQL Some knowledge of relational
How To Create A Table In Sql 2.5.2.2 (Ahem)
Database Systems Unit 5 Database Implementation: SQL Data Definition Language Learning Goals In this unit you will learn how to transfer a logical data model into a physical database, how to extend or
A Comparison of Database Query Languages: SQL, SPARQL, CQL, DMX
ISSN: 2393-8528 Contents lists available at www.ijicse.in International Journal of Innovative Computer Science & Engineering Volume 3 Issue 2; March-April-2016; Page No. 09-13 A Comparison of Database
Introduction to Python
WEEK ONE Introduction to Python Python is such a simple language to learn that we can throw away the manual and start with an example. Traditionally, the first program to write in any programming language
SQL. Short introduction
SQL Short introduction 1 Overview SQL, which stands for Structured Query Language, is used to communicate with a database. Through SQL one can create, manipulate, query and delete tables and contents.
Physical Design. Meeting the needs of the users is the gold standard against which we measure our success in creating a database.
Physical Design Physical Database Design (Defined): Process of producing a description of the implementation of the database on secondary storage; it describes the base relations, file organizations, and
So you want to create an Email a Friend action
So you want to create an Email a Friend action This help file will take you through all the steps on how to create a simple and effective email a friend action. It doesn t cover the advanced features;
sqlite driver manual
sqlite driver manual A libdbi driver using the SQLite embedded database engine Markus Hoenicka [email protected] sqlite driver manual: A libdbi driver using the SQLite embedded database engine
Information Systems SQL. Nikolaj Popov
Information Systems SQL Nikolaj Popov Research Institute for Symbolic Computation Johannes Kepler University of Linz, Austria [email protected] Outline SQL Table Creation Populating and Modifying
Advanced Query for Query Developers
for Developers This is a training guide to step you through the advanced functions of in NUFinancials. is an ad-hoc reporting tool that allows you to retrieve data that is stored in the NUFinancials application.
A Brief Introduction to MySQL
A Brief Introduction to MySQL by Derek Schuurman Introduction to Databases A database is a structured collection of logically related data. One common type of database is the relational database, a term
SQL Tables, Keys, Views, Indexes
CS145 Lecture Notes #8 SQL Tables, Keys, Views, Indexes Creating & Dropping Tables Basic syntax: CREATE TABLE ( DROP TABLE ;,,..., ); Types available: INT or INTEGER REAL or FLOAT CHAR( ), VARCHAR( ) DATE,
Advance DBMS. Structured Query Language (SQL)
Structured Query Language (SQL) Introduction Commercial database systems use more user friendly language to specify the queries. SQL is the most influential commercially marketed product language. Other
Database Query 1: SQL Basics
Database Query 1: SQL Basics CIS 3730 Designing and Managing Data J.G. Zheng Fall 2010 1 Overview Using Structured Query Language (SQL) to get the data you want from relational databases Learning basic
B.1 Database Design and Definition
Appendix B Database Design B.1 Database Design and Definition Throughout the SQL chapter we connected to and queried the IMDB database. This database was set up by IMDB and available for us to use. But
its not in the manual
its not in the manual An SQL Cookbook. The Back-story: I ve always liked the technical cookbook concept. For those of you who aren t familiar with the format, it s basically a loosely structured compendium
1 Structured Query Language: Again. 2 Joining Tables
1 Structured Query Language: Again So far we ve only seen the basic features of SQL. More often than not, you can get away with just using the basic SELECT, INSERT, UPDATE, or DELETE statements. Sometimes
Lecture 25: Database Notes
Lecture 25: Database Notes 36-350, Fall 2014 12 November 2014 The examples here use http://www.stat.cmu.edu/~cshalizi/statcomp/ 14/lectures/23/baseball.db, which is derived from Lahman s baseball database
Creating Database Tables in Microsoft SQL Server
Creating Database Tables in Microsoft SQL Server Microsoft SQL Server is a relational database server that stores and retrieves data for multi-user network-based applications. SQL Server databases are
MS ACCESS DATABASE DATA TYPES
MS ACCESS DATABASE DATA TYPES Data Type Use For Size Text Memo Number Text or combinations of text and numbers, such as addresses. Also numbers that do not require calculations, such as phone numbers,
Ad Hoc Advanced Table of Contents
Ad Hoc Advanced Table of Contents Functions... 1 Adding a Function to the Adhoc Query:... 1 Constant... 2 Coalesce... 4 Concatenate... 6 Add/Subtract... 7 Logical Expressions... 8 Creating a Logical Expression:...
SQL Programming. CS145 Lecture Notes #10. Motivation. Oracle PL/SQL. Basics. Example schema:
CS145 Lecture Notes #10 SQL Programming Example schema: CREATE TABLE Student (SID INTEGER PRIMARY KEY, name CHAR(30), age INTEGER, GPA FLOAT); CREATE TABLE Take (SID INTEGER, CID CHAR(10), PRIMARY KEY(SID,
Once the schema has been designed, it can be implemented in the RDBMS.
2. Creating a database Designing the database schema... 1 Representing Classes, Attributes and Objects... 2 Data types... 5 Additional constraints... 6 Choosing the right fields... 7 Implementing a table
Relational Database: Additional Operations on Relations; SQL
Relational Database: Additional Operations on Relations; SQL Greg Plaxton Theory in Programming Practice, Fall 2005 Department of Computer Science University of Texas at Austin Overview The course packet
Chapter 6: Physical Database Design and Performance. Database Development Process. Physical Design Process. Physical Database Design
Chapter 6: Physical Database Design and Performance Modern Database Management 6 th Edition Jeffrey A. Hoffer, Mary B. Prescott, Fred R. McFadden Robert C. Nickerson ISYS 464 Spring 2003 Topic 23 Database
Using SQL Server Management Studio
Using SQL Server Management Studio Microsoft SQL Server Management Studio 2005 is a graphical tool for database designer or programmer. With SQL Server Management Studio 2005 you can: Create databases
CS143 Notes: Views & Authorization
CS143 Notes: Views & Authorization Book Chapters (4th) Chapter 4.7, 6.5-6 (5th) Chapter 4.2, 8.6 (6th) Chapter 4.4, 5.3 Views What is a view? A virtual table created on top of other real tables Almost
Boats bid bname color 101 Interlake blue 102 Interlake red 103 Clipper green 104 Marine red. Figure 1: Instances of Sailors, Boats and Reserves
Tutorial 5: SQL By Chaofa Gao Tables used in this note: Sailors(sid: integer, sname: string, rating: integer, age: real); Boats(bid: integer, bname: string, color: string); Reserves(sid: integer, bid:
Microsoft Query, the helper application included with Microsoft Office, allows
3 RETRIEVING ISERIES DATA WITH MICROSOFT QUERY Microsoft Query, the helper application included with Microsoft Office, allows Office applications such as Word and Excel to read data from ODBC data sources.
Oracle Database: SQL and PL/SQL Fundamentals NEW
Oracle University Contact Us: + 38516306373 Oracle Database: SQL and PL/SQL Fundamentals NEW Duration: 5 Days What you will learn This Oracle Database: SQL and PL/SQL Fundamentals training delivers the
Query. Training and Participation Guide Financials 9.2
Query Training and Participation Guide Financials 9.2 Contents Overview... 4 Objectives... 5 Types of Queries... 6 Query Terminology... 6 Roles and Security... 7 Choosing a Reporting Tool... 8 Working
USC Marshall School of Business Academic Information Services. Excel 2007 Qualtrics Survey Analysis
USC Marshall School of Business Academic Information Services Excel 2007 Qualtrics Survey Analysis DESCRIPTION OF EXCEL ANALYSIS TOOLS AVAILABLE... 3 Summary of Tools Available and their Properties...
SQL Server An Overview
SQL Server An Overview SQL Server Microsoft SQL Server is designed to work effectively in a number of environments: As a two-tier or multi-tier client/server database system As a desktop database system
Intro to Databases. ACM Webmonkeys 2011
Intro to Databases ACM Webmonkeys 2011 Motivation Computer programs that deal with the real world often need to store a large amount of data. E.g.: Weather in US cities by month for the past 10 years List
Introduction to SQL and SQL in R. LISA Short Courses Xinran Hu
Introduction to SQL and SQL in R LISA Short Courses Xinran Hu 1 Laboratory for Interdisciplinary Statistical Analysis LISA helps VT researchers benefit from the use of Statistics Collaboration: Visit our
XEP-0043: Jabber Database Access
XEP-0043: Jabber Database Access Justin Kirby mailto:[email protected] xmpp:[email protected] 2003-10-20 Version 0.2 Status Type Short Name Retracted Standards Track Expose RDBM systems directly
Structured Query Language. Telemark University College Department of Electrical Engineering, Information Technology and Cybernetics
Telemark University College Department of Electrical Engineering, Information Technology and Cybernetics Structured Query Language HANS- PETTER HALVORSEN, 2014.03.03 Faculty of Technology, Postboks 203,
Cal Answers Analysis Training Part III. Advanced OBIEE - Dashboard Reports
Cal Answers Analysis Training Part III Advanced OBIEE - Dashboard Reports University of California, Berkeley March 2012 Table of Contents Table of Contents... 1 Overview... 2 Remember How to Create a Query?...
The join operation allows you to combine related rows of data found in two tables into a single result set.
(Web) Application Development With Ian Week 3 SQL with Multiple Tables Join The join operation allows you to combine related rows of data found in two tables into a single result set. It works similarly
Base Conversion written by Cathy Saxton
Base Conversion written by Cathy Saxton 1. Base 10 In base 10, the digits, from right to left, specify the 1 s, 10 s, 100 s, 1000 s, etc. These are powers of 10 (10 x ): 10 0 = 1, 10 1 = 10, 10 2 = 100,
Introduction to Microsoft Jet SQL
Introduction to Microsoft Jet SQL Microsoft Jet SQL is a relational database language based on the SQL 1989 standard of the American Standards Institute (ANSI). Microsoft Jet SQL contains two kinds of
Errors That Can Occur When You re Running a Report From Tigerpaw s SQL-based System (Version 9 and Above) Modified 10/2/2008
Errors That Can Occur When You re Running a Report From Tigerpaw s SQL-based System (Version 9 and Above) Modified 10/2/2008 1 Introduction The following is an explanation of some errors you might encounter
IT2305 Database Systems I (Compulsory)
Database Systems I (Compulsory) INTRODUCTION This is one of the 4 modules designed for Semester 2 of Bachelor of Information Technology Degree program. CREDITS: 04 LEARNING OUTCOMES On completion of this
- Eliminating redundant data - Ensuring data dependencies makes sense. ie:- data is stored logically
Normalization of databases Database normalization is a technique of organizing the data in the database. Normalization is a systematic approach of decomposing tables to eliminate data redundancy and undesirable
PeopleSoft Query Training
PeopleSoft Query Training Overview Guide Tanya Harris & Alfred Karam Publish Date - 3/16/2011 Chapter: Introduction Table of Contents Introduction... 4 Navigation of Queries... 4 Query Manager... 6 Query
We will learn the Python programming language. Why? Because it is easy to learn and many people write programs in Python so we can share.
LING115 Lecture Note Session #4 Python (1) 1. Introduction As we have seen in previous sessions, we can use Linux shell commands to do simple text processing. We now know, for example, how to count words.
More on SQL. Juliana Freire. Some slides adapted from J. Ullman, L. Delcambre, R. Ramakrishnan, G. Lindstrom and Silberschatz, Korth and Sudarshan
More on SQL Some slides adapted from J. Ullman, L. Delcambre, R. Ramakrishnan, G. Lindstrom and Silberschatz, Korth and Sudarshan SELECT A1, A2,, Am FROM R1, R2,, Rn WHERE C1, C2,, Ck Interpreting a Query
Technology Foundations. Conan C. Albrecht, Ph.D.
Technology Foundations Conan C. Albrecht, Ph.D. Overview 9. Human Analysis Reports 8. Create Reports 6. Import Data 7. Primary Analysis Data Warehouse 5. Transfer Data as CSV, TSV, or XML 1. Extract Data
SQL: Queries, Programming, Triggers
SQL: Queries, Programming, Triggers Chapter 5 Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke 1 R1 Example Instances We will use these instances of the Sailors and Reserves relations in
Oracle Database: SQL and PL/SQL Fundamentals
Oracle University Contact Us: 1.800.529.0165 Oracle Database: SQL and PL/SQL Fundamentals Duration: 5 Days What you will learn This course is designed to deliver the fundamentals of SQL and PL/SQL along
Example Instances. SQL: Queries, Programming, Triggers. Conceptual Evaluation Strategy. Basic SQL Query. A Note on Range Variables
SQL: Queries, Programming, Triggers Chapter 5 Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke 1 Example Instances We will use these instances of the Sailors and Reserves relations in our
Knocker main application User manual
Knocker main application User manual Author: Jaroslav Tykal Application: Knocker.exe Document Main application Page 1/18 U Content: 1 START APPLICATION... 3 1.1 CONNECTION TO DATABASE... 3 1.2 MODULE DEFINITION...
A table is a collection of related data entries and it consists of columns and rows.
CST 250 MySQL Notes (Source: www.w3schools.com) MySQL is the most popular open-source database system. What is MySQL? MySQL is a database. The data in MySQL is stored in database objects called tables.
DBMS / Business Intelligence, SQL Server
DBMS / Business Intelligence, SQL Server Orsys, with 30 years of experience, is providing high quality, independant State of the Art seminars and hands-on courses corresponding to the needs of IT professionals.
Encoding Text with a Small Alphabet
Chapter 2 Encoding Text with a Small Alphabet Given the nature of the Internet, we can break the process of understanding how information is transmitted into two components. First, we have to figure out
SQL Server Table Design - Best Practices
CwJ Consulting Ltd SQL Server Table Design - Best Practices Author: Andy Hogg Date: 20 th February 2015 Version: 1.11 SQL Server Table Design Best Practices 1 Contents 1. Introduction... 3 What is a table?...
White Paper. Blindfolded SQL Injection
White Paper In the past few years, SQL Injection attacks have been on the rise. The increase in the number of Database based applications, combined with various publications that explain the problem and
SQL: Queries, Programming, Triggers
SQL: Queries, Programming, Triggers CSC343 Introduction to Databases - A. Vaisman 1 R1 Example Instances We will use these instances of the Sailors and Reserves relations in our examples. If the key for
Fact Sheet In-Memory Analysis
Fact Sheet In-Memory Analysis 1 Copyright Yellowfin International 2010 Contents In Memory Overview...3 Benefits...3 Agile development & rapid delivery...3 Data types supported by the In-Memory Database...4
Chapter 5. SQL: Queries, Constraints, Triggers
Chapter 5 SQL: Queries, Constraints, Triggers 1 Overview: aspects of SQL DML: Data Management Language. Pose queries (Ch. 5) and insert, delete, modify rows (Ch. 3) DDL: Data Definition Language. Creation,
Instant SQL Programming
Instant SQL Programming Joe Celko Wrox Press Ltd. INSTANT Table of Contents Introduction 1 What Can SQL Do for Me? 2 Who Should Use This Book? 2 How To Use This Book 3 What You Should Know 3 Conventions
MS Access Lab 2. Topic: Tables
MS Access Lab 2 Topic: Tables Summary Introduction: Tables, Start to build a new database Creating Tables: Datasheet View, Design View Working with Data: Sorting, Filtering Help on Tables Introduction
SQL Query Evaluation. Winter 2006-2007 Lecture 23
SQL Query Evaluation Winter 2006-2007 Lecture 23 SQL Query Processing Databases go through three steps: Parse SQL into an execution plan Optimize the execution plan Evaluate the optimized plan Execution
Oracle Database: SQL and PL/SQL Fundamentals
Oracle University Contact Us: +966 12 739 894 Oracle Database: SQL and PL/SQL Fundamentals Duration: 5 Days What you will learn This Oracle Database: SQL and PL/SQL Fundamentals training is designed to
IT2304: Database Systems 1 (DBS 1)
: Database Systems 1 (DBS 1) (Compulsory) 1. OUTLINE OF SYLLABUS Topic Minimum number of hours Introduction to DBMS 07 Relational Data Model 03 Data manipulation using Relational Algebra 06 Data manipulation
Inquiry Formulas. student guide
Inquiry Formulas student guide NOTICE This documentation and the Axium software programs may only be used in accordance with the accompanying Ajera License Agreement. You may not use, copy, modify, or
Lecture 6. SQL, Logical DB Design
Lecture 6 SQL, Logical DB Design Relational Query Languages A major strength of the relational model: supports simple, powerful querying of data. Queries can be written intuitively, and the DBMS is responsible
MySQL for Beginners Ed 3
Oracle University Contact Us: 1.800.529.0165 MySQL for Beginners Ed 3 Duration: 4 Days What you will learn The MySQL for Beginners course helps you learn about the world's most popular open source database.
Databases Model the Real World. The Entity- Relationship Model. Conceptual Design. Steps in Database Design. ER Model Basics. ER Model Basics (Contd.
The Entity- Relationship Model R &G - Chapter 2 A relationship, I think, is like a shark, you know? It has to constantly move forward or it dies. And I think what we got on our hands is a dead shark. Woody
Setting up a basic database in Access 2007
Setting up a basic database in Access 2007 1. Open Access. This is the screen that you should see 2. Click on Blank database 3. Enter the name customer mailing list in the file name section (this will
SQL: joins. Practices. Recap: the SQL Select Command. Recap: Tables for Plug-in Cars
Recap: the SQL Select Command SQL: joins SELECT [DISTINCT] sel_expression [, sel_expression ] FROM table_references [WHERE condition] [GROUPBY column [,column ] [[HAVING condition]] [ORDER BY columns [ASC
INTEGRATING MICROSOFT DYNAMICS CRM WITH SIMEGO DS3
INTEGRATING MICROSOFT DYNAMICS CRM WITH SIMEGO DS3 Often the most compelling way to introduce yourself to a software product is to try deliver value as soon as possible. Simego DS3 is designed to get you
A basic create statement for a simple student table would look like the following.
Creating Tables A basic create statement for a simple student table would look like the following. create table Student (SID varchar(10), FirstName varchar(30), LastName varchar(30), EmailAddress varchar(30));
Migration Manager v6. User Guide. Version 1.0.5.0
Migration Manager v6 User Guide Version 1.0.5.0 Revision 1. February 2013 Content Introduction... 3 Requirements... 3 Installation and license... 4 Basic Imports... 4 Workspace... 4 1. Menu... 4 2. Explorer...
Microsoft Office Access 2007 Training
Mississippi College presents: Microsoft Office Access 2007 Training Course contents Overview: Fast, easy, simple Lesson 1: A new beginning Lesson 2: OK, back to work Lesson 3: Save your files in the format
not at all a manual simply a quick how-to-do guide
not at all a manual simply a quick how-to-do guide As a general rule, the GUI implemented by spatialite-gis is closely related to the one implemented by the companion app spatialite-gui So, if you are
MariaDB Cassandra interoperability
MariaDB Cassandra interoperability Cassandra Storage Engine in MariaDB Sergei Petrunia Colin Charles Who are we Sergei Petrunia Principal developer of CassandraSE, optimizer developer, formerly from MySQL
White Paper. PiLab Technology Performance Test, Deep Queries. pilab.pl
White Paper PiLab Technology Performance Test, Deep Queries pilab.pl Table of Content Forward... 3 Summary of Results... 3 Technical Introduction... 3 Hardware... 4 Disk read/write speed... 4 Network speed
Outline. SAS-seminar Proc SQL, the pass-through facility. What is SQL? What is a database? What is Proc SQL? What is SQL and what is a database
Outline SAS-seminar Proc SQL, the pass-through facility How to make your data processing someone else s problem What is SQL and what is a database Quick introduction to Proc SQL The pass-through facility
Informatica e Sistemi in Tempo Reale
Informatica e Sistemi in Tempo Reale Introduction to C programming Giuseppe Lipari http://retis.sssup.it/~lipari Scuola Superiore Sant Anna Pisa October 25, 2010 G. Lipari (Scuola Superiore Sant Anna)
WRITING EFFICIENT SQL. By Selene Bainum
WRITING EFFICIENT SQL By Selene Bainum About Me Extensive SQL & database development since 1995 ColdFusion Developer since 1996 Author & Speaker Co-Founder RiteTech LLC IT & Web Company in Washington,
Retrieving Data Using the SQL SELECT Statement. Copyright 2006, Oracle. All rights reserved.
Retrieving Data Using the SQL SELECT Statement Objectives After completing this lesson, you should be able to do the following: List the capabilities of SQL SELECT statements Execute a basic SELECT statement
Database Migration from MySQL to RDM Server
MIGRATION GUIDE Database Migration from MySQL to RDM Server A Birdstep Technology, Inc. Raima Embedded Database Division Migration Guide Published: May, 2009 Author: Daigoro F. Toyama Senior Software Engineer
1 Using a SQL Filter in Outlook 2002/2003 Views. 2 Defining the Problem The Task at Hand
1 Using a SQL Filter in Outlook 2002/2003 Views Those of you who have used Outlook for a while may have discovered the power of Outlook Views and use these on every folder to group, sort and filter your
Using Excel As A Database
Using Excel As A Database Access is a great database application, but let s face it sometimes it s just a bit complicated! There are a lot of times when it would be nice to have some of the capabilities
TrendWorX32 SQL Query Engine V9.2 Beta III
TrendWorX32 SQL Query Engine V9.2 Beta III Documentation (Preliminary November 2009) OPC Automation at your fingertips 1. Introduction TrendWorX32 Logger logs data to a database. You can use the TrendWorX32
Partitioning under the hood in MySQL 5.5
Partitioning under the hood in MySQL 5.5 Mattias Jonsson, Partitioning developer Mikael Ronström, Partitioning author Who are we? Mikael is a founder of the technology behind NDB
INTRODUCING AZURE SEARCH
David Chappell INTRODUCING AZURE SEARCH Sponsored by Microsoft Corporation Copyright 2015 Chappell & Associates Contents Understanding Azure Search... 3 What Azure Search Provides...3 What s Required to
Why MySQL beats MongoDB
SEARCH MARKETING EVOLVED Why MySQL beats MongoDB Searchmetrics in one big data scenario Suite Stephan Sommer-Schulz (Director Research) Searchmetrics Inc. 2011 The Challenge Backlink Database: Build a
database abstraction layer database abstraction layers in PHP Lukas Smith BackendMedia [email protected]
Lukas Smith database abstraction layers in PHP BackendMedia 1 Overview Introduction Motivation PDO extension PEAR::MDB2 Client API SQL syntax SQL concepts Result sets Error handling High level features
