SlideShare une entreprise Scribd logo
1  sur  36
Télécharger pour lire hors ligne
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

Contenu connexe

Tendances (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
 

En vedette

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
 

En vedette (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á
 

Similaire à 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
 

Similaire à 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
 

Plus 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
 

Plus 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 简要介绍
 

Dernier

Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesSinan KOZAK
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Servicegiselly40
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsTop 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsRoshan Dwivedi
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...Neo4j
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Scriptwesley chun
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024Results
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024The Digital Insurer
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEarley Information Science
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 

Dernier (20)

Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen Frames
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsTop 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 

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