SlideShare a Scribd company logo
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
Sql
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
Sql
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

More Related Content

What's hot (20)

PPT
SQL : introduction
Shakila Mahjabin
 
PDF
PostgreSQL Tutorial For Beginners | Edureka
Edureka!
 
PPTX
Sql - Structured Query Language
Wan Hussain Wan Ishak
 
PPTX
Database Programming
Henry Osborne
 
PPTX
What is SQL Server?
CPD INDIA
 
PPTX
Structured query language(sql)ppt
Gowarthini
 
PDF
Chapter 4 Structured Query Language
Eddyzulham Mahluzydde
 
PPTX
Database Architecture
Er. Nawaraj Bhandari
 
PPTX
SQL Commands
Sachidananda M H
 
ODP
Ms sql-server
Md.Mojibul Hoque
 
PPT
Module02
Sridhar P
 
PDF
Sql a practical introduction
Hasan Kata
 
PPT
Sql server T-sql basics ppt-3
Vibrant Technologies & Computers
 
PPT
MYSQL.ppt
webhostingguy
 
PDF
SQL Overview
Stewart Rogers
 
PDF
Database Architecture and Basic Concepts
Tony Wong
 
PPT
Database presentation
webhostingguy
 
PPTX
Sql fundamentals
Ravinder Kamboj
 
SQL : introduction
Shakila Mahjabin
 
PostgreSQL Tutorial For Beginners | Edureka
Edureka!
 
Sql - Structured Query Language
Wan Hussain Wan Ishak
 
Database Programming
Henry Osborne
 
What is SQL Server?
CPD INDIA
 
Structured query language(sql)ppt
Gowarthini
 
Chapter 4 Structured Query Language
Eddyzulham Mahluzydde
 
Database Architecture
Er. Nawaraj Bhandari
 
SQL Commands
Sachidananda M H
 
Ms sql-server
Md.Mojibul Hoque
 
Module02
Sridhar P
 
Sql a practical introduction
Hasan Kata
 
Sql server T-sql basics ppt-3
Vibrant Technologies & Computers
 
MYSQL.ppt
webhostingguy
 
SQL Overview
Stewart Rogers
 
Database Architecture and Basic Concepts
Tony Wong
 
Database presentation
webhostingguy
 
Sql fundamentals
Ravinder Kamboj
 

Viewers also liked (14)

PDF
Final irb for sabbatical parkinson's support group work
ariemens
 
PPTX
Los gigantes
juanpa1615
 
PDF
Técnico en marketing
CenproexFormacion
 
PDF
Las100mejoresroka las mejores
Pepe Rsr
 
PDF
Proyecto seguridad en la granja (1)
Camilo Sandoval
 
PDF
Final Resume1
Nico Samaniego
 
PPT
Etica en los negocios
Marisel Avelino Leon
 
DOCX
Mapa mental sobre la unidad
chernandezsa
 
DOC
Actividad 9sdvnsdkjfvndflvkjnmlgskfdhbsrthrsttttttttttttsssssssssssssssssssss...
Marisol Hernández
 
PDF
El colón
Vale Verón Giroldi
 
PPTX
Mantenimiento de la fuente de alimentación
Dany Kriz Love
 
DOCX
BNOVA SMART
Amit Punekar
 
PDF
Portafolio núm 4
Karla Bello
 
PDF
Los náufragos de Urabá
En casa
 
Final irb for sabbatical parkinson's support group work
ariemens
 
Los gigantes
juanpa1615
 
Técnico en marketing
CenproexFormacion
 
Las100mejoresroka las mejores
Pepe Rsr
 
Proyecto seguridad en la granja (1)
Camilo Sandoval
 
Final Resume1
Nico Samaniego
 
Etica en los negocios
Marisel Avelino Leon
 
Mapa mental sobre la unidad
chernandezsa
 
Actividad 9sdvnsdkjfvndflvkjnmlgskfdhbsrthrsttttttttttttsssssssssssssssssssss...
Marisol Hernández
 
Mantenimiento de la fuente de alimentación
Dany Kriz Love
 
BNOVA SMART
Amit Punekar
 
Portafolio núm 4
Karla Bello
 
Los náufragos de Urabá
En casa
 
Ad

Similar to Sql (20)

PDF
sql_data.pdf
VandanaGoyal21
 
PPT
Mysql database
Arshikhan08
 
PDF
Sql a practical introduction
sanjaychauhan689
 
PDF
MySQL for beginners
Saeid Zebardast
 
PPTX
Ch-11 Relational Databases.pptx
ShadowDawg
 
PDF
Complete SQL in one video by shradha.pdf
rahulashu699
 
PDF
Sql a practical_introduction
investnow
 
PPTX
2018 02 20_biological_databases_part2_v_upload
Prof. Wim Van Criekinge
 
PPT
My sql
Muhammad Umar
 
PPTX
Ch 2-introduction to dbms
Rupali Rana
 
PPTX
Data Manipulation ppt. for BSIT students
julie4baxtii
 
PPTX
Data types and variables in php for writing and databse
vishal choudhary
 
PPTX
2016 02 23_biological_databases_part2
Prof. Wim Van Criekinge
 
PDF
DATA MANAGEMENT computer science class 12 unit - 3 notes.pdf
NeetuPrasad16
 
PPT
PHP - Getting good with MySQL part I
Firdaus Adib
 
PPTX
2017 biological databasespart2
Prof. Wim Van Criekinge
 
PDF
ADBMS unit 1.pdfsdgdsgdsgdsgdsgdsgdsgdsg
zmulani8
 
PDF
Class XII-UNIT III - SQL and MySQL Notes_0.pdf
rohithlingineni1
 
PPTX
Introduction to my_sql
Basavaraj Hampali
 
PPT
mySQL and Relational Databases
webhostingguy
 
sql_data.pdf
VandanaGoyal21
 
Mysql database
Arshikhan08
 
Sql a practical introduction
sanjaychauhan689
 
MySQL for beginners
Saeid Zebardast
 
Ch-11 Relational Databases.pptx
ShadowDawg
 
Complete SQL in one video by shradha.pdf
rahulashu699
 
Sql a practical_introduction
investnow
 
2018 02 20_biological_databases_part2_v_upload
Prof. Wim Van Criekinge
 
Ch 2-introduction to dbms
Rupali Rana
 
Data Manipulation ppt. for BSIT students
julie4baxtii
 
Data types and variables in php for writing and databse
vishal choudhary
 
2016 02 23_biological_databases_part2
Prof. Wim Van Criekinge
 
DATA MANAGEMENT computer science class 12 unit - 3 notes.pdf
NeetuPrasad16
 
PHP - Getting good with MySQL part I
Firdaus Adib
 
2017 biological databasespart2
Prof. Wim Van Criekinge
 
ADBMS unit 1.pdfsdgdsgdsgdsgdsgdsgdsgdsg
zmulani8
 
Class XII-UNIT III - SQL and MySQL Notes_0.pdf
rohithlingineni1
 
Introduction to my_sql
Basavaraj Hampali
 
mySQL and Relational Databases
webhostingguy
 
Ad

More from YUCHENG HU (20)

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

Recently uploaded (20)

PPTX
AI and Robotics for Human Well-being.pptx
JAYMIN SUTHAR
 
PDF
TrustArc Webinar - Navigating Data Privacy in LATAM: Laws, Trends, and Compli...
TrustArc
 
PPTX
IT Runs Better with ThousandEyes AI-driven Assurance
ThousandEyes
 
PDF
MASTERDECK GRAPHSUMMIT SYDNEY (Public).pdf
Neo4j
 
PDF
CIFDAQ's Market Wrap : Bears Back in Control?
CIFDAQ
 
PDF
Per Axbom: The spectacular lies of maps
Nexer Digital
 
PDF
Build with AI and GDG Cloud Bydgoszcz- ADK .pdf
jaroslawgajewski1
 
PPTX
Applied-Statistics-Mastering-Data-Driven-Decisions.pptx
parmaryashparmaryash
 
PDF
Brief History of Internet - Early Days of Internet
sutharharshit158
 
PPTX
Agile Chennai 18-19 July 2025 | Emerging patterns in Agentic AI by Bharani Su...
AgileNetwork
 
PDF
Economic Impact of Data Centres to the Malaysian Economy
flintglobalapac
 
PPTX
Farrell_Programming Logic and Design slides_10e_ch02_PowerPoint.pptx
bashnahara11
 
PPTX
Simple and concise overview about Quantum computing..pptx
mughal641
 
PDF
Make GenAI investments go further with the Dell AI Factory
Principled Technologies
 
PDF
RAT Builders - How to Catch Them All [DeepSec 2024]
malmoeb
 
PDF
Presentation about Hardware and Software in Computer
snehamodhawadiya
 
PPTX
Introduction to Flutter by Ayush Desai.pptx
ayushdesai204
 
PPTX
Agentic AI in Healthcare Driving the Next Wave of Digital Transformation
danielle hunter
 
PDF
introduction to computer hardware and sofeware
chauhanshraddha2007
 
PDF
Peak of Data & AI Encore - Real-Time Insights & Scalable Editing with ArcGIS
Safe Software
 
AI and Robotics for Human Well-being.pptx
JAYMIN SUTHAR
 
TrustArc Webinar - Navigating Data Privacy in LATAM: Laws, Trends, and Compli...
TrustArc
 
IT Runs Better with ThousandEyes AI-driven Assurance
ThousandEyes
 
MASTERDECK GRAPHSUMMIT SYDNEY (Public).pdf
Neo4j
 
CIFDAQ's Market Wrap : Bears Back in Control?
CIFDAQ
 
Per Axbom: The spectacular lies of maps
Nexer Digital
 
Build with AI and GDG Cloud Bydgoszcz- ADK .pdf
jaroslawgajewski1
 
Applied-Statistics-Mastering-Data-Driven-Decisions.pptx
parmaryashparmaryash
 
Brief History of Internet - Early Days of Internet
sutharharshit158
 
Agile Chennai 18-19 July 2025 | Emerging patterns in Agentic AI by Bharani Su...
AgileNetwork
 
Economic Impact of Data Centres to the Malaysian Economy
flintglobalapac
 
Farrell_Programming Logic and Design slides_10e_ch02_PowerPoint.pptx
bashnahara11
 
Simple and concise overview about Quantum computing..pptx
mughal641
 
Make GenAI investments go further with the Dell AI Factory
Principled Technologies
 
RAT Builders - How to Catch Them All [DeepSec 2024]
malmoeb
 
Presentation about Hardware and Software in Computer
snehamodhawadiya
 
Introduction to Flutter by Ayush Desai.pptx
ayushdesai204
 
Agentic AI in Healthcare Driving the Next Wave of Digital Transformation
danielle hunter
 
introduction to computer hardware and sofeware
chauhanshraddha2007
 
Peak of Data & AI Encore - Real-Time Insights & Scalable Editing with ArcGIS
Safe Software
 

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
  • 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
  • 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