SlideShare a Scribd company logo
1 of 19
Welcome!
Databases 101
SQL Server
What is a database?
Database
Table
Rows
● Multiple SQL Server
instances per server are
possible
● Multiple databases per
SQL server are possible
● “Multiple Drawers”
Tables can have indexes
...but what’s an index?
● Think of an index at the back of a text book.
● Indexed on some specific column or columns
● This is important for performance when looking
up information.
● Why am I telling you this?
Image Credit: http://media.datadirect.com/download/docs/sequelnk/odbc30/uindex.htm
Image Credit: http://4vector.com/thumb_data/afd-
Relational Databases
Hierarchical DBS Relational DBS
Image Credit: IBM http://www.ibm.com/developerworks/xml/library/x-matters8/index.html?ca=drs
SQL Server instances...who uses them?
Development
QA
Stage
Development QA
CS
Application
s
Production
APIs
Reporting
Ok, so what is SQL?
SQL = Structured Query Language
● A 4th generation programming language for managing data held in relational
database management systems
● Based on relational algebra concepts
● Good news: Powerful but easy to use
● Bad news: Powerful but easy to use
SQL command categories:
● DDL (Data Definition Language) - CREATE TABLE, etc.
● DCL (Data Control Language) - GRANT, REVOKE, etc.
● DML (Data Manipulation Language) - INSERT, UPDATE, DELETE, SELECT
We’ll focus on a small subset of SQL commands within the DML category:
SELECT commands.
Anatomy of a SELECT statement
SELECT FirstName, LastName
FROM People
WHERE ID = 1234567
SELECT FirstName, LastName
FROM People
WHERE Department_ID = 56789
AND (LastName LIKE ‘Smith’ OR LastName LIKE ‘Bradford’)
SELECT FirstName, LastName
FROM People
Anatomy of a SELECT statement
WHERE clause:
● Acts as a filter. Only give me results
where x = y
● Compares the ID column against a
value or another column
SELECT FirstName, LastName
FROM People
WHERE Department_ID = 56789
AND (LastName LIKE ‘Smith’ OR LastName LIKE ‘Bradford’)
Multiple WHERE
filters
OR operator = Either of
these conditions can be true
SELECT FirstName, LastName
FROM People
SELECT command
Column names
FROM tablename
SELECT FirstName, LastName
FROM People
WHERE ID = 1234567
Locking, Blocking, and Deadlocking
Locking
● Locking is the restriction of data access to some data in the database. What does that mean? If
I’m working on a row of data, you can’t change it.
● Tables are shared resources. Lots of processes may be reading, inserting, updating, or deleting
from them at the same time.
● Locking enables these processes to occur in a managed, orderly fashion (e.g. Bank Account:
deduction from person A blocks a deduction from person B until deduction from person A is
complete).
Blocking
● When a table is locked by one process and another process attempts to access it, blocking
occurs.
● Blocking is normal to a point...we need it to maintain integrity...but it can be dangerous.
● Ways we manage blocking
○ Avoid unnecessary blocking by writing better code
○ Keep an eye on blocking with a Block Monitor to alert us if a block is out of control
○ Use NOLOCK when doing ad hoc queries - very important!
Locking, Blocking, and Deadlocking
SELECT FirstName, LastName
FROM People WITH (NOLOCK)
WHERE ID = 1234567
Query hint
Using the ‘WITH (NOLOCK) hint means you are forfeiting your right to exclusive
access to that data, and changes may occur while you are viewing it.
Why is that a good thing?
Why could that be a bad thing?
Locking, Blocking, and Deadlocking
** Always use the WITH (NOLOCK) syntax on your queries! **
Locking, Blocking, and Deadlocking
Deadlocking
Image Credit: http://www.sqlxl.com/images/sql_deadlock_image001.pngImage Credit:
Bye, bye
Dos and Don’ts
Do
● Use COUNT() function to see how many rows you are working on, before blindly
selecting back massive amounts of data:
SELECT COUNT(ID)
FROM People WITH (NOLOCK)
Column name
● Use TOP clause to view a subset of rows if you are investigating the type of data
in a table:
SELECT TOP 10 *
FROM People WITH (NOLOCK)
● Use WHERE clause whenever possible to avoid needless row retrieval:
SELECT TOP 10 *
FROM People WITH (NOLOCK)
WHERE LastName LIKE ‘Jones’
Dos and Don’ts
Don’t
● Use SELECT * to pull back all data when all data is not needed
SELECT *
FROM People
● Use negative logic like: <>, NOT LIKE, NOT EXISTS
SELECT TOP 10 *
FROM People
WHERE LastName NOT LIKE ‘Jones’
● Join more than three or four tables when possible:
SELECT p.ID
FROM People p
INNER JOIN Department d ON d.Dept_ID = p.Dept_ID
INNER JOIN…
INNER JOIN…
WHERE LastName LIKE ‘Jones’
Joining Tables
The power of relational databases lies in the ability to join data between tables. Most tables will
have relationships to other tables in the database and following these ‘threads’ between tables
allows us to efficiently store and retrieve data:
SELECT pl.Title
FROM Publication pl WITH (NOLOCK)
INNER JOIN Publisher p WITH (NOLOCK) ON p.PubID = pl.PubID
WHERE p.PubAddress LIKE ‘%New York%’
Publisher
Author
Publication
Joining Tables
Avoid Cartesian products!!
A cartesian product occurs when you use CROSS JOIN without WHERE filters. This forces the
query to join EVERY row to EVERY OTHER row in the joined tables
SELECT pl.Title
FROM Publication pl WITH (NOLOCK)
CROSS JOIN Publisher p WITH (NOLOCK)
WHERE p.PubAddress LIKE ‘%New York%’---------------------------------------------------
Stored Procedures
● Stored procedures = encapsulated code
● They are like tiny little applications - they contain SQL code that, when called, will run
the same way everytime
● Example:
Stored Procedure:
cs_EmployeeNames
Stored Procedure code:
Select FirstName, LastName
FROM People
This...
EXEC cs_EmployeeNames
...gives you the same results as this
Select FirstName, LastName
FROM People
Stored Procedures
Stored procedure auditing
● Tracks who ran what stored procedure
● What parameters where passed in (in other words, for which client was the sp run?)
● When it was run
Image Credit: http://www.keepcalm-o-matic.co.uk/p/big-brother-is-watching-you-13/
Data Policy
● Do not read/interpret data for your own personal use
● Be VERY conscientious of how you communicate data back and forth to customers. Our cs Chat is secure, but email is
not...never pass sensitive data via email, other IM clients, fax, etc. SFTP is the only acceptable way to pass sensitive data.
● Do not share customer data across customer boundaries - be careful of even off handed comments on the phone (Oh, your
fill rate is this but so-and-so is that, etc.)
● Do not take data home or outside of company controlled devices (e.g. your laptop) unless absolutely necessary to complete
your work. This includes thumb drives, printed material, etc.
● Be absolutely certain the client you are sharing data with is who you think it is. This is especially tricky over the phone. If
unsure, end the conversation and call them back at the verified contact number to ensure you are speaking with the correct
person.
● Do not share usernames and passwords. Ever. (This includes SQL users, PCs, Customer data, etc.)
● Do not log in with your credential for someone else. Ever.
● This can seem innocuous, but you are liable for what they do under your credentials.
● Check with IT before storing client or company data anywhere outside of company approved devices or drives (eg. Google
docs, Evernote, etc.) This is very tightly controlled.
Don’t be afraid of the DBAs
And we’re normal.
Really.
No, seriously.
We’re here to help.

More Related Content

Similar to Databases 101

How to build data accessibility for everyone
How to build data accessibility for everyoneHow to build data accessibility for everyone
How to build data accessibility for everyoneKaren Hsieh
 
Dirty Data? Clean it up! - Rocky Mountain DataCon 2016
Dirty Data? Clean it up! - Rocky Mountain DataCon 2016Dirty Data? Clean it up! - Rocky Mountain DataCon 2016
Dirty Data? Clean it up! - Rocky Mountain DataCon 2016Dan Lynn
 
TBBUG - Deep Dive (Part 1) - 2022Nov29.pdf
TBBUG - Deep Dive (Part 1) - 2022Nov29.pdfTBBUG - Deep Dive (Part 1) - 2022Nov29.pdf
TBBUG - Deep Dive (Part 1) - 2022Nov29.pdfParesh Yadav
 
Graylog Engineering - Design Your Architecture
Graylog Engineering - Design Your ArchitectureGraylog Engineering - Design Your Architecture
Graylog Engineering - Design Your ArchitectureGraylog
 
Ledingkart Meetup #2: Scaling Search @Lendingkart
Ledingkart Meetup #2: Scaling Search @LendingkartLedingkart Meetup #2: Scaling Search @Lendingkart
Ledingkart Meetup #2: Scaling Search @LendingkartMukesh Singh
 
RESTful services on IBM Domino/XWork
RESTful services on IBM Domino/XWorkRESTful services on IBM Domino/XWork
RESTful services on IBM Domino/XWorkJohn Dalsgaard
 
Rapid Data Analytics @ Netflix
Rapid Data Analytics @ NetflixRapid Data Analytics @ Netflix
Rapid Data Analytics @ NetflixData Con LA
 
Rapid Data Analytics @ Netflix
Rapid Data Analytics @ NetflixRapid Data Analytics @ Netflix
Rapid Data Analytics @ NetflixMonisha Kanoth
 
Bank Question Solution-ADBA Previous Year Question for AP, ANE, AME, ADA, AE
Bank Question Solution-ADBA Previous Year Question for AP, ANE, AME, ADA, AEBank Question Solution-ADBA Previous Year Question for AP, ANE, AME, ADA, AE
Bank Question Solution-ADBA Previous Year Question for AP, ANE, AME, ADA, AEEngr. Md. Jamal Uddin Rayhan
 
Collecting and Making Sense of Diverse Data at WayUp
Collecting and Making Sense of Diverse Data at WayUpCollecting and Making Sense of Diverse Data at WayUp
Collecting and Making Sense of Diverse Data at WayUpHarlan Harris
 
Randomizing Data With SQL Server
Randomizing Data With SQL ServerRandomizing Data With SQL Server
Randomizing Data With SQL ServerWally Pons
 
Agile Data: Building Hadoop Analytics Applications
Agile Data: Building Hadoop Analytics ApplicationsAgile Data: Building Hadoop Analytics Applications
Agile Data: Building Hadoop Analytics ApplicationsDataWorks Summit
 
Pandas, Data Wrangling & Data Science
Pandas, Data Wrangling & Data SciencePandas, Data Wrangling & Data Science
Pandas, Data Wrangling & Data ScienceKrishna Sankar
 
Active Data Stores at 30,000ft
Active Data Stores at 30,000ftActive Data Stores at 30,000ft
Active Data Stores at 30,000ftJeffrey Sica
 
Don't Build "Death Star" Security - O'Reilly Software Architecture Conference...
Don't Build "Death Star" Security - O'Reilly Software Architecture Conference...Don't Build "Death Star" Security - O'Reilly Software Architecture Conference...
Don't Build "Death Star" Security - O'Reilly Software Architecture Conference...David Timothy Strauss
 
Database workshop - Encode | Bhuvan Gandhi | Vishwas Ganatra
Database workshop - Encode | Bhuvan Gandhi | Vishwas GanatraDatabase workshop - Encode | Bhuvan Gandhi | Vishwas Ganatra
Database workshop - Encode | Bhuvan Gandhi | Vishwas GanatraBhuvan Gandhi
 
Data Science Folk Knowledge
Data Science Folk KnowledgeData Science Folk Knowledge
Data Science Folk KnowledgeKrishna Sankar
 
Data massage: How databases have been scaled from one to one million nodes
Data massage: How databases have been scaled from one to one million nodesData massage: How databases have been scaled from one to one million nodes
Data massage: How databases have been scaled from one to one million nodesUlf Wendel
 

Similar to Databases 101 (20)

Data masking a developer's guide
Data masking a developer's guideData masking a developer's guide
Data masking a developer's guide
 
How to build data accessibility for everyone
How to build data accessibility for everyoneHow to build data accessibility for everyone
How to build data accessibility for everyone
 
Dirty Data? Clean it up! - Rocky Mountain DataCon 2016
Dirty Data? Clean it up! - Rocky Mountain DataCon 2016Dirty Data? Clean it up! - Rocky Mountain DataCon 2016
Dirty Data? Clean it up! - Rocky Mountain DataCon 2016
 
TBBUG - Deep Dive (Part 1) - 2022Nov29.pdf
TBBUG - Deep Dive (Part 1) - 2022Nov29.pdfTBBUG - Deep Dive (Part 1) - 2022Nov29.pdf
TBBUG - Deep Dive (Part 1) - 2022Nov29.pdf
 
Graylog Engineering - Design Your Architecture
Graylog Engineering - Design Your ArchitectureGraylog Engineering - Design Your Architecture
Graylog Engineering - Design Your Architecture
 
Ledingkart Meetup #2: Scaling Search @Lendingkart
Ledingkart Meetup #2: Scaling Search @LendingkartLedingkart Meetup #2: Scaling Search @Lendingkart
Ledingkart Meetup #2: Scaling Search @Lendingkart
 
RESTful services on IBM Domino/XWork
RESTful services on IBM Domino/XWorkRESTful services on IBM Domino/XWork
RESTful services on IBM Domino/XWork
 
Rapid Data Analytics @ Netflix
Rapid Data Analytics @ NetflixRapid Data Analytics @ Netflix
Rapid Data Analytics @ Netflix
 
Rapid Data Analytics @ Netflix
Rapid Data Analytics @ NetflixRapid Data Analytics @ Netflix
Rapid Data Analytics @ Netflix
 
Bank Question Solution-ADBA Previous Year Question for AP, ANE, AME, ADA, AE
Bank Question Solution-ADBA Previous Year Question for AP, ANE, AME, ADA, AEBank Question Solution-ADBA Previous Year Question for AP, ANE, AME, ADA, AE
Bank Question Solution-ADBA Previous Year Question for AP, ANE, AME, ADA, AE
 
Collecting and Making Sense of Diverse Data at WayUp
Collecting and Making Sense of Diverse Data at WayUpCollecting and Making Sense of Diverse Data at WayUp
Collecting and Making Sense of Diverse Data at WayUp
 
Randomizing Data With SQL Server
Randomizing Data With SQL ServerRandomizing Data With SQL Server
Randomizing Data With SQL Server
 
Agile Data: Building Hadoop Analytics Applications
Agile Data: Building Hadoop Analytics ApplicationsAgile Data: Building Hadoop Analytics Applications
Agile Data: Building Hadoop Analytics Applications
 
Pandas, Data Wrangling & Data Science
Pandas, Data Wrangling & Data SciencePandas, Data Wrangling & Data Science
Pandas, Data Wrangling & Data Science
 
Active Data Stores at 30,000ft
Active Data Stores at 30,000ftActive Data Stores at 30,000ft
Active Data Stores at 30,000ft
 
Don't Build "Death Star" Security - O'Reilly Software Architecture Conference...
Don't Build "Death Star" Security - O'Reilly Software Architecture Conference...Don't Build "Death Star" Security - O'Reilly Software Architecture Conference...
Don't Build "Death Star" Security - O'Reilly Software Architecture Conference...
 
Database workshop - Encode | Bhuvan Gandhi | Vishwas Ganatra
Database workshop - Encode | Bhuvan Gandhi | Vishwas GanatraDatabase workshop - Encode | Bhuvan Gandhi | Vishwas Ganatra
Database workshop - Encode | Bhuvan Gandhi | Vishwas Ganatra
 
Web Scraping Basics
Web Scraping BasicsWeb Scraping Basics
Web Scraping Basics
 
Data Science Folk Knowledge
Data Science Folk KnowledgeData Science Folk Knowledge
Data Science Folk Knowledge
 
Data massage: How databases have been scaled from one to one million nodes
Data massage: How databases have been scaled from one to one million nodesData massage: How databases have been scaled from one to one million nodes
Data massage: How databases have been scaled from one to one million nodes
 

Recently uploaded

Intro to Passkeys and the State of Passwordless.pptx
Intro to Passkeys and the State of Passwordless.pptxIntro to Passkeys and the State of Passwordless.pptx
Intro to Passkeys and the State of Passwordless.pptxFIDO Alliance
 
Introduction to FIDO Authentication and Passkeys.pptx
Introduction to FIDO Authentication and Passkeys.pptxIntroduction to FIDO Authentication and Passkeys.pptx
Introduction to FIDO Authentication and Passkeys.pptxFIDO Alliance
 
The Zero-ETL Approach: Enhancing Data Agility and Insight
The Zero-ETL Approach: Enhancing Data Agility and InsightThe Zero-ETL Approach: Enhancing Data Agility and Insight
The Zero-ETL Approach: Enhancing Data Agility and InsightSafe Software
 
Simplifying Mobile A11y Presentation.pptx
Simplifying Mobile A11y Presentation.pptxSimplifying Mobile A11y Presentation.pptx
Simplifying Mobile A11y Presentation.pptxMarkSteadman7
 
2024 May Patch Tuesday
2024 May Patch Tuesday2024 May Patch Tuesday
2024 May Patch TuesdayIvanti
 
WSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering DevelopersWSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering DevelopersWSO2
 
ADP Passwordless Journey Case Study.pptx
ADP Passwordless Journey Case Study.pptxADP Passwordless Journey Case Study.pptx
ADP Passwordless Journey Case Study.pptxFIDO Alliance
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Victor Rentea
 
The Ultimate Prompt Engineering Guide for Generative AI: Get the Most Out of ...
The Ultimate Prompt Engineering Guide for Generative AI: Get the Most Out of ...The Ultimate Prompt Engineering Guide for Generative AI: Get the Most Out of ...
The Ultimate Prompt Engineering Guide for Generative AI: Get the Most Out of ...SOFTTECHHUB
 
Decarbonising Commercial Real Estate: The Role of Operational Performance
Decarbonising Commercial Real Estate: The Role of Operational PerformanceDecarbonising Commercial Real Estate: The Role of Operational Performance
Decarbonising Commercial Real Estate: The Role of Operational PerformanceIES VE
 
Navigating Identity and Access Management in the Modern Enterprise
Navigating Identity and Access Management in the Modern EnterpriseNavigating Identity and Access Management in the Modern Enterprise
Navigating Identity and Access Management in the Modern EnterpriseWSO2
 
Working together SRE & Platform Engineering
Working together SRE & Platform EngineeringWorking together SRE & Platform Engineering
Working together SRE & Platform EngineeringMarcus Vechiato
 
Modernizing Legacy Systems Using Ballerina
Modernizing Legacy Systems Using BallerinaModernizing Legacy Systems Using Ballerina
Modernizing Legacy Systems Using BallerinaWSO2
 
AI in Action: Real World Use Cases by Anitaraj
AI in Action: Real World Use Cases by AnitarajAI in Action: Real World Use Cases by Anitaraj
AI in Action: Real World Use Cases by AnitarajAnitaRaj43
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingEdi Saputra
 
UiPath manufacturing technology benefits and AI overview
UiPath manufacturing technology benefits and AI overviewUiPath manufacturing technology benefits and AI overview
UiPath manufacturing technology benefits and AI overviewDianaGray10
 
AI+A11Y 11MAY2024 HYDERBAD GAAD 2024 - HelloA11Y (11 May 2024)
AI+A11Y 11MAY2024 HYDERBAD GAAD 2024 - HelloA11Y (11 May 2024)AI+A11Y 11MAY2024 HYDERBAD GAAD 2024 - HelloA11Y (11 May 2024)
AI+A11Y 11MAY2024 HYDERBAD GAAD 2024 - HelloA11Y (11 May 2024)Samir Dash
 
TEST BANK For Principles of Anatomy and Physiology, 16th Edition by Gerard J....
TEST BANK For Principles of Anatomy and Physiology, 16th Edition by Gerard J....TEST BANK For Principles of Anatomy and Physiology, 16th Edition by Gerard J....
TEST BANK For Principles of Anatomy and Physiology, 16th Edition by Gerard J....rightmanforbloodline
 
Design Guidelines for Passkeys 2024.pptx
Design Guidelines for Passkeys 2024.pptxDesign Guidelines for Passkeys 2024.pptx
Design Guidelines for Passkeys 2024.pptxFIDO Alliance
 

Recently uploaded (20)

Intro to Passkeys and the State of Passwordless.pptx
Intro to Passkeys and the State of Passwordless.pptxIntro to Passkeys and the State of Passwordless.pptx
Intro to Passkeys and the State of Passwordless.pptx
 
Introduction to FIDO Authentication and Passkeys.pptx
Introduction to FIDO Authentication and Passkeys.pptxIntroduction to FIDO Authentication and Passkeys.pptx
Introduction to FIDO Authentication and Passkeys.pptx
 
The Zero-ETL Approach: Enhancing Data Agility and Insight
The Zero-ETL Approach: Enhancing Data Agility and InsightThe Zero-ETL Approach: Enhancing Data Agility and Insight
The Zero-ETL Approach: Enhancing Data Agility and Insight
 
Simplifying Mobile A11y Presentation.pptx
Simplifying Mobile A11y Presentation.pptxSimplifying Mobile A11y Presentation.pptx
Simplifying Mobile A11y Presentation.pptx
 
2024 May Patch Tuesday
2024 May Patch Tuesday2024 May Patch Tuesday
2024 May Patch Tuesday
 
WSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering DevelopersWSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering Developers
 
ADP Passwordless Journey Case Study.pptx
ADP Passwordless Journey Case Study.pptxADP Passwordless Journey Case Study.pptx
ADP Passwordless Journey Case Study.pptx
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
 
The Ultimate Prompt Engineering Guide for Generative AI: Get the Most Out of ...
The Ultimate Prompt Engineering Guide for Generative AI: Get the Most Out of ...The Ultimate Prompt Engineering Guide for Generative AI: Get the Most Out of ...
The Ultimate Prompt Engineering Guide for Generative AI: Get the Most Out of ...
 
Decarbonising Commercial Real Estate: The Role of Operational Performance
Decarbonising Commercial Real Estate: The Role of Operational PerformanceDecarbonising Commercial Real Estate: The Role of Operational Performance
Decarbonising Commercial Real Estate: The Role of Operational Performance
 
Navigating Identity and Access Management in the Modern Enterprise
Navigating Identity and Access Management in the Modern EnterpriseNavigating Identity and Access Management in the Modern Enterprise
Navigating Identity and Access Management in the Modern Enterprise
 
Working together SRE & Platform Engineering
Working together SRE & Platform EngineeringWorking together SRE & Platform Engineering
Working together SRE & Platform Engineering
 
Modernizing Legacy Systems Using Ballerina
Modernizing Legacy Systems Using BallerinaModernizing Legacy Systems Using Ballerina
Modernizing Legacy Systems Using Ballerina
 
AI in Action: Real World Use Cases by Anitaraj
AI in Action: Real World Use Cases by AnitarajAI in Action: Real World Use Cases by Anitaraj
AI in Action: Real World Use Cases by Anitaraj
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
Overview of Hyperledger Foundation
Overview of Hyperledger FoundationOverview of Hyperledger Foundation
Overview of Hyperledger Foundation
 
UiPath manufacturing technology benefits and AI overview
UiPath manufacturing technology benefits and AI overviewUiPath manufacturing technology benefits and AI overview
UiPath manufacturing technology benefits and AI overview
 
AI+A11Y 11MAY2024 HYDERBAD GAAD 2024 - HelloA11Y (11 May 2024)
AI+A11Y 11MAY2024 HYDERBAD GAAD 2024 - HelloA11Y (11 May 2024)AI+A11Y 11MAY2024 HYDERBAD GAAD 2024 - HelloA11Y (11 May 2024)
AI+A11Y 11MAY2024 HYDERBAD GAAD 2024 - HelloA11Y (11 May 2024)
 
TEST BANK For Principles of Anatomy and Physiology, 16th Edition by Gerard J....
TEST BANK For Principles of Anatomy and Physiology, 16th Edition by Gerard J....TEST BANK For Principles of Anatomy and Physiology, 16th Edition by Gerard J....
TEST BANK For Principles of Anatomy and Physiology, 16th Edition by Gerard J....
 
Design Guidelines for Passkeys 2024.pptx
Design Guidelines for Passkeys 2024.pptxDesign Guidelines for Passkeys 2024.pptx
Design Guidelines for Passkeys 2024.pptx
 

Databases 101

  • 2. SQL Server What is a database? Database Table Rows ● Multiple SQL Server instances per server are possible ● Multiple databases per SQL server are possible ● “Multiple Drawers” Tables can have indexes ...but what’s an index? ● Think of an index at the back of a text book. ● Indexed on some specific column or columns ● This is important for performance when looking up information. ● Why am I telling you this? Image Credit: http://media.datadirect.com/download/docs/sequelnk/odbc30/uindex.htm Image Credit: http://4vector.com/thumb_data/afd-
  • 3. Relational Databases Hierarchical DBS Relational DBS Image Credit: IBM http://www.ibm.com/developerworks/xml/library/x-matters8/index.html?ca=drs
  • 4. SQL Server instances...who uses them? Development QA Stage Development QA CS Application s Production APIs Reporting
  • 5. Ok, so what is SQL? SQL = Structured Query Language ● A 4th generation programming language for managing data held in relational database management systems ● Based on relational algebra concepts ● Good news: Powerful but easy to use ● Bad news: Powerful but easy to use SQL command categories: ● DDL (Data Definition Language) - CREATE TABLE, etc. ● DCL (Data Control Language) - GRANT, REVOKE, etc. ● DML (Data Manipulation Language) - INSERT, UPDATE, DELETE, SELECT We’ll focus on a small subset of SQL commands within the DML category: SELECT commands.
  • 6. Anatomy of a SELECT statement SELECT FirstName, LastName FROM People WHERE ID = 1234567 SELECT FirstName, LastName FROM People WHERE Department_ID = 56789 AND (LastName LIKE ‘Smith’ OR LastName LIKE ‘Bradford’) SELECT FirstName, LastName FROM People
  • 7. Anatomy of a SELECT statement WHERE clause: ● Acts as a filter. Only give me results where x = y ● Compares the ID column against a value or another column SELECT FirstName, LastName FROM People WHERE Department_ID = 56789 AND (LastName LIKE ‘Smith’ OR LastName LIKE ‘Bradford’) Multiple WHERE filters OR operator = Either of these conditions can be true SELECT FirstName, LastName FROM People SELECT command Column names FROM tablename SELECT FirstName, LastName FROM People WHERE ID = 1234567
  • 8. Locking, Blocking, and Deadlocking Locking ● Locking is the restriction of data access to some data in the database. What does that mean? If I’m working on a row of data, you can’t change it. ● Tables are shared resources. Lots of processes may be reading, inserting, updating, or deleting from them at the same time. ● Locking enables these processes to occur in a managed, orderly fashion (e.g. Bank Account: deduction from person A blocks a deduction from person B until deduction from person A is complete). Blocking ● When a table is locked by one process and another process attempts to access it, blocking occurs. ● Blocking is normal to a point...we need it to maintain integrity...but it can be dangerous. ● Ways we manage blocking ○ Avoid unnecessary blocking by writing better code ○ Keep an eye on blocking with a Block Monitor to alert us if a block is out of control ○ Use NOLOCK when doing ad hoc queries - very important!
  • 9. Locking, Blocking, and Deadlocking SELECT FirstName, LastName FROM People WITH (NOLOCK) WHERE ID = 1234567 Query hint Using the ‘WITH (NOLOCK) hint means you are forfeiting your right to exclusive access to that data, and changes may occur while you are viewing it. Why is that a good thing? Why could that be a bad thing?
  • 10. Locking, Blocking, and Deadlocking ** Always use the WITH (NOLOCK) syntax on your queries! **
  • 11. Locking, Blocking, and Deadlocking Deadlocking Image Credit: http://www.sqlxl.com/images/sql_deadlock_image001.pngImage Credit: Bye, bye
  • 12. Dos and Don’ts Do ● Use COUNT() function to see how many rows you are working on, before blindly selecting back massive amounts of data: SELECT COUNT(ID) FROM People WITH (NOLOCK) Column name ● Use TOP clause to view a subset of rows if you are investigating the type of data in a table: SELECT TOP 10 * FROM People WITH (NOLOCK) ● Use WHERE clause whenever possible to avoid needless row retrieval: SELECT TOP 10 * FROM People WITH (NOLOCK) WHERE LastName LIKE ‘Jones’
  • 13. Dos and Don’ts Don’t ● Use SELECT * to pull back all data when all data is not needed SELECT * FROM People ● Use negative logic like: <>, NOT LIKE, NOT EXISTS SELECT TOP 10 * FROM People WHERE LastName NOT LIKE ‘Jones’ ● Join more than three or four tables when possible: SELECT p.ID FROM People p INNER JOIN Department d ON d.Dept_ID = p.Dept_ID INNER JOIN… INNER JOIN… WHERE LastName LIKE ‘Jones’
  • 14. Joining Tables The power of relational databases lies in the ability to join data between tables. Most tables will have relationships to other tables in the database and following these ‘threads’ between tables allows us to efficiently store and retrieve data: SELECT pl.Title FROM Publication pl WITH (NOLOCK) INNER JOIN Publisher p WITH (NOLOCK) ON p.PubID = pl.PubID WHERE p.PubAddress LIKE ‘%New York%’ Publisher Author Publication
  • 15. Joining Tables Avoid Cartesian products!! A cartesian product occurs when you use CROSS JOIN without WHERE filters. This forces the query to join EVERY row to EVERY OTHER row in the joined tables SELECT pl.Title FROM Publication pl WITH (NOLOCK) CROSS JOIN Publisher p WITH (NOLOCK) WHERE p.PubAddress LIKE ‘%New York%’---------------------------------------------------
  • 16. Stored Procedures ● Stored procedures = encapsulated code ● They are like tiny little applications - they contain SQL code that, when called, will run the same way everytime ● Example: Stored Procedure: cs_EmployeeNames Stored Procedure code: Select FirstName, LastName FROM People This... EXEC cs_EmployeeNames ...gives you the same results as this Select FirstName, LastName FROM People
  • 17. Stored Procedures Stored procedure auditing ● Tracks who ran what stored procedure ● What parameters where passed in (in other words, for which client was the sp run?) ● When it was run Image Credit: http://www.keepcalm-o-matic.co.uk/p/big-brother-is-watching-you-13/
  • 18. Data Policy ● Do not read/interpret data for your own personal use ● Be VERY conscientious of how you communicate data back and forth to customers. Our cs Chat is secure, but email is not...never pass sensitive data via email, other IM clients, fax, etc. SFTP is the only acceptable way to pass sensitive data. ● Do not share customer data across customer boundaries - be careful of even off handed comments on the phone (Oh, your fill rate is this but so-and-so is that, etc.) ● Do not take data home or outside of company controlled devices (e.g. your laptop) unless absolutely necessary to complete your work. This includes thumb drives, printed material, etc. ● Be absolutely certain the client you are sharing data with is who you think it is. This is especially tricky over the phone. If unsure, end the conversation and call them back at the verified contact number to ensure you are speaking with the correct person. ● Do not share usernames and passwords. Ever. (This includes SQL users, PCs, Customer data, etc.) ● Do not log in with your credential for someone else. Ever. ● This can seem innocuous, but you are liable for what they do under your credentials. ● Check with IT before storing client or company data anywhere outside of company approved devices or drives (eg. Google docs, Evernote, etc.) This is very tightly controlled.
  • 19. Don’t be afraid of the DBAs And we’re normal. Really. No, seriously. We’re here to help.

Editor's Notes

  1. Good: It helps prevent blocking when you are running queries Bad: It means you *could* get ‘dirty’ results - give example: balances query to help a customer update a balance while someone else in the district is doing an data import to change the balances. You’re going to think you’re adding x amount to balace y when it will actually be balance z
  2. In my CS days I ran a bad query and within 2 minutes, Eric and Frank showed up at my desk frantically telling me to kill the query! I was blocking a critical table and the system had effectively ground to a halt for millions of users across the country. USE NOLOCK!!
  3. Eventually, SQL Server will choose one of the deadlocked processes as a victim and ‘kill’ it to allow traffic to continue
  4. Some of these are generalities and there will be times when you use them, but don’t make it a habit of using them all the time. SELECT * pulls back all columns of every table in the query and creates needless network traffic Negative logic often forces what are called table or index scans, making the SQL Server look at EVERY row in the table to make sure it DOESN”T equal your ‘negative’ filter...this can get very expensive on large tables
  5. You’re generally not going to be using the CROSS JOIN type of Join anyway...so best to NOT use it unless you are absolutely certain of what you are doing with that type of join as an example, if you join two tables, each with 100,000 rows, a cartesian product would return 10,000,000,000 (billion) rows. Two tables of 1,000,000 rows each returns 1,000,000,000,000 (trillion)
  6. Wrappers allow us to track changes to client data Wrappers are a tool for you - very helpful - but ask before you pull the trigger if you are unsure. Quick demo of where WRAPPERs live
  7. We have been entrusted with our clients sensitive data and we must be extremely careful how we handle and protect it.