SlideShare uma empresa Scribd logo
1 de 36
Baixar para ler offline
SQL
What is a database?
 a collection of data
 Usually consists of entities and
relations
 An entity is an individual “object” that exists and is
distinguishable from other individuals.
Example: specific person, company, event, plant
 Entities have attributes
Example: people have names and addresses
 A relationship is an association among several entities
Database Management System
(DBMS)
 A computerized record-keeping system
 Allows operations such as:
 Adding new files
 Inserting data into existing files
 Retrieving data from existing files
 Changing data
 Deleting data
 Removing existing files from the database
Data Models
 A data model is a collection of concepts for
describing data.
 A schema is a description of a particular
collection of data, using the given data
model.
 The relational model of data is the most
widely used model today.
 Main concept: relation, basically a table with
rows and columns.
 Every relation has a schema, which describes
the columns, or fields.
Levels of Abstraction
Relational Databases
 Data is logically perceived as a two-
dimensional table
 Relational databases are sets of tables
 tables are relations
Example Table
Relational Database Query
 A relational database query is a question
about the data, and the answer consists of a
new relation containing the result.
 Queries are one part of the Data
Manipulation Language of a DBMS (we also
need to create, update, insert data)
 Language: Structured Query Language (SQL)
Example SQL query
 Select G.Accession, G.Medline
 From Genebank G
 Where G.source=`baker’s yeast’;
No explicit links between
tables
 Of course, there may be implicit links
in that two tables share the same
attribute (like the accession number)
 In fact, in a relational DB, this is the
only way to connect distinct tables, at
the logical level anyway
 A link between one table and another
is called a foreign key
Why use a DBMS
 Data independence and efficient
access.
 Reduced application development
time.
 Data integrity and security.
 Uniform data administration.
 Concurrent access, recovery from
crashes.
Example
 Suppose you created a file to hold names, ID
numbers and faculty/student status
 This was a flat file that resembled a table in
a database
 What if you wanted to now add new data for
some of the faculty with credit card
information?
 How would you connect the two tables?
Example
Fred 1234567
Mark 2345678
George 3456789
Quinn 4567890
ID Credit Card
1234567 44444444
4567890 55555555
How to use MySQL
 Connect to MySQL Server
shell> ~clement/mysqlbin/bin/mysql -h pathogen.cs.byu.edu –u
cs360 <Enter>
Welcome to the MySQL monitor.
Type 'help' for help.
mysql>
How to use MySQL
Data Definition 1
mysql> SHOW DATABASES;
Database
mysql
test
tmp
Creating Tables
 CREATE TABLE image (
image_id INT,
image_type CHAR(3),
filename CHAR(40),
url CHAR(128),
Primary Key(image_id));
 creates a table with 4 columns and no
rows
Another table
 create table image_decoder
(image_type CHAR(3),
decoder_program varchar(20),
args varchar(20));
Basic Data Types
 INT - signed integer value. Implementation-dependent
# bits
 NUMERIC(total length, number of decimal places)
 NUMERIC(8,4) - 3 digits, a decimal point, 4 decimal places
 REAL - floating point number
 BIT - single boolean value
 DATE - year, month, day
 TIME
 TIMESTAMP - date/time
 VARCHAR(length) - variable length string <= length
 BLOB - Binary Large Object
How to use MySQL
 INSERT INTO image
( image_id, image_type, filename, url)
VALUES
( 1, ‘jpg’, ‘image1’, ‘http://host/dir/image1’)
Values must be in the right order and fill all columns
Values must be the order specified.
But, you don’t need to fill all columns.
More
 insert into image_decoder
values('jpg','/usr/bin/jpgview’,’’);
Selecting Rows
 SELECT image_type from image
WHERE filename=‘image1’
 SELECT image_decoder.decoder_program FROM
image_decoder, image
WHERE image.filename=‘image1’
AND
image.image_type=image_decoder.image_type
 The Join operation can be viewed as creating a virtual table
on the fly from rows in two or more tables
 SELECT * from image GROUP by image_type
Basic Where Clauses
 Operators
 =, <, >, <=, >=, != (or <>)
 WHERE image_id = 2
 LIKE - wildcard comparison
 WHERE decoder_program LIKE ‘c:%’
 ISNULL - checks for null value
 IN - contained in a set (usually for subqueries)
 WHERE image_id IN (1,2)
 WHERE image_id IN
SELECT image_id FROM Image
Updating Rows
 UPDATE Image
SET url=‘http://newhost/image1’
WHERE filename=‘image1’
 The where clause may select multiple rows
e.g. WHERE image_id < 50
 If the WHERE clause is excluded, the SET
operation is applied to every row in the
table
Deleting Rows
 DELETE from Image
WHERE image_id=2
 Entire row is removed from the table
 DELETE from Image
 Every row is removed from the table!!!
How to use MySQL
 Data manipulation 2
mysql> SELECT * FROM seqs;
+-------+-----------+----------+
| title | accession | sequence |
+-------+-----------+----------+
| Human | u235 | cgatcagt |
+-------+-----------+----------+
mysql> insert into seqs
-> values('Dog','u222','ccgtacgt');
mysql> SELECT * FROM seqs;
+-------+-----------+----------+
| title | accession | sequence |
+-------+-----------+----------+
| Human | u235 | cgatcagt |
| Dog | u222 | ccgtacgt |
+-------+-----------+----------+
Add data from file
 mysql> load data local infile
’/users/faculty/snell/CS360/sample.txt' into
table seqs;
 Delete it
 mysql> delete from seqs
 Redo load with up arrow
 select title, accession from seqs;
 update seqs set accession = 'H0794' where
title = 'Human-01';
 select * from seqs order by title;
More commands
 mysql> select * from seqs where title
like 'Human%';
More commands
 use mysql;
 show tables;
 describe db;
PERL DBI
$dbh = DBI->connect("dbi:mysql:
database=sequences;
host=paintball:1236;",
"phylo","")
or die("Couldn't connect");
$SQL= "select * from seqs";
$Select = $dbh->prepare($SQL);
$Select->execute();
while($Row=$Select->fetchrow_hashref)
print "title $Row->{title}, sequence $Row->{sequence} n";
$dbh->disconnect();
What Is the Perl DBI?
 The standard Database Interface for
Perl
 “A perl module and specification that
defines a consistent database interface
independent of the actual database being
used”
Why the Perl DBI?
 Once upon a time…
 One language, many database interfaces
 Perl 5 - A new way
 Modules and Objects. The DBI is born.
 The future is now…
 ODBC, Oracle, Informix, Ingres, mSQL, mysql, DB2, Solid,
Sybase, Postgress, Quickbase, Empress, Fulcrum, ...
 The same database interface
Making simple things easy
and difficult things possible
 Goals
 Be simple to use for simple applications
 Have sufficient flexibility to accommodate unusual
functionality and non-SQL databases
 Conform to applicable standards (ODBC etc.)
 Enable the creation of database-independent Perl scripts
without being limited to the lowest functionality
 Be free.
 A ‘higher-level’ interface than ODBC/JDBC
Under the Hood
 DBI defines and implements an interface
 Driver modules do much of the real work
 DBI provides default methods, functions, tools etc for
drivers
 Not limited to the lowest common denominator -
mechanism provided for driver specific extensions
 Designed and built for speed
 Valuable detailed call tracing/debugging built-in
So why use the Perl DBI?
 Because...
 It delivers what it promises
 It’s here, there and everywhere
 It’s fast, flexible and well proven
 It’s free, with source
 Commercial support is available
 It has a large user base and a strong
future

Mais conteúdo relacionado

Mais procurados (20)

SQL : introduction
SQL : introductionSQL : introduction
SQL : introduction
 
PostgreSQL Tutorial For Beginners | Edureka
PostgreSQL Tutorial For Beginners | EdurekaPostgreSQL Tutorial For Beginners | Edureka
PostgreSQL Tutorial For Beginners | Edureka
 
Sql - Structured Query Language
Sql - Structured Query LanguageSql - Structured Query Language
Sql - Structured Query Language
 
Database Programming
Database ProgrammingDatabase Programming
Database Programming
 
What is SQL Server?
What is SQL Server?What is SQL Server?
What is SQL Server?
 
Structured query language(sql)ppt
Structured query language(sql)pptStructured query language(sql)ppt
Structured query language(sql)ppt
 
Chapter 4 Structured Query Language
Chapter 4 Structured Query LanguageChapter 4 Structured Query Language
Chapter 4 Structured Query Language
 
Database Architecture
Database ArchitectureDatabase Architecture
Database Architecture
 
SQL Commands
SQL Commands SQL Commands
SQL Commands
 
Database programming
Database programmingDatabase programming
Database programming
 
Ms sql-server
Ms sql-serverMs sql-server
Ms sql-server
 
Module02
Module02Module02
Module02
 
Sql a practical introduction
Sql   a practical introductionSql   a practical introduction
Sql a practical introduction
 
Sql server T-sql basics ppt-3
Sql server T-sql basics  ppt-3Sql server T-sql basics  ppt-3
Sql server T-sql basics ppt-3
 
MYSQL.ppt
MYSQL.pptMYSQL.ppt
MYSQL.ppt
 
SQL Overview
SQL OverviewSQL Overview
SQL Overview
 
Database Architecture and Basic Concepts
Database Architecture and Basic ConceptsDatabase Architecture and Basic Concepts
Database Architecture and Basic Concepts
 
Database presentation
Database presentationDatabase presentation
Database presentation
 
SQL
SQL SQL
SQL
 
Sql fundamentals
Sql fundamentalsSql fundamentals
Sql fundamentals
 

Destaque

Final irb for sabbatical parkinson's support group work
Final irb for sabbatical parkinson's support group workFinal irb for sabbatical parkinson's support group work
Final irb for sabbatical parkinson's support group workariemens
 
Las100mejoresroka las mejores
Las100mejoresroka las mejores Las100mejoresroka las mejores
Las100mejoresroka las mejores Pepe Rsr
 
Proyecto seguridad en la granja (1)
Proyecto seguridad en la granja (1)Proyecto seguridad en la granja (1)
Proyecto seguridad en la granja (1)Camilo Sandoval
 
Mapa mental sobre la unidad
Mapa mental sobre la unidadMapa mental sobre la unidad
Mapa mental sobre la unidadchernandezsa
 
Actividad 9sdvnsdkjfvndflvkjnmlgskfdhbsrthrsttttttttttttsssssssssssssssssssss...
Actividad 9sdvnsdkjfvndflvkjnmlgskfdhbsrthrsttttttttttttsssssssssssssssssssss...Actividad 9sdvnsdkjfvndflvkjnmlgskfdhbsrthrsttttttttttttsssssssssssssssssssss...
Actividad 9sdvnsdkjfvndflvkjnmlgskfdhbsrthrsttttttttttttsssssssssssssssssssss...Marisol Hernández
 
Mantenimiento de la fuente de alimentación
Mantenimiento de la fuente de alimentaciónMantenimiento de la fuente de alimentación
Mantenimiento de la fuente de alimentaciónDany Kriz Love
 
Portafolio núm 4
Portafolio núm 4Portafolio núm 4
Portafolio núm 4Karla Bello
 
Los náufragos de Urabá
Los náufragos de UrabáLos náufragos de Urabá
Los náufragos de UrabáEn casa
 

Destaque (14)

Final irb for sabbatical parkinson's support group work
Final irb for sabbatical parkinson's support group workFinal irb for sabbatical parkinson's support group work
Final irb for sabbatical parkinson's support group work
 
Los gigantes
Los gigantesLos gigantes
Los gigantes
 
Técnico en marketing
Técnico en marketingTécnico en marketing
Técnico en marketing
 
Las100mejoresroka las mejores
Las100mejoresroka las mejores Las100mejoresroka las mejores
Las100mejoresroka las mejores
 
Proyecto seguridad en la granja (1)
Proyecto seguridad en la granja (1)Proyecto seguridad en la granja (1)
Proyecto seguridad en la granja (1)
 
Final Resume1
Final Resume1Final Resume1
Final Resume1
 
Etica en los negocios
Etica en los negociosEtica en los negocios
Etica en los negocios
 
Mapa mental sobre la unidad
Mapa mental sobre la unidadMapa mental sobre la unidad
Mapa mental sobre la unidad
 
Actividad 9sdvnsdkjfvndflvkjnmlgskfdhbsrthrsttttttttttttsssssssssssssssssssss...
Actividad 9sdvnsdkjfvndflvkjnmlgskfdhbsrthrsttttttttttttsssssssssssssssssssss...Actividad 9sdvnsdkjfvndflvkjnmlgskfdhbsrthrsttttttttttttsssssssssssssssssssss...
Actividad 9sdvnsdkjfvndflvkjnmlgskfdhbsrthrsttttttttttttsssssssssssssssssssss...
 
El colón
El colónEl colón
El colón
 
Mantenimiento de la fuente de alimentación
Mantenimiento de la fuente de alimentaciónMantenimiento de la fuente de alimentación
Mantenimiento de la fuente de alimentación
 
BNOVA SMART
BNOVA SMARTBNOVA SMART
BNOVA SMART
 
Portafolio núm 4
Portafolio núm 4Portafolio núm 4
Portafolio núm 4
 
Los náufragos de Urabá
Los náufragos de UrabáLos náufragos de Urabá
Los náufragos de Urabá
 

Semelhante a Sql

Slick: Bringing Scala’s Powerful Features to Your Database Access
Slick: Bringing Scala’s Powerful Features to Your Database Access Slick: Bringing Scala’s Powerful Features to Your Database Access
Slick: Bringing Scala’s Powerful Features to Your Database Access Rebecca Grenier
 
Module 6WEB SERVER AND SERVER SIDE SCRPTING, PART-2Chapte.docx
Module 6WEB SERVER AND SERVER SIDE SCRPTING, PART-2Chapte.docxModule 6WEB SERVER AND SERVER SIDE SCRPTING, PART-2Chapte.docx
Module 6WEB SERVER AND SERVER SIDE SCRPTING, PART-2Chapte.docxmoirarandell
 
Working with databases in Perl
Working with databases in PerlWorking with databases in Perl
Working with databases in PerlLaurent Dami
 
Entity Framework Database and Code First
Entity Framework Database and Code FirstEntity Framework Database and Code First
Entity Framework Database and Code FirstJames Johnson
 
Data handling in r
Data handling in rData handling in r
Data handling in rAbhik Seal
 
Chapter 3.1.pptx
Chapter 3.1.pptxChapter 3.1.pptx
Chapter 3.1.pptxmebratu9
 
Drupal II: The SQL
Drupal II: The SQLDrupal II: The SQL
Drupal II: The SQLddiers
 
Chapter Seven- JDBC.pptx
Chapter Seven- JDBC.pptxChapter Seven- JDBC.pptx
Chapter Seven- JDBC.pptxBlenKassahun1
 
Bank mangement system
Bank mangement systemBank mangement system
Bank mangement systemFaisalGhffar
 
Jdbc Dao it-slideshares.blogspot.com
Jdbc Dao it-slideshares.blogspot.comJdbc Dao it-slideshares.blogspot.com
Jdbc Dao it-slideshares.blogspot.comphanleson
 

Semelhante a Sql (20)

Mdst 3559-03-01-sql-php
Mdst 3559-03-01-sql-phpMdst 3559-03-01-sql-php
Mdst 3559-03-01-sql-php
 
MYSQL - PHP Database Connectivity
MYSQL - PHP Database ConnectivityMYSQL - PHP Database Connectivity
MYSQL - PHP Database Connectivity
 
Slick: Bringing Scala’s Powerful Features to Your Database Access
Slick: Bringing Scala’s Powerful Features to Your Database Access Slick: Bringing Scala’s Powerful Features to Your Database Access
Slick: Bringing Scala’s Powerful Features to Your Database Access
 
Module 6WEB SERVER AND SERVER SIDE SCRPTING, PART-2Chapte.docx
Module 6WEB SERVER AND SERVER SIDE SCRPTING, PART-2Chapte.docxModule 6WEB SERVER AND SERVER SIDE SCRPTING, PART-2Chapte.docx
Module 6WEB SERVER AND SERVER SIDE SCRPTING, PART-2Chapte.docx
 
Php 2
Php 2Php 2
Php 2
 
Working with databases in Perl
Working with databases in PerlWorking with databases in Perl
Working with databases in Perl
 
7. SQL.pptx
7. SQL.pptx7. SQL.pptx
7. SQL.pptx
 
Introduction to dbms
Introduction to dbmsIntroduction to dbms
Introduction to dbms
 
My sql1
My sql1My sql1
My sql1
 
La sql
La sqlLa sql
La sql
 
Entity Framework Database and Code First
Entity Framework Database and Code FirstEntity Framework Database and Code First
Entity Framework Database and Code First
 
Data handling in r
Data handling in rData handling in r
Data handling in r
 
Chapter 3.1.pptx
Chapter 3.1.pptxChapter 3.1.pptx
Chapter 3.1.pptx
 
Drupal II: The SQL
Drupal II: The SQLDrupal II: The SQL
Drupal II: The SQL
 
PHP and Mysql
PHP and MysqlPHP and Mysql
PHP and Mysql
 
Chapter Seven- JDBC.pptx
Chapter Seven- JDBC.pptxChapter Seven- JDBC.pptx
Chapter Seven- JDBC.pptx
 
Bank mangement system
Bank mangement systemBank mangement system
Bank mangement system
 
Jdbc Dao it-slideshares.blogspot.com
Jdbc Dao it-slideshares.blogspot.comJdbc Dao it-slideshares.blogspot.com
Jdbc Dao it-slideshares.blogspot.com
 
Database concepts
Database conceptsDatabase concepts
Database concepts
 
Android sq lite-chapter 22
Android sq lite-chapter 22Android sq lite-chapter 22
Android sq lite-chapter 22
 

Mais de YUCHENG HU

Confluencewiki 使用空间
Confluencewiki 使用空间Confluencewiki 使用空间
Confluencewiki 使用空间YUCHENG HU
 
Presta shop 1.6 如何安装简体中文语言文件
Presta shop 1.6 如何安装简体中文语言文件Presta shop 1.6 如何安装简体中文语言文件
Presta shop 1.6 如何安装简体中文语言文件YUCHENG HU
 
Logback 介绍
Logback 介绍Logback 介绍
Logback 介绍YUCHENG HU
 
Presta shop 1.6 详细安装指南
Presta shop 1.6 详细安装指南Presta shop 1.6 详细安装指南
Presta shop 1.6 详细安装指南YUCHENG HU
 
Presta shop 1.6 的安装环境
Presta shop 1.6 的安装环境Presta shop 1.6 的安装环境
Presta shop 1.6 的安装环境YUCHENG HU
 
Presta shop 1.6 如何安装简体中文语言文件
Presta shop 1.6 如何安装简体中文语言文件Presta shop 1.6 如何安装简体中文语言文件
Presta shop 1.6 如何安装简体中文语言文件YUCHENG HU
 
Presta shop 1.6 图文安装教程
Presta shop 1.6 图文安装教程Presta shop 1.6 图文安装教程
Presta shop 1.6 图文安装教程YUCHENG HU
 
V tiger 5.4.0 图文安装教程
V tiger 5.4.0 图文安装教程V tiger 5.4.0 图文安装教程
V tiger 5.4.0 图文安装教程YUCHENG HU
 
Confluence 回顾(retrospectives) 蓝图 cwikiossez
Confluence 回顾(retrospectives) 蓝图   cwikiossezConfluence 回顾(retrospectives) 蓝图   cwikiossez
Confluence 回顾(retrospectives) 蓝图 cwikiossezYUCHENG HU
 
Confluence 会议记录(meeting notes)蓝图 cwikiossez
Confluence 会议记录(meeting notes)蓝图   cwikiossezConfluence 会议记录(meeting notes)蓝图   cwikiossez
Confluence 会议记录(meeting notes)蓝图 cwikiossezYUCHENG HU
 
VTIGER - 销售机会 - CWIKIOSSEZ
VTIGER - 销售机会 - CWIKIOSSEZ VTIGER - 销售机会 - CWIKIOSSEZ
VTIGER - 销售机会 - CWIKIOSSEZ YUCHENG HU
 
Confluence 使用一个模板新建一个页面 cwikiossez
Confluence 使用一个模板新建一个页面     cwikiossezConfluence 使用一个模板新建一个页面     cwikiossez
Confluence 使用一个模板新建一个页面 cwikiossezYUCHENG HU
 
Confluence 使用模板
Confluence 使用模板Confluence 使用模板
Confluence 使用模板YUCHENG HU
 
Cwikiossez confluence 订阅页面更新邮件通知
Cwikiossez confluence 订阅页面更新邮件通知Cwikiossez confluence 订阅页面更新邮件通知
Cwikiossez confluence 订阅页面更新邮件通知YUCHENG HU
 
Cwikiossez confluence 关注页面 博客页面和空间
Cwikiossez confluence 关注页面 博客页面和空间Cwikiossez confluence 关注页面 博客页面和空间
Cwikiossez confluence 关注页面 博客页面和空间YUCHENG HU
 
My sql università di enna a.a. 2005-06
My sql   università di enna a.a. 2005-06My sql   università di enna a.a. 2005-06
My sql università di enna a.a. 2005-06YUCHENG HU
 
My sql would you like transactions
My sql would you like transactionsMy sql would you like transactions
My sql would you like transactionsYUCHENG HU
 
MySQL 简要介绍
MySQL 简要介绍MySQL 简要介绍
MySQL 简要介绍YUCHENG HU
 

Mais de YUCHENG HU (20)

Confluencewiki 使用空间
Confluencewiki 使用空间Confluencewiki 使用空间
Confluencewiki 使用空间
 
Git
GitGit
Git
 
Presta shop 1.6 如何安装简体中文语言文件
Presta shop 1.6 如何安装简体中文语言文件Presta shop 1.6 如何安装简体中文语言文件
Presta shop 1.6 如何安装简体中文语言文件
 
Logback 介绍
Logback 介绍Logback 介绍
Logback 介绍
 
Presta shop 1.6 详细安装指南
Presta shop 1.6 详细安装指南Presta shop 1.6 详细安装指南
Presta shop 1.6 详细安装指南
 
Presta shop 1.6 的安装环境
Presta shop 1.6 的安装环境Presta shop 1.6 的安装环境
Presta shop 1.6 的安装环境
 
Presta shop 1.6 如何安装简体中文语言文件
Presta shop 1.6 如何安装简体中文语言文件Presta shop 1.6 如何安装简体中文语言文件
Presta shop 1.6 如何安装简体中文语言文件
 
Presta shop 1.6 图文安装教程
Presta shop 1.6 图文安装教程Presta shop 1.6 图文安装教程
Presta shop 1.6 图文安装教程
 
V tiger 5.4.0 图文安装教程
V tiger 5.4.0 图文安装教程V tiger 5.4.0 图文安装教程
V tiger 5.4.0 图文安装教程
 
Confluence 回顾(retrospectives) 蓝图 cwikiossez
Confluence 回顾(retrospectives) 蓝图   cwikiossezConfluence 回顾(retrospectives) 蓝图   cwikiossez
Confluence 回顾(retrospectives) 蓝图 cwikiossez
 
Confluence 会议记录(meeting notes)蓝图 cwikiossez
Confluence 会议记录(meeting notes)蓝图   cwikiossezConfluence 会议记录(meeting notes)蓝图   cwikiossez
Confluence 会议记录(meeting notes)蓝图 cwikiossez
 
VTIGER - 销售机会 - CWIKIOSSEZ
VTIGER - 销售机会 - CWIKIOSSEZ VTIGER - 销售机会 - CWIKIOSSEZ
VTIGER - 销售机会 - CWIKIOSSEZ
 
Confluence 使用一个模板新建一个页面 cwikiossez
Confluence 使用一个模板新建一个页面     cwikiossezConfluence 使用一个模板新建一个页面     cwikiossez
Confluence 使用一个模板新建一个页面 cwikiossez
 
Confluence 使用模板
Confluence 使用模板Confluence 使用模板
Confluence 使用模板
 
Cwikiossez confluence 订阅页面更新邮件通知
Cwikiossez confluence 订阅页面更新邮件通知Cwikiossez confluence 订阅页面更新邮件通知
Cwikiossez confluence 订阅页面更新邮件通知
 
Cwikiossez confluence 关注页面 博客页面和空间
Cwikiossez confluence 关注页面 博客页面和空间Cwikiossez confluence 关注页面 博客页面和空间
Cwikiossez confluence 关注页面 博客页面和空间
 
My sql università di enna a.a. 2005-06
My sql   università di enna a.a. 2005-06My sql   università di enna a.a. 2005-06
My sql università di enna a.a. 2005-06
 
My sql would you like transactions
My sql would you like transactionsMy sql would you like transactions
My sql would you like transactions
 
MySQL 指南
MySQL 指南MySQL 指南
MySQL 指南
 
MySQL 简要介绍
MySQL 简要介绍MySQL 简要介绍
MySQL 简要介绍
 

Último

Data governance with Unity Catalog Presentation
Data governance with Unity Catalog PresentationData governance with Unity Catalog Presentation
Data governance with Unity Catalog PresentationKnoldus Inc.
 
Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...Rick Flair
 
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyesHow to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyesThousandEyes
 
Time Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsTime Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsNathaniel Shimoni
 
A Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersA Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersNicole Novielli
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxLoriGlavin3
 
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...Wes McKinney
 
Assure Ecommerce and Retail Operations Uptime with ThousandEyes
Assure Ecommerce and Retail Operations Uptime with ThousandEyesAssure Ecommerce and Retail Operations Uptime with ThousandEyes
Assure Ecommerce and Retail Operations Uptime with ThousandEyesThousandEyes
 
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24Mark Goldstein
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
Decarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a realityDecarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a realityIES VE
 
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...Alkin Tezuysal
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024Lonnie McRorey
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity PlanDatabarracks
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfLoriGlavin3
 
(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...
(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...
(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...AliaaTarek5
 
A Framework for Development in the AI Age
A Framework for Development in the AI AgeA Framework for Development in the AI Age
A Framework for Development in the AI AgeCprime
 
Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024Hiroshi SHIBATA
 
Enhancing User Experience - Exploring the Latest Features of Tallyman Axis Lo...
Enhancing User Experience - Exploring the Latest Features of Tallyman Axis Lo...Enhancing User Experience - Exploring the Latest Features of Tallyman Axis Lo...
Enhancing User Experience - Exploring the Latest Features of Tallyman Axis Lo...Scott Andery
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxLoriGlavin3
 

Último (20)

Data governance with Unity Catalog Presentation
Data governance with Unity Catalog PresentationData governance with Unity Catalog Presentation
Data governance with Unity Catalog Presentation
 
Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...
 
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyesHow to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
 
Time Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsTime Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directions
 
A Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersA Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software Developers
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
 
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
 
Assure Ecommerce and Retail Operations Uptime with ThousandEyes
Assure Ecommerce and Retail Operations Uptime with ThousandEyesAssure Ecommerce and Retail Operations Uptime with ThousandEyes
Assure Ecommerce and Retail Operations Uptime with ThousandEyes
 
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
Decarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a realityDecarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a reality
 
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity Plan
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdf
 
(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...
(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...
(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...
 
A Framework for Development in the AI Age
A Framework for Development in the AI AgeA Framework for Development in the AI Age
A Framework for Development in the AI Age
 
Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024
 
Enhancing User Experience - Exploring the Latest Features of Tallyman Axis Lo...
Enhancing User Experience - Exploring the Latest Features of Tallyman Axis Lo...Enhancing User Experience - Exploring the Latest Features of Tallyman Axis Lo...
Enhancing User Experience - Exploring the Latest Features of Tallyman Axis Lo...
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
 

Sql

  • 1. SQL
  • 2. What is a database?  a collection of data  Usually consists of entities and relations  An entity is an individual “object” that exists and is distinguishable from other individuals. Example: specific person, company, event, plant  Entities have attributes Example: people have names and addresses  A relationship is an association among several entities
  • 3. Database Management System (DBMS)  A computerized record-keeping system  Allows operations such as:  Adding new files  Inserting data into existing files  Retrieving data from existing files  Changing data  Deleting data  Removing existing files from the database
  • 4. Data Models  A data model is a collection of concepts for describing data.  A schema is a description of a particular collection of data, using the given data model.  The relational model of data is the most widely used model today.  Main concept: relation, basically a table with rows and columns.  Every relation has a schema, which describes the columns, or fields.
  • 6. Relational Databases  Data is logically perceived as a two- dimensional table  Relational databases are sets of tables  tables are relations
  • 8. Relational Database Query  A relational database query is a question about the data, and the answer consists of a new relation containing the result.  Queries are one part of the Data Manipulation Language of a DBMS (we also need to create, update, insert data)  Language: Structured Query Language (SQL)
  • 9. Example SQL query  Select G.Accession, G.Medline  From Genebank G  Where G.source=`baker’s yeast’;
  • 10. No explicit links between tables  Of course, there may be implicit links in that two tables share the same attribute (like the accession number)  In fact, in a relational DB, this is the only way to connect distinct tables, at the logical level anyway  A link between one table and another is called a foreign key
  • 11.
  • 12. Why use a DBMS  Data independence and efficient access.  Reduced application development time.  Data integrity and security.  Uniform data administration.  Concurrent access, recovery from crashes.
  • 13. Example  Suppose you created a file to hold names, ID numbers and faculty/student status  This was a flat file that resembled a table in a database  What if you wanted to now add new data for some of the faculty with credit card information?  How would you connect the two tables?
  • 14. Example Fred 1234567 Mark 2345678 George 3456789 Quinn 4567890 ID Credit Card 1234567 44444444 4567890 55555555
  • 15. How to use MySQL  Connect to MySQL Server shell> ~clement/mysqlbin/bin/mysql -h pathogen.cs.byu.edu –u cs360 <Enter> Welcome to the MySQL monitor. Type 'help' for help. mysql>
  • 16. How to use MySQL Data Definition 1 mysql> SHOW DATABASES; Database mysql test tmp
  • 17. Creating Tables  CREATE TABLE image ( image_id INT, image_type CHAR(3), filename CHAR(40), url CHAR(128), Primary Key(image_id));  creates a table with 4 columns and no rows
  • 18. Another table  create table image_decoder (image_type CHAR(3), decoder_program varchar(20), args varchar(20));
  • 19. Basic Data Types  INT - signed integer value. Implementation-dependent # bits  NUMERIC(total length, number of decimal places)  NUMERIC(8,4) - 3 digits, a decimal point, 4 decimal places  REAL - floating point number  BIT - single boolean value  DATE - year, month, day  TIME  TIMESTAMP - date/time  VARCHAR(length) - variable length string <= length  BLOB - Binary Large Object
  • 20. How to use MySQL  INSERT INTO image ( image_id, image_type, filename, url) VALUES ( 1, ‘jpg’, ‘image1’, ‘http://host/dir/image1’) Values must be in the right order and fill all columns Values must be the order specified. But, you don’t need to fill all columns.
  • 21. More  insert into image_decoder values('jpg','/usr/bin/jpgview’,’’);
  • 22. Selecting Rows  SELECT image_type from image WHERE filename=‘image1’  SELECT image_decoder.decoder_program FROM image_decoder, image WHERE image.filename=‘image1’ AND image.image_type=image_decoder.image_type  The Join operation can be viewed as creating a virtual table on the fly from rows in two or more tables  SELECT * from image GROUP by image_type
  • 23. Basic Where Clauses  Operators  =, <, >, <=, >=, != (or <>)  WHERE image_id = 2  LIKE - wildcard comparison  WHERE decoder_program LIKE ‘c:%’  ISNULL - checks for null value  IN - contained in a set (usually for subqueries)  WHERE image_id IN (1,2)  WHERE image_id IN SELECT image_id FROM Image
  • 24. Updating Rows  UPDATE Image SET url=‘http://newhost/image1’ WHERE filename=‘image1’  The where clause may select multiple rows e.g. WHERE image_id < 50  If the WHERE clause is excluded, the SET operation is applied to every row in the table
  • 25. Deleting Rows  DELETE from Image WHERE image_id=2  Entire row is removed from the table  DELETE from Image  Every row is removed from the table!!!
  • 26. How to use MySQL  Data manipulation 2 mysql> SELECT * FROM seqs; +-------+-----------+----------+ | title | accession | sequence | +-------+-----------+----------+ | Human | u235 | cgatcagt | +-------+-----------+----------+ mysql> insert into seqs -> values('Dog','u222','ccgtacgt'); mysql> SELECT * FROM seqs; +-------+-----------+----------+ | title | accession | sequence | +-------+-----------+----------+ | Human | u235 | cgatcagt | | Dog | u222 | ccgtacgt | +-------+-----------+----------+
  • 27. Add data from file  mysql> load data local infile ’/users/faculty/snell/CS360/sample.txt' into table seqs;  Delete it  mysql> delete from seqs  Redo load with up arrow  select title, accession from seqs;  update seqs set accession = 'H0794' where title = 'Human-01';  select * from seqs order by title;
  • 28. More commands  mysql> select * from seqs where title like 'Human%';
  • 29. More commands  use mysql;  show tables;  describe db;
  • 30. PERL DBI $dbh = DBI->connect("dbi:mysql: database=sequences; host=paintball:1236;", "phylo","") or die("Couldn't connect"); $SQL= "select * from seqs"; $Select = $dbh->prepare($SQL); $Select->execute(); while($Row=$Select->fetchrow_hashref) print "title $Row->{title}, sequence $Row->{sequence} n"; $dbh->disconnect();
  • 31. What Is the Perl DBI?  The standard Database Interface for Perl  “A perl module and specification that defines a consistent database interface independent of the actual database being used”
  • 32. Why the Perl DBI?  Once upon a time…  One language, many database interfaces  Perl 5 - A new way  Modules and Objects. The DBI is born.  The future is now…  ODBC, Oracle, Informix, Ingres, mSQL, mysql, DB2, Solid, Sybase, Postgress, Quickbase, Empress, Fulcrum, ...  The same database interface
  • 33. Making simple things easy and difficult things possible  Goals  Be simple to use for simple applications  Have sufficient flexibility to accommodate unusual functionality and non-SQL databases  Conform to applicable standards (ODBC etc.)  Enable the creation of database-independent Perl scripts without being limited to the lowest functionality  Be free.  A ‘higher-level’ interface than ODBC/JDBC
  • 34. Under the Hood  DBI defines and implements an interface  Driver modules do much of the real work  DBI provides default methods, functions, tools etc for drivers  Not limited to the lowest common denominator - mechanism provided for driver specific extensions  Designed and built for speed  Valuable detailed call tracing/debugging built-in
  • 35.
  • 36. So why use the Perl DBI?  Because...  It delivers what it promises  It’s here, there and everywhere  It’s fast, flexible and well proven  It’s free, with source  Commercial support is available  It has a large user base and a strong future