Introduction to SQL Server and the Structure Query Language

Slides:



Advertisements
Similar presentations
N.G.Acharya & D.K.Marathe college Chembur-E, Mumbai-71
Advertisements

2010/11 : [1]Building Web Applications using MySQL and PHP (W1)MySQL Recap.
Copyright © by Royal Institute of Information Technology Introduction To Structured Query Language (SQL) 1.
Introduction to Structured Query Language (SQL)
Databases Lab 5 Further Select Statements. Functions in SQL There are many types of functions provided. The ones that are used most are: –Date and Time.
Structured Query Language Part I Chapter Three CIS 218.
Database Systems: Design, Implementation, and Management Eighth Edition Chapter 7 Introduction to Structured Query Language (SQL)
Databases Tutorial 2 Further Select Statements. Objectives for Week Data types Sort retrieved data Formatting output.
Concepts of Database Management Sixth Edition
1ISM - © 2010 Houman Younessi Lecture 3 Convener: Houman Younessi Information Systems Spring 2011.
DATABASES AND SQL. Introduction Relation: Relation means table(data is arranged in rows and columns) Domain : A domain is a pool of values appearing in.
Rationale Aspiring Database Developers should be able to efficiently query and maintain databases. This module will help students learn the Structured.
Relational DBs and SQL Designing Your Web Database (Ch. 8) → Creating and Working with a MySQL Database (Ch. 9, 10) 1.
Chapter 3 Single-Table Queries
 SQL stands for Structured Query Language.  SQL lets you access and manipulate databases.  SQL is an ANSI (American National Standards Institute) standard.
Database A collection of related data. Database Applications Banking: all transactions Airlines: reservations, schedules Universities: registration, grades.
HAP 709 – Healthcare Databases SQL Data Manipulation Language (DML) Updated Fall, 2009.
Chapter 10 Selected Single-Row Functions Oracle 10g: SQL.
CHAPTER:14 Simple Queries in SQL Prepared By Prepared By : VINAY ALEXANDER ( विनय अलेक्सजेंड़र ) PGT(CS),KV JHAGRAKHAND.
1 CS 430 Database Theory Winter 2005 Lecture 12: SQL DML - SELECT.
About the Presentations The presentations cover the objectives found in the opening of each chapter. All chapter objectives are listed in the beginning.
SQL: Data Manipulation Presented by Mary Choi For CS157B Dr. Sin Min Lee.
CPS120: Introduction to Computer Science Lecture 19 Introduction to SQL.
1 Single Table Queries. 2 Objectives  SELECT, WHERE  AND / OR / NOT conditions  Computed columns  LIKE, IN, BETWEEN operators  ORDER BY, GROUP BY,
SQL SQL Server : Overview SQL : Overview Types of SQL Database : Creation Tables : Creation & Manipulation Data : Creation & Manipulation Data : Retrieving.
Concepts of Database Management Seventh Edition
Oracle 11g: SQL Chapter 10 Selected Single-Row Functions.
6 1 Lecture 8: Introduction to Structured Query Language (SQL) J. S. Chou, P.E., Ph.D.
Concepts of Database Management Eighth Edition Chapter 3 The Relational Model 2: SQL.
1 DBS201: Introduction to Structure Query Language (SQL) Lecture 1.
Advanced SELECT Queries CS 146. Review: Retrieving Data From a Single Table Syntax: Limitation: Retrieves "raw" data Note the default formats… SELECT.
IFS Intro to Data Management Chapter 5 Getting More Than Simple Columns.
Database Fundamental & Design by A.Surasit Samaisut Copyrights : All Rights Reserved.
AL-MAAREFA COLLEGE FOR SCIENCE AND TECHNOLOGY INFO 232: DATABASE SYSTEMS CHAPTER 7 (Part II) INTRODUCTION TO STRUCTURED QUERY LANGUAGE (SQL) Instructor.
Lecture 8 – SQL Joins – assemble new views from existing tables INNER JOIN’s The Cartesian Product Theta Joins and Equi-joins Self Joins Natural Join.
Concepts of Database Management Seventh Edition Chapter 3 The Relational Model 2: SQL.
SQL Aggregation Oracle and ANSI Standard SQL Lecture 9.
1/18/00CSE 711 data mining1 What is SQL? Query language for structural databases (esp. RDB) Structured Query Language Originated from Sequel 2 by Chamberlin.
CMPT 258 Database Systems The Relationship Model (Chapter 3)
Single-Table Queries 2: Advanced Topics CS 320. Review: Retrieving Data From a Single Table Syntax: Limitation: Retrieves "raw" data SELECT field1, field2,
A Guide to SQL, Eighth Edition Chapter Four Single-Table Queries.
7 1 Database Systems: Design, Implementation, & Management, 7 th Edition, Rob & Coronel 7.6 Advanced Select Queries SQL provides useful functions that.
SQL: Structured Query Language It enables to create and operate on relational databases, which are sets of related information stored in tables. It is.
There’s a particular style to it… Rob Hatton
Retrieving Information Pertemuan 3 Matakuliah: T0413/Current Popular IT II Tahun: 2007.
Concepts of Database Management, Fifth Edition Chapter 3: The Relational Model 2: SQL.
1 ORACLE I 3 – SQL 1 Salim Phone: YM: talim_bansal.
Chapter 12 Introducing Databases. Objectives What a database is and which databases are typically used with ASP.NET pages What SQL is, how it looks, and.
SQL SQL Ayshah I. Almugahwi Maryam J. Alkhalifa
Creating Database Objects
SQL Query Getting to the data ……..
Relational Database Design
Chapter 10 Selected Single-Row Functions Oracle 10g: SQL
Prof: Dr. Shu-Ching Chen TA: Yimin Yang
Prof: Dr. Shu-Ching Chen TA: Hsin-Yu Ha
Chapter # 7 Introduction to Structured Query Language (SQL) Part II.
Chapter 4 Summary Query.
Prof: Dr. Shu-Ching Chen TA: Haiman Tian
Copyright © 2012 Pearson Education, Inc. Publishing as Prentice Hall
Database systems Lecture 3 – SQL + CRUD
Chapter 7 Introduction to Structured Query Language (SQL)
COP 2700 – Data Structures - SQL
Contents Preface I Introduction Lesson Objectives I-2
Query Functions.
Section 4 - Sorting/Functions
Database Management System
Trainer: Bach Ngoc Toan– TEDU Website:
Creating Database Objects
SQL (Structured Query Language)
Intermediate Query Structure and Development
Presentation transcript:

Introduction to SQL Server and the Structure Query Language Dave Valentine dkValz@comcast.net www.ingenioussql.com

Agenda What is SQL Server What is SQL Table, Columns, Rows SELECT FROM WHERE SQL Functions GROUP BY ORDER BY

About Dave MCP MCSA: SQL Server 2012 Database Architect / Database Developer Adjunct Professor @IngeniousSQL dkValz@comcast.net IngeniousSQL.com

What is a Database Collection of structured/organized data Typically stored on a computer or in the cloud Simple to Complex Small to Large What is stored in a database

RDBMS Relational Database Management System Relational Database Tables Rows Columns Popular RDBMS: SQL Server Oracle MySQL

SQL Structured Query Language ANSI Standard RDBMS independent SQL Flavors DDL – Data Definition Language DML – Data Manipulation Language

Tables Database constructs that store data Collection of related data Rows and Columns Spreadsheets

Columns Set of data definitions for data that is stored in a table Types Text VARCHAR, NVARCHAR, CHAR, NCHAR Numerical BIT, TINYINT, SMALLINT, INT, BIGINT, DECIMAL, FLOAT, MONEY Date DATETIME, DATE, TIME Fields Attributes

Rows Set of related data values stored in a table Single record in spreadsheet Tuple Record Address ID Address City State ZIP 22 1234 Music Ave Shakopee MN 11111 23 609 Freemont Street Las Vegas NV 22222 24 1850 Birch Street Wayzata 55555 25 1713 Dixon Drive Mahtomedi 44444 26 2121 SQL Lane Bemidji 33333

SELECT The SELECT statement returns data from a database table Data is returned in the form of a result set. Basic SELECT syntax SELECT Col1, Col2, … ColN FROM TableName; Col1, Col2, … ColN are the columns of a table TableName whose values you want to return. All the columns available in the table TableName can be returned using the syntax SELECT * FROM TableName Is SELECT * a good idea?

FROM Defines where the data will be retrieved in a SELECT statement Simple Complex Optional

WHERE Used to filter records in a dataset Basic WHERE syntax SELECT Col1, Col2, … ColN FROM TableName WHERE Col1 = [Some Value] Typically follows the FROM statement Simple Complex Optional

Comparison Operators Mathematical symbol to compare two expressions Primarily used in the WHERE clause Outcome yields a Boolean value Common Operators = Equal to > Greater than < Less than >= Greater than or equal to <= Less than or equal to <> Not equal to

Logical Operators Logical operators compare two or more conditions to filter data sets Yields Boolean values (True or False) SQL Common Operators NOT AND OR LIKE BETWEEN IN Truth Tables Operation Precedence

Truth Tables NOT TRUE FALSE   AND OR

Operator Precedence Operators at the top of this list are evaluated before an operators in the lower parts of this list. ~ *, /, % +, - =, >, <, >=, <=, <>, !=, !>, !< NOT AND ALL, ANY, BETWEEN, IN, LIKE, OR, SOME =

String Functions Built in functionality that can manipulate expressions Popular SQL Server String Functions: CONCAT Adds two or more strings together ( + ) LEFT Extracts a number of characters from a string (starting from left) LEN Returns the length of a string LOWER Converts a string to lower-case LTRIM Removes leading spaces from a string REPLACE Replaces all occurrences of a string within a string, with a new string REVERSE Reverses a string and returns the result RIGHT Extracts a number of characters from a string (starting from right) RTRIM Removes trailing spaces from a string SUBSTRING Extracts some characters from a string UPPER Converts a string to upper-case

Date Functions Built in functionality that manipulates date expressions Popular SQL Server String Functions GETDATE Returns the current database system date and time GETUTCDATE Returns the current database system UTC date and time DATEADD Adds a time/date interval to a date and then returns the date DATEDIFF Returns the difference between two dates DAY Returns the day of the month for a specified date MONTH Returns the month part for a specified date (1 to 12) YEAR Returns the Year part for a specified date .

Numerical Functions Built in functionality that aggregates numerical columns Popular SQL Server Numerical Functions ABS Returns the absolute value of a number POWER Returns the value of a number raised to the power of another number ROUND Rounds a number to a specified number of decimal places SQRT Returns the square root of a number SQUARE Returns the square of a number SUM Calculates the sum of a set of values AVG Returns the average value in a set of values COUNT Returns the number of records in a set of values MAX Returns the maximum value in a set of values MIN Returns the minimum value in a set of values

Product ID Name Number Sold 1 Adjustable Race 2500 2 Bearing Ball 2000 1000 3 BB Ball Bearing 800 500 4 Headset Ball Bearings 200 Headset Ball Bearings 600

GROUP BY Used to arrange identical rows of data into groups Groups are determined by the columns specified  Basic GROUP BY Syntax SELECT Col1, Col2 FROM TableName WHERE Col3 = [SomeValue] GROUP BY Col1, Col2 Typically follows the WHERE statement Commonly used with aggregating functions

ORDER BY Used to sort the result set in ascending or descending order Default is ascending Order is determined by the columns specified Basic ORDER BY Syntax SELECT Col1, Col2 FROM TableName WHERE Col3 = [SomeValue] GROUP BY Col1, Col2 ORDER BY Col1 ASC, Col2 DESC Typically one of the last statements in a query Caution with numerical data stored as characters

Table Joins Joining tables to single result set Found in the FROM section of a query Types INNER LEFT RIGHT CROSS FULL Basic JOIN Syntax SELECT Col1, Col2 FROM TableName1 tn1 INNER JOIN TableName2 tn2 ON tn1.Col1 = tn2.Col1 WHERE Col3 = [SomeValue] GROUP BY Col1, Col2

Advanced Functions ISNULL Returns the expression if it not null else the specified value COALESCE Returns the first non null value in the specified expression list CAST Casts an expression to another data type CONVERT Converts an expression to another data type Convert Dates to String https://docs.microsoft.com/en-us/sql/t-sql/functions/cast-and-convert-transact-sql

Summary SQL and SQL Server Table, Columns, Rows SELECT FROM WHERE SQL Functions GROUP BY ORDER BY

Questions Dave Valentine @ingeniousSQL ingeniousSQL.com linkedin.com/in/ingenioussql