SlideShare a Scribd company logo
1 of 71
Download to read offline
Sol Genomics Network
Databases and SQL syntax
workshop
UPLB January 2016
Noe Fernandez-Pozo
Sol Genomics Network
• Relational and not relational databases
• PostgreSQL and SQL syntax
• Table relationships and constraints
Class Content
Sol Genomics Network
Relational Databases
Databases structured to
recognize relations among
stored items of information.
Sol Genomics Network
Relational Database Schemas
Sol Genomics Network
SGN Database
An ontology-based modular schema
for representing genome-associated
biological information
genes, genomes, sequences, maps, markers, users, expression
data, phenotipic data, breeding data, blast management …
https://solgenomics.net
+
Sol Genomics Network
Non Relational Databases
Non-relational databases, also called NoSQL databases.
• GBS
• Breeding data
• Phenotypic data
• Variation data
Sol Genomics Network
Indexed Files
• BLAST databases
• Bowtie indexes
• JBrowse
Sol Genomics Network
SQL Language
http://www.postgresql.org
The world’s most advanced
open source database
http://www.postgresql.org/docs/9.4/static/sql-commands.html
Sol Genomics Network
Connect to a database for the first time
sudo -u postgres psql postgres
install postgreSQL
sudo aptitude install postgresql
connect for the first time
password user change user password
du list roles
postgreSQL
Terminal
UNIX
Terminal
Sol Genomics Network
Connect to a PostgreSQL Database
psql --help
psql help
man psql
psql manual
Sol Genomics Network
Connect to a PostgreSQL database
psql -h host —U user
Connect to the database
psql -h localhost —U bioinfo -d pineapple_backup
Connect to the database using bioinfo user
psql -h localhost —U postgres
Connect to the database using postgres user
Sol Genomics Network
Create and alter a role
du list roles
CREATE ROLE bioinfo WITH LOGIN ENCRYPTED PASSWORD 'bioinfo' CREATEDB;
create role with permission to create databases
DROP ROLE bioinfo;
delete role bioinfo
ALTER ROLE bioinfo CREATEROLE CREATEDB REPLICATION SUPERUSER;
grant all permissions to bioinfo user
http://www.postgresql.org/docs/9.4/static/sql-alterrole.html
Sol Genomics Network
SQL syntax
• Create, edit and delete databases and schemas

• Import and export databases

• Create, edit and delete tables

• Import tables from a file

• Transactions: begin, rollback and commit

• Insert data and update data in databases

• Explore databases, schemas and tables

• Select and conditions: limit, offset, distinct, where, etc.

• Basic table joining
Sol Genomics Network
Basic
Commands
Sol Genomics Network
Basic Commands
? show help
h SQL syntax help
h create database SQL syntax help
l List databases
c mydb Connect to a database
q quit psql
http://www.postgresql.org/docs/9.4/static/sql-commands.html
Sol Genomics Network
Basic Commands
dn list schemas from the database
dt list all tables from public schema
dt sgn.* list all tables from sgn schema
d blast_db list all tables from sgn schema
o file.txt send output to file
Sol Genomics Network
SQL
Development
Commands
Sol Genomics Network
Create Database
CREATE DATABASE db_name;
create a database
CREATE DATABASE db_name WITH OWNER user1 ENCODING ‘UTF8’;
create a database and define owner and encoding
l list all databases
CREATE DATABASE pineapple_db;
create a database called pineapple_db
Sol Genomics Network
Grant Permissions
GRANT ALL PRIVILEGES ON DATABASE db_name TO user1;
grant permissions to an user on a database
SELECT ("read")
UPDATE ("write")
INSERT ("append")
DELETE
TRUNCATE
REFERENCES
CREATE
CONNECT
TEMPORARY
ALL PRIVILEGES
Sol Genomics Network
Grant Permissions
rolename=xxxx -- privileges granted to a role
=xxxx -- privileges granted to PUBLIC
r -- SELECT ("read")
w -- UPDATE ("write")
a -- INSERT ("append")
d -- DELETE
D -- TRUNCATE
x -- REFERENCES
t -- TRIGGER
X -- EXECUTE
U -- USAGE
C -- CREATE
c -- CONNECT
T -- TEMPORARY
arwdDxt -- ALL PRIVILEGES (for tables, varies for other objects)
* -- grant option for preceding privilege
/yyyy -- role that granted this privilege
dp mytable
Access privileges
Schema | Name | Type | Access privileges | Column access privileges
--------+---------+-------+-----------------------+--------------------------
public | mytable | table | bioinfo=arwdDxt/bioinfo | col1:
: =r/bioinfo : bioinfo_rw=rw/bioinfo
: admin=arw/bioinfo
Sol Genomics Network
ALTER DATABASE db_name RENAME TO new_db_name;
rename database db_name to new_db_name
Edit a Database
ALTER DATABASE db_name OWNER TO new_owner;
change database owner
Sol Genomics Network
How To Delete a Database
DROP DATABASE db_name;
delete a database
DROP DATABASE pineapple_db;
delete a database called pineapple_db
Sol Genomics Network
Dump a database
pg_dump -U user -h host -W db_name > db_file
back up a database
pg_dump -U postgres -h localhost pineapple_db > pineapple_dump.sql
back up a database called pineapple_db
ask for password
Sol Genomics Network
Import a Dumped Database
cat pineapple_dump.sql | psql -U postgres -h localhost -d pineapple_db
import a database
CREATE DATABASE pineapple_db; create a database
Sol Genomics Network
Exercises I
1. Print in a file the table info (not the data) for all the tables in
pineapple_backup

2. Create and delete a user with your name (no bioinfo)

3. Create a database called new_pineapple

4. Rename that database to pineapple_demo

5. Export the database pineapple_backup in a file called
pineapple_backup.sql

6. Import the database pineapple_backup into
pineapple_demo
Sol Genomics Network
type
column
title
column
file_base
column
primary key
column
Table Estructure
blast_db_id | file_base | title | type
-------------+------------------------------+----------------------------------------------+------------
1 | unigene/Capsicum_combined | Capsicum annuum (pepper) Unigenes | nucleotide
2 | unigene/Ipomoea_batatas | Ipomoea batatas (sweet potato) Unigenes | nucleotide
3 | unigene/Nicotiana_sylvestris | Nicotiana sylvestris (wood tobacco) Unigenes | nucleotide
4 | unigene/Petunia_hybrida | Petunia hybrida Unigenes | nucleotide
5 | genbank/nt | NCBI NT comprehensive nucleotide database | nucleotide
Columns
Sol Genomics Network
Table Estructure
Row
blast_db_id | file_base | title | type
-------------+------------------------------+----------------------------------------------+------------
1 | unigene/Capsicum_combined | Capsicum annuum (pepper) Unigenes | nucleotide
2 | unigene/Ipomoea_batatas | Ipomoea batatas (sweet potato) Unigenes | nucleotide
3 | unigene/Nicotiana_sylvestris | Nicotiana sylvestris (wood tobacco) Unigenes | nucleotide
4 | unigene/Petunia_hybrida | Petunia hybrida Unigenes | nucleotide
5 | genbank/nt | NCBI NT comprehensive nucleotide database | nucleotide
Sol Genomics Network
UNIQUE NOT NULL nucleotide
or
protein
Constraints
blast_db_id | file_base | title | type
-------------+------------------------------+----------------------------------------------+------------
31 | unigene/Capsicum_combined | Capsicum annuum (pepper) protein sequences | protein
71 | unigene/Ipomoea_batatas | Ipomoea batatas (sweet potato) Unigenes | nucleotide
70 | unigene/Nicotiana_sylvestris | Nicotiana sylvestris (wood tobacco) Unigenes | nucleotide
29 | unigene/Petunia_hybrida | Petunia hybrida Unigenes | nucleotide
15 | genbank/nt | NCBI NT comprehensive nucleotide database | nucleotide
• NOT NULL Constraint: Ensures that a column cannot have NULL value.
• UNIQUE Constraint: Ensures that all values in a column are different.
• PRIMARY Key: Uniquely identifies each row/record in a database table.
• FOREIGN Key: Constrains data based on columns in other tables.
• CHECK Constraint: The CHECK constraint ensures that all values in a column
satisfy certain conditions.
Sol Genomics Network
Database Schema

Relationships and Normalization
gene
gene_id
gene_name
gene_description
organism_name
sequence
sequence_length
sequence_type
primary_key
gene_id | gene_name | gene_description | organism_name | sequence | sequence_length | sequence_type
---------+-----------+------------------+---------------+----------------+--------------—-—+-----------—--
1 | Aco000001 | 60S ribosomal | Pineapple | ATGTCGTCGATTTA | 432 | nucleotide
2 | Aco000002 | 26S proteasome | Pineapple | ATGAATTGCGAGAC | 512 | nucleotide
3 | Aco000003 | microtubule | Pineapple | ATGGATGATGCGCA | 765 | nucleotide
4 | Aco000004 | DNA polymerase | Pineapple | MSSIIDKTKRTKKA | 180 | protein
5 | Aco000005 | Ubiquitin | Pineapple | MDDAPVPVAEPTLM | 214 | protein
6 | Aco000001 | 60S ribosomal | Pineapple | MSSIIDKTKRTKKA | 142 | protein
7 | Aco000002 | 26S proteasome | Pineapple | MDDAPVPVAEPTLM | 174 | protein
Sol Genomics Network
One To Many
gene
gene_id
name
description
organism_id
sequence
sequence_id
sequence
type
length
gene_id
organism
organism_id
scientific_name
common_name
1 * 1 *
has many has many
foreign_key
primary_key
gene_id | name | description | organism_id
---------+-----------+----------------+-------------
1 | Aco000001 | 60S ribosomal | 1
2 | Aco000002 | 26S proteasome | 1
3 | Aco000003 | microtubule | 1
4 | Aco000004 | DNA polymerase | 1
5 | Aco000005 | Ubiquitin | 1
organism_id | scientific_name | common_name
-------------+-----------------+-------------
1 | Ananas comosus | Pineapple
sequence_id | sequence | length | type | gene_id
-----------—+----------------+--------+-----------—+—---—---—
1 | ATGTCGTCGATTTA | 432 | nucleotide | 1
2 | ATGAATTGCGAGAC | 512 | nucleotide | 2
3 | ATGGATGATGCGCA | 765 | nucleotide | 3
4 | MSSIIDKTKRTKKA | 180 | protein | 1
5 | MDDAPVPVAEPTLM | 214 | protein | 2
Sol Genomics Network
One To Many
gene_id | name | description | organism_id
---------+-----------+----------------+-------------
1 | Aco000001 | 60S ribosomal | 1
2 | Aco000002 | 26S proteasome | 1
3 | Aco000003 | microtubule | 1
4 | Aco000004 | DNA polymerase | 1
5 | Aco000005 | Ubiquitin | 1
organism_id | scientific_name | common_name
-------------+-----------------+-------------
1 | Ananas comosus | Pineapple
gene_id | gene_name | gene_description | organism_name | sequence | sequence_length | sequence_type
---------+-----------+------------------+---------------+----------------+--------------—-—+-----------—--
1 | Aco000001 | 60S ribosomal | Pineapple | ATGTCGTCGATTTA | 432 | nucleotide
2 | Aco000002 | 26S proteasome | Pineapple | ATGAATTGCGAGAC | 512 | nucleotide
3 | Aco000003 | microtubule | Pineapple | ATGGATGATGCGCA | 765 | nucleotide
4 | Aco000004 | DNA polymerase | Pineapple | MSSIIDKTKRTKKA | 180 | protein
5 | Aco000005 | Ubiquitin | Pineapple | MDDAPVPVAEPTLM | 214 | protein
sequence_id | sequence | length | type | gene_id
-----------—+----------------+--------+-----------—+—---—---—
1 | ATGTCGTCGATTTA | 432 | nucleotide | 1
2 | ATGAATTGCGAGAC | 512 | nucleotide | 2
3 | ATGGATGATGCGCA | 765 | nucleotide | 3
4 | MSSIIDKTKRTKKA | 180 | protein | 1
5 | MDDAPVPVAEPTLM | 214 | protein | 2
Sol Genomics Network
Many To Many
blast_db
blast_db_id
name
description
path
group
group_order
BLAST databases
classified in categories
Sol Genomics Network
Many To Many Relationship
blast_db_blast_db_group
blast_db_blast_db_group_id
blast_db_id
blast_db_group_id
blast_db_group
blast_db_group_id
name
ordinal
blast_db
blast_db_id
name
description
path
1 *
*
1
foreign_key
primary_key
primary_key
primary_key
Sol Genomics Network
Create a Schema
CREATE SCHEMA schema_name;
create a schema
CREATE SCHEMA IF NOT EXISTS schema_name AUTHORIZATION user_name;
create a schema schema_name owned by user_name if it does not exist already
Sol Genomics Network
ALTER SCHEMA name RENAME TO new_name;
rename schema name to new_name
Edit a Schema
ALTER SCHEMA name OWNER TO new_owner;
change schema owner
Sol Genomics Network
How To Delete a Schema
DROP SCHEMA schema_name CASCADE;
delete a schema
DROP SCHEMA blast RESTRICT;
delete a schema called blast Refuse to drop the schema if it
contains any objects. This is the
default.
Sol Genomics Network
Create a New Table
CREATE TABLE table_name ();
create an empty table
CREATE TABLE sgn.blast_db ();
create an empty table blast_db in sgn schema
Sol Genomics Network
Create a Table
CREATE TABLE gene (
gene_id bigserial PRIMARY KEY,
name varchar(80) UNIQUE NOT NULL,
description text,
length integer,
sequence text,
organism_id bigserial REFERENCES organism (organism_id)
);
large autoincrementing integer
the value is a number
row unique id
link to another table row id
this column cannot be empty
gene
gene_id
name
description
length
sequence
organism_id
Sol Genomics Network
Create a Table
CREATE TABLE gene (
gene_id bigserial PRIMARY KEY,
name varchar(80) UNIQUE NOT NULL,
description text,
length integer,
sequence text,
organism_id bigserial REFERENCES organism (organism_id)
);
value limited to 80 variable characters values cannot be repeated
variable characters unlimited length
gene
gene_id
name
description
length
sequence
organism_id
Sol Genomics Network
Numeric Types
Sol Genomics Network
Edit Tables
ALTER TABLE mytable ADD COLUMN mycolumn varchar(30);
add a column of type varchar to a table
ALTER TABLE gene DROP COLUMN sequence RESTRICT;
drop a column from a table
ALTER TABLE gene ALTER COLUMN name TYPE varchar(40);
change column type
ALTER TABLE gene RENAME COLUMN name TO gene_name;
rename a column
Sol Genomics Network
Delete a Table Using Drop
DROP TABLE table_name CASCADE;
delete a table
DROP TABLE gene RESTRICT;
delete a table called gene Refuse to drop the table if any
objects depend on it. This is the
default.
Sol Genomics Network
Delete all rows from a table
TRUNCATE table_name CASCADE;
delete rows from a table
TRUNCATE gene RESTART IDENTITY;
empty the table gene and restart primary id index
TRUNCATE gene, blast_db;
empty all the rows from tables gene and blast_db
Sol Genomics Network
Delete a Table
DELETE FROM table_name;
empty a table
DELETE FROM gene WHERE column=‘value’;
delete the rows from table gene based on a condition
Sol Genomics Network
DropVs.TruncateVs Delete
DROP TABLE removes tables from the database. Only the table owner, the schema owner, and superuser
can drop a table. To empty a table of rows without destroying the table, use DELETE or TRUNCATE.

To drop a table that is referenced a foreign-key constraint of another table, CASCADE must be specified.
(CASCADE will only remove the foreign-key constraint, not the other table entirely.)
DROP TABLE -- remove a table
TRUNCATE -- empty a table or set of tables
TRUNCATE quickly removes all rows from a set of tables. Very useful on large tables.
DELETE -- delete rows of a table based on a condition
DELETE deletes rows that satisfy the WHERE clause from the specified table. If the WHERE clause is
absent, the effect is to delete all rows in the table. The result is a valid, but empty table.
Sol Genomics Network
Create New Tables From SQL File
psql -U username -d myDataBase -W -a -f myInsertFile
create tables from a file
psql -U bioinfo -d pineapple_demo -h localhost -a -f gene_tables.sql
create tables from gene_tables.sql file in pineapple_demo database
ask for password
print input from file
Sol Genomics Network
Exercises II
1. Create a database called ananas

2. Create a table called “Genes” with the columns:

• name

• description

• sequence

3. Rename the table “Genes” to “gene”

4. Remove the column “sequence”

5. Add a column named organism_id

6. What are the “gene” table column types? (integer, text…)

7. Drop the table “gene”
Sol Genomics Network
Exercises II
8. Use truncate to delete all the sequences from
pineapple_demo (created in Exercises I)

9. Write in a file the code to create the next tables and
load them into a database called ananas
gene
gene_id
name
description
organism_id
sequence
sequence_id
sequence
length
type
gene_id
organism
organism_id
scientific_name
common_name
1 * 1 *
has many has many
Sol Genomics Network
Database Schema
gene
gene_id
name
description
organism_id
sequence
sequence_id
sequence
length
type
gene_id
organism
organism_id
scientific_name
common_name
1 * 1 *
has many has many
psql -U bioinfo -d pineapple_demo -h localhost -a -f gene_tables.sql
psql -U bioinfo -d pineapple_demo -h localhost -a -f blastdb_tables.sql
Sol Genomics Network
Insert Rows
INSERT INTO mytable (col1,col2) VALUES (‘val1’,’val2’);
insert values into a table
INSERT INTO gene (name,description) VALUES (‘Solyc01g001’,’unknown’);
insert gene name and description into gene table
Sol Genomics Network
Update Rows
UPDATE mytable SET col1=‘val1’ WHERE col2=‘val2’;
change column values from a row
UPDATE gene SET name = ‘Solyc01g001’ WHERE gene_id=1;
set gene name to Solyc01g001 for the row with gene_id 1
UPDATE mytable SET a=5, b=3, c=1 WHERE a>0;
change several column
values from a row
Sol Genomics Network
Delete Rows
DELETE FROM mytable WHERE column=‘value’;
delete the rows from table gene based on a condition
DELETE FROM gene WHERE length<=‘100’;
delete genes smaller than 100 nucleotides
DELETE FROM gene WHERE name=‘Solyc01g001’; delete gene named
Solyc01g001
gene
gene_id
name
description
length
Sol Genomics Network
Transactions
BEGIN;
INSERT INTO gene (name,description) VALUES (‘Solyc01g001’,’unknown’);
COMMIT;
commit a transaction
BEGIN;
UPDATE gene SET name=‘Solyc01g001’ WHERE gene_id=1;
ROLLBACK;
undo a transaction
Sol Genomics Network
Exercises III
1. Insert into the tables organism, gene and sequence the first
two sequences from the file pineapple_5k_proteins.fasta
from the folder ~/Desktop/Data

2. Create a database called pineapple_copy and import the
data from pineapple_backup.sql file created in Exercises I

3. Use transactions to delete the sequences longer than 100
amino acids from pineapple_copy
Sol Genomics Network
Database Schema
gene
gene_id
name
description
organism_id
sequence
sequence_id
sequence
length
type
gene_id
organism
organism_id
scientific_name
common_name
1 * 1 *
scripts to upload data. Eg: load_pineapple_fasta.pl
has many has many
Sol Genomics Network
SQL query
commands
Sol Genomics Network
Querying a Table
SELECT * FROM mytable;
query all the data from the table
SELECT name,description FROM gene;
get the name and description from all the genes gene
gene_id
name
description
organism_id
Sol Genomics Network
Select - Where
SELECT * FROM mytable WHERE col1=‘val1’;
query all the rows from a table for a condition
SELECT name,description FROM gene WHERE name=‘Aco000001’;
get the name and description from gene Aco000001
gene
gene_id
name
description
organism_id
Sol Genomics Network
Limit and Offset
SELECT * FROM mytable LIMIT 10;
display the first 10 entries found
SELECT name FROM gene OFFSET 10;
display the last 10 gene names found in table gene
Sol Genomics Network
Select - Distinct
SELECT DISTINCT col1 FROM mytable;
get the different entries for col1 on mytable
SELECT DISTINCT description FROM gene;
get the different descriptions from the gene table
gene
gene_id
name
description
organism_id
Sol Genomics Network
Count
SELECT COUNT(*) FROM mytable;
count rows from table
SELECT COUNT(DISTINCT description) FROM gene;
count the different descriptions from gene table
SELECT COUNT(name) FROM gene; count the gene names
gene
gene_id
name
description
organism_id
Sol Genomics Network
Sort Query Results
SELECT * FROM mytable ORDER BY col1;
get all the rows from mytable sorted by column 1
SELECT sequence_id,length FROM sequence ORDER BY length ASC;
get all the sequence_id values sorted by
sequence length in descendant order
sequence
sequence_id
sequence
length
type
gene_id
SELECT sequence_id,length FROM sequence ORDER BY length DESC;
ascendant order
Sol Genomics Network
In
SELECT * FROM mytable WHERE col1 IN (‘val1’,’val2’);
query all the rows for several values from a column
SELECT * FROM gene WHERE gene_id IN (1,2);
get the rows for the genes with id 1 and 2
gene
gene_id
name
description
organism_id
Sol Genomics Network
Comparison Operators
In addition to the comparison operators, 

the special BETWEEN construct is available:

WHERE col_name BETWEEN x AND y

is equivalent to

WHERE col_name >= x AND col_name <= y

Notice that BETWEEN treats the endpoint values as included in the range. NOT BETWEEN
does the opposite comparison:

WHERE col_name NOT BETWEEN x AND y

is equivalent to

WHERE col_name < x OR col_name > y
Sol Genomics Network
NULL
Sol Genomics Network
Like
SELECT * FROM mytable WHERE col1 LIKE ‘ribosomal’;
return all the rows when col is equal to ribosomal
SELECT * FROM gene WHERE description ILIKE ‘ribosomal%’;
return all the rows with description starting with ribosomal
SELECT * FROM gene WHERE description NOT LIKE ‘%ribosomal%’;
return all the rows with description not containing ribosomal
case insensitive search
Sol Genomics Network
Like and iLike
LIKE case sensitive comparison
iLIKE case insensitive comparison
_ one character wildcard
% wildcard
LIKE ‘ribosomal’
LIKE ‘ribosomal%’
LIKE ‘%ribosomal’
LIKE ‘%ribosomal%’
LIKE ‘Ribosomal%’
LIKE ‘_ibosomal%’
iLIKE ‘%ribosomal%’
NOT LIKE ‘%ribosomal’
SELECT * FROM gene WHERE description LIKE ‘ribosomal’;
See the results and count the output for
Sol Genomics Network
Join Tables
SELECT * FROM table1 JOIN table2 USING(common_id);
join two tables by a common id
SELECT * FROM table1 JOIN table2 ON(id1=id2) where …;
join two tables using two ids with equivalent values
Sol Genomics Network
Exercises IV
1. Find the 10 longest genes in pineapple_backup

2. Find the 10 shortest genes in pineapple_backup

3. How many different descriptions are in
pineapple_backup

4. How many genes are in in pineapple_backup

5. What is the description for the gene Aco005884?

6. What is the description for the gene with id 4341?

7. What is the gene with the first description
alphabetically?

8. And the last one?
Sol Genomics Network
Exercises IV
9. How many gene description start with A (uppercase A)

10. How many different descriptions start with A

11. What is the name, description and length of the longest gene
starting with A?

12. What are the genes with length between 118 and 120?

13. And their descriptions?

14. What is the longest protein containing ribosomal in its
description? (case insensitive)

15. What are the genes smaller than 50 or longer than 3000
amino acids?
Sol Genomics Network
Exercises IV
16. What are the descriptions for the genes Aco000443.1 and
Aco000775.1?

17. Save in a file all the organism, gene and sequence
information for the entries with gene ids 427 and 752

More Related Content

Similar to Introduction to SQL

Databases_CSS2.pptx
Databases_CSS2.pptxDatabases_CSS2.pptx
Databases_CSS2.pptxSilpa87
 
Seqr - Protein Sequence Search: Presented by Lianyi Han, Medical Science & Co...
Seqr - Protein Sequence Search: Presented by Lianyi Han, Medical Science & Co...Seqr - Protein Sequence Search: Presented by Lianyi Han, Medical Science & Co...
Seqr - Protein Sequence Search: Presented by Lianyi Han, Medical Science & Co...Lucidworks
 
ECCB 2014: Extracting patterns of database and software usage from the bioinf...
ECCB 2014: Extracting patterns of database and software usage from the bioinf...ECCB 2014: Extracting patterns of database and software usage from the bioinf...
ECCB 2014: Extracting patterns of database and software usage from the bioinf...geraintduck
 
MySQL Baics - Texas Linxufest beginners tutorial May 31st, 2019
MySQL Baics - Texas Linxufest beginners tutorial May 31st, 2019MySQL Baics - Texas Linxufest beginners tutorial May 31st, 2019
MySQL Baics - Texas Linxufest beginners tutorial May 31st, 2019Dave Stokes
 
Oracle12c Pluggable Database Hands On - TROUG 2014
Oracle12c Pluggable Database Hands On - TROUG 2014Oracle12c Pluggable Database Hands On - TROUG 2014
Oracle12c Pluggable Database Hands On - TROUG 2014Özgür Umut Vurgun
 
Role of bioinformatics in life sciences research
Role of bioinformatics in life sciences researchRole of bioinformatics in life sciences research
Role of bioinformatics in life sciences researchAnshika Bansal
 
2016 bioinformatics i_databases_wim_vancriekinge
2016 bioinformatics i_databases_wim_vancriekinge2016 bioinformatics i_databases_wim_vancriekinge
2016 bioinformatics i_databases_wim_vancriekingeProf. Wim Van Criekinge
 
Postgresql Database Administration Basic - Day2
Postgresql  Database Administration Basic  - Day2Postgresql  Database Administration Basic  - Day2
Postgresql Database Administration Basic - Day2PoguttuezhiniVP
 
RMAN in 12c: The Next Generation (PPT)
RMAN in 12c: The Next Generation (PPT)RMAN in 12c: The Next Generation (PPT)
RMAN in 12c: The Next Generation (PPT)Gustavo Rene Antunez
 
DAS (Distributed Annotation System): Introduction
DAS (Distributed Annotation System): IntroductionDAS (Distributed Annotation System): Introduction
DAS (Distributed Annotation System): IntroductionRafael C. Jimenez
 
Swertz bosc2010 molgenis
Swertz bosc2010 molgenisSwertz bosc2010 molgenis
Swertz bosc2010 molgenisBOSC 2010
 
Overview of oracle database
Overview of oracle databaseOverview of oracle database
Overview of oracle databaseSamar Prasad
 
Overview of oracle database
Overview of oracle databaseOverview of oracle database
Overview of oracle databaseSamar Prasad
 

Similar to Introduction to SQL (20)

Enfin, DAS and BioMart
Enfin, DAS and BioMartEnfin, DAS and BioMart
Enfin, DAS and BioMart
 
NGS: Mapping and de novo assembly
NGS: Mapping and de novo assemblyNGS: Mapping and de novo assembly
NGS: Mapping and de novo assembly
 
Postgre sql unleashed
Postgre sql unleashedPostgre sql unleashed
Postgre sql unleashed
 
Databases_CSS2.pptx
Databases_CSS2.pptxDatabases_CSS2.pptx
Databases_CSS2.pptx
 
Seqr - Protein Sequence Search: Presented by Lianyi Han, Medical Science & Co...
Seqr - Protein Sequence Search: Presented by Lianyi Han, Medical Science & Co...Seqr - Protein Sequence Search: Presented by Lianyi Han, Medical Science & Co...
Seqr - Protein Sequence Search: Presented by Lianyi Han, Medical Science & Co...
 
ECCB 2014: Extracting patterns of database and software usage from the bioinf...
ECCB 2014: Extracting patterns of database and software usage from the bioinf...ECCB 2014: Extracting patterns of database and software usage from the bioinf...
ECCB 2014: Extracting patterns of database and software usage from the bioinf...
 
MySQL Baics - Texas Linxufest beginners tutorial May 31st, 2019
MySQL Baics - Texas Linxufest beginners tutorial May 31st, 2019MySQL Baics - Texas Linxufest beginners tutorial May 31st, 2019
MySQL Baics - Texas Linxufest beginners tutorial May 31st, 2019
 
Intro to databases
Intro to databasesIntro to databases
Intro to databases
 
Perl Programming - 04 Programming Database
Perl Programming - 04 Programming DatabasePerl Programming - 04 Programming Database
Perl Programming - 04 Programming Database
 
2016 02 23_biological_databases_part1
2016 02 23_biological_databases_part12016 02 23_biological_databases_part1
2016 02 23_biological_databases_part1
 
Oracle12c Pluggable Database Hands On - TROUG 2014
Oracle12c Pluggable Database Hands On - TROUG 2014Oracle12c Pluggable Database Hands On - TROUG 2014
Oracle12c Pluggable Database Hands On - TROUG 2014
 
Role of bioinformatics in life sciences research
Role of bioinformatics in life sciences researchRole of bioinformatics in life sciences research
Role of bioinformatics in life sciences research
 
Overview of RedDatabase 2.5
Overview of RedDatabase 2.5Overview of RedDatabase 2.5
Overview of RedDatabase 2.5
 
2016 bioinformatics i_databases_wim_vancriekinge
2016 bioinformatics i_databases_wim_vancriekinge2016 bioinformatics i_databases_wim_vancriekinge
2016 bioinformatics i_databases_wim_vancriekinge
 
Postgresql Database Administration Basic - Day2
Postgresql  Database Administration Basic  - Day2Postgresql  Database Administration Basic  - Day2
Postgresql Database Administration Basic - Day2
 
RMAN in 12c: The Next Generation (PPT)
RMAN in 12c: The Next Generation (PPT)RMAN in 12c: The Next Generation (PPT)
RMAN in 12c: The Next Generation (PPT)
 
DAS (Distributed Annotation System): Introduction
DAS (Distributed Annotation System): IntroductionDAS (Distributed Annotation System): Introduction
DAS (Distributed Annotation System): Introduction
 
Swertz bosc2010 molgenis
Swertz bosc2010 molgenisSwertz bosc2010 molgenis
Swertz bosc2010 molgenis
 
Overview of oracle database
Overview of oracle databaseOverview of oracle database
Overview of oracle database
 
Overview of oracle database
Overview of oracle databaseOverview of oracle database
Overview of oracle database
 

More from solgenomics

Sl4.0 and ITAG4.0
Sl4.0 and ITAG4.0Sl4.0 and ITAG4.0
Sl4.0 and ITAG4.0solgenomics
 
Cassavabase-PhenoApps demo ISTRC 2018
Cassavabase-PhenoApps demo ISTRC 2018Cassavabase-PhenoApps demo ISTRC 2018
Cassavabase-PhenoApps demo ISTRC 2018solgenomics
 
Cassavabase-PhenoApp sample tracking
Cassavabase-PhenoApp sample trackingCassavabase-PhenoApp sample tracking
Cassavabase-PhenoApp sample trackingsolgenomics
 
breeding informatics solutions at SGN
breeding informatics solutions at SGNbreeding informatics solutions at SGN
breeding informatics solutions at SGNsolgenomics
 
Musabase PAG 2018
Musabase PAG 2018Musabase PAG 2018
Musabase PAG 2018solgenomics
 
Cassavabase workshop ibadan March17
Cassavabase workshop ibadan March17Cassavabase workshop ibadan March17
Cassavabase workshop ibadan March17solgenomics
 
Improvements in the Tomato Reference Genome (SL3.0) and Annotation (ITAG3.0)
Improvements in the Tomato Reference Genome (SL3.0) and Annotation (ITAG3.0)Improvements in the Tomato Reference Genome (SL3.0) and Annotation (ITAG3.0)
Improvements in the Tomato Reference Genome (SL3.0) and Annotation (ITAG3.0)solgenomics
 
SolGS Hyderabad conference 2016
SolGS Hyderabad conference 2016SolGS Hyderabad conference 2016
SolGS Hyderabad conference 2016solgenomics
 
SolGS workshop 2016
SolGS workshop 2016SolGS workshop 2016
SolGS workshop 2016solgenomics
 
Cassavabase workshop IITA oct2016
Cassavabase workshop IITA oct2016Cassavabase workshop IITA oct2016
Cassavabase workshop IITA oct2016solgenomics
 
Introduction to YamBase
Introduction to YamBaseIntroduction to YamBase
Introduction to YamBasesolgenomics
 
Cassavabase SolGS presentation PAG 2016
Cassavabase SolGS presentation PAG 2016Cassavabase SolGS presentation PAG 2016
Cassavabase SolGS presentation PAG 2016solgenomics
 
Cassavabase SolGS poster PAG 2016
Cassavabase SolGS poster PAG 2016Cassavabase SolGS poster PAG 2016
Cassavabase SolGS poster PAG 2016solgenomics
 
3c Cassavabase workshop: manage-crosses
3c  Cassavabase workshop: manage-crosses3c  Cassavabase workshop: manage-crosses
3c Cassavabase workshop: manage-crossessolgenomics
 
3d Cassavabase workshop: manage field-trial
3d  Cassavabase workshop: manage field-trial3d  Cassavabase workshop: manage field-trial
3d Cassavabase workshop: manage field-trialsolgenomics
 
3e Cassavabase workshop: manage genotyping-trials
3e  Cassavabase workshop: manage genotyping-trials3e  Cassavabase workshop: manage genotyping-trials
3e Cassavabase workshop: manage genotyping-trialssolgenomics
 
3f Cassavabase workshop: manage field-book
3f  Cassavabase workshop: manage field-book3f  Cassavabase workshop: manage field-book
3f Cassavabase workshop: manage field-booksolgenomics
 
3g Cassavabase workshop: manage phenotyping
3g  Cassavabase workshop: manage phenotyping3g  Cassavabase workshop: manage phenotyping
3g Cassavabase workshop: manage phenotypingsolgenomics
 
4 Cassavabase workshop: analyze menu
4  Cassavabase workshop: analyze menu4  Cassavabase workshop: analyze menu
4 Cassavabase workshop: analyze menusolgenomics
 

More from solgenomics (20)

Sl4.0 and ITAG4.0
Sl4.0 and ITAG4.0Sl4.0 and ITAG4.0
Sl4.0 and ITAG4.0
 
Cassavabase-PhenoApps demo ISTRC 2018
Cassavabase-PhenoApps demo ISTRC 2018Cassavabase-PhenoApps demo ISTRC 2018
Cassavabase-PhenoApps demo ISTRC 2018
 
Cassavabase-PhenoApp sample tracking
Cassavabase-PhenoApp sample trackingCassavabase-PhenoApp sample tracking
Cassavabase-PhenoApp sample tracking
 
breeding informatics solutions at SGN
breeding informatics solutions at SGNbreeding informatics solutions at SGN
breeding informatics solutions at SGN
 
Musabase PAG 2018
Musabase PAG 2018Musabase PAG 2018
Musabase PAG 2018
 
Cassavabase workshop ibadan March17
Cassavabase workshop ibadan March17Cassavabase workshop ibadan March17
Cassavabase workshop ibadan March17
 
Improvements in the Tomato Reference Genome (SL3.0) and Annotation (ITAG3.0)
Improvements in the Tomato Reference Genome (SL3.0) and Annotation (ITAG3.0)Improvements in the Tomato Reference Genome (SL3.0) and Annotation (ITAG3.0)
Improvements in the Tomato Reference Genome (SL3.0) and Annotation (ITAG3.0)
 
SolGS Hyderabad conference 2016
SolGS Hyderabad conference 2016SolGS Hyderabad conference 2016
SolGS Hyderabad conference 2016
 
SolGS workshop 2016
SolGS workshop 2016SolGS workshop 2016
SolGS workshop 2016
 
Cassavabase workshop IITA oct2016
Cassavabase workshop IITA oct2016Cassavabase workshop IITA oct2016
Cassavabase workshop IITA oct2016
 
Sql cheat sheet
Sql cheat sheetSql cheat sheet
Sql cheat sheet
 
Introduction to YamBase
Introduction to YamBaseIntroduction to YamBase
Introduction to YamBase
 
Cassavabase SolGS presentation PAG 2016
Cassavabase SolGS presentation PAG 2016Cassavabase SolGS presentation PAG 2016
Cassavabase SolGS presentation PAG 2016
 
Cassavabase SolGS poster PAG 2016
Cassavabase SolGS poster PAG 2016Cassavabase SolGS poster PAG 2016
Cassavabase SolGS poster PAG 2016
 
3c Cassavabase workshop: manage-crosses
3c  Cassavabase workshop: manage-crosses3c  Cassavabase workshop: manage-crosses
3c Cassavabase workshop: manage-crosses
 
3d Cassavabase workshop: manage field-trial
3d  Cassavabase workshop: manage field-trial3d  Cassavabase workshop: manage field-trial
3d Cassavabase workshop: manage field-trial
 
3e Cassavabase workshop: manage genotyping-trials
3e  Cassavabase workshop: manage genotyping-trials3e  Cassavabase workshop: manage genotyping-trials
3e Cassavabase workshop: manage genotyping-trials
 
3f Cassavabase workshop: manage field-book
3f  Cassavabase workshop: manage field-book3f  Cassavabase workshop: manage field-book
3f Cassavabase workshop: manage field-book
 
3g Cassavabase workshop: manage phenotyping
3g  Cassavabase workshop: manage phenotyping3g  Cassavabase workshop: manage phenotyping
3g Cassavabase workshop: manage phenotyping
 
4 Cassavabase workshop: analyze menu
4  Cassavabase workshop: analyze menu4  Cassavabase workshop: analyze menu
4 Cassavabase workshop: analyze menu
 

Recently uploaded

Stunning ➥8448380779▻ Call Girls In Panchshil Enclave Delhi NCR
Stunning ➥8448380779▻ Call Girls In Panchshil Enclave Delhi NCRStunning ➥8448380779▻ Call Girls In Panchshil Enclave Delhi NCR
Stunning ➥8448380779▻ Call Girls In Panchshil Enclave Delhi NCRDelhi Call girls
 
Spermiogenesis or Spermateleosis or metamorphosis of spermatid
Spermiogenesis or Spermateleosis or metamorphosis of spermatidSpermiogenesis or Spermateleosis or metamorphosis of spermatid
Spermiogenesis or Spermateleosis or metamorphosis of spermatidSarthak Sekhar Mondal
 
Call Us ≽ 9953322196 ≼ Call Girls In Mukherjee Nagar(Delhi) |
Call Us ≽ 9953322196 ≼ Call Girls In Mukherjee Nagar(Delhi) |Call Us ≽ 9953322196 ≼ Call Girls In Mukherjee Nagar(Delhi) |
Call Us ≽ 9953322196 ≼ Call Girls In Mukherjee Nagar(Delhi) |aasikanpl
 
Biopesticide (2).pptx .This slides helps to know the different types of biop...
Biopesticide (2).pptx  .This slides helps to know the different types of biop...Biopesticide (2).pptx  .This slides helps to know the different types of biop...
Biopesticide (2).pptx .This slides helps to know the different types of biop...RohitNehra6
 
Call Girls in Munirka Delhi 💯Call Us 🔝8264348440🔝
Call Girls in Munirka Delhi 💯Call Us 🔝8264348440🔝Call Girls in Munirka Delhi 💯Call Us 🔝8264348440🔝
Call Girls in Munirka Delhi 💯Call Us 🔝8264348440🔝soniya singh
 
Scheme-of-Work-Science-Stage-4 cambridge science.docx
Scheme-of-Work-Science-Stage-4 cambridge science.docxScheme-of-Work-Science-Stage-4 cambridge science.docx
Scheme-of-Work-Science-Stage-4 cambridge science.docxyaramohamed343013
 
Unlocking the Potential: Deep dive into ocean of Ceramic Magnets.pptx
Unlocking  the Potential: Deep dive into ocean of Ceramic Magnets.pptxUnlocking  the Potential: Deep dive into ocean of Ceramic Magnets.pptx
Unlocking the Potential: Deep dive into ocean of Ceramic Magnets.pptxanandsmhk
 
VIRUSES structure and classification ppt by Dr.Prince C P
VIRUSES structure and classification ppt by Dr.Prince C PVIRUSES structure and classification ppt by Dr.Prince C P
VIRUSES structure and classification ppt by Dr.Prince C PPRINCE C P
 
Orientation, design and principles of polyhouse
Orientation, design and principles of polyhouseOrientation, design and principles of polyhouse
Orientation, design and principles of polyhousejana861314
 
Boyles law module in the grade 10 science
Boyles law module in the grade 10 scienceBoyles law module in the grade 10 science
Boyles law module in the grade 10 sciencefloriejanemacaya1
 
Behavioral Disorder: Schizophrenia & it's Case Study.pdf
Behavioral Disorder: Schizophrenia & it's Case Study.pdfBehavioral Disorder: Schizophrenia & it's Case Study.pdf
Behavioral Disorder: Schizophrenia & it's Case Study.pdfSELF-EXPLANATORY
 
Biological Classification BioHack (3).pdf
Biological Classification BioHack (3).pdfBiological Classification BioHack (3).pdf
Biological Classification BioHack (3).pdfmuntazimhurra
 
Recombinant DNA technology (Immunological screening)
Recombinant DNA technology (Immunological screening)Recombinant DNA technology (Immunological screening)
Recombinant DNA technology (Immunological screening)PraveenaKalaiselvan1
 
Animal Communication- Auditory and Visual.pptx
Animal Communication- Auditory and Visual.pptxAnimal Communication- Auditory and Visual.pptx
Animal Communication- Auditory and Visual.pptxUmerFayaz5
 
zoogeography of pakistan.pptx fauna of Pakistan
zoogeography of pakistan.pptx fauna of Pakistanzoogeography of pakistan.pptx fauna of Pakistan
zoogeography of pakistan.pptx fauna of Pakistanzohaibmir069
 
Nightside clouds and disequilibrium chemistry on the hot Jupiter WASP-43b
Nightside clouds and disequilibrium chemistry on the hot Jupiter WASP-43bNightside clouds and disequilibrium chemistry on the hot Jupiter WASP-43b
Nightside clouds and disequilibrium chemistry on the hot Jupiter WASP-43bSérgio Sacani
 
NAVSEA PEO USC - Unmanned & Small Combatants 26Oct23.pdf
NAVSEA PEO USC - Unmanned & Small Combatants 26Oct23.pdfNAVSEA PEO USC - Unmanned & Small Combatants 26Oct23.pdf
NAVSEA PEO USC - Unmanned & Small Combatants 26Oct23.pdfWadeK3
 
Disentangling the origin of chemical differences using GHOST
Disentangling the origin of chemical differences using GHOSTDisentangling the origin of chemical differences using GHOST
Disentangling the origin of chemical differences using GHOSTSérgio Sacani
 
SOLUBLE PATTERN RECOGNITION RECEPTORS.pptx
SOLUBLE PATTERN RECOGNITION RECEPTORS.pptxSOLUBLE PATTERN RECOGNITION RECEPTORS.pptx
SOLUBLE PATTERN RECOGNITION RECEPTORS.pptxkessiyaTpeter
 

Recently uploaded (20)

Stunning ➥8448380779▻ Call Girls In Panchshil Enclave Delhi NCR
Stunning ➥8448380779▻ Call Girls In Panchshil Enclave Delhi NCRStunning ➥8448380779▻ Call Girls In Panchshil Enclave Delhi NCR
Stunning ➥8448380779▻ Call Girls In Panchshil Enclave Delhi NCR
 
Spermiogenesis or Spermateleosis or metamorphosis of spermatid
Spermiogenesis or Spermateleosis or metamorphosis of spermatidSpermiogenesis or Spermateleosis or metamorphosis of spermatid
Spermiogenesis or Spermateleosis or metamorphosis of spermatid
 
Call Us ≽ 9953322196 ≼ Call Girls In Mukherjee Nagar(Delhi) |
Call Us ≽ 9953322196 ≼ Call Girls In Mukherjee Nagar(Delhi) |Call Us ≽ 9953322196 ≼ Call Girls In Mukherjee Nagar(Delhi) |
Call Us ≽ 9953322196 ≼ Call Girls In Mukherjee Nagar(Delhi) |
 
Biopesticide (2).pptx .This slides helps to know the different types of biop...
Biopesticide (2).pptx  .This slides helps to know the different types of biop...Biopesticide (2).pptx  .This slides helps to know the different types of biop...
Biopesticide (2).pptx .This slides helps to know the different types of biop...
 
Call Girls in Munirka Delhi 💯Call Us 🔝8264348440🔝
Call Girls in Munirka Delhi 💯Call Us 🔝8264348440🔝Call Girls in Munirka Delhi 💯Call Us 🔝8264348440🔝
Call Girls in Munirka Delhi 💯Call Us 🔝8264348440🔝
 
Scheme-of-Work-Science-Stage-4 cambridge science.docx
Scheme-of-Work-Science-Stage-4 cambridge science.docxScheme-of-Work-Science-Stage-4 cambridge science.docx
Scheme-of-Work-Science-Stage-4 cambridge science.docx
 
Unlocking the Potential: Deep dive into ocean of Ceramic Magnets.pptx
Unlocking  the Potential: Deep dive into ocean of Ceramic Magnets.pptxUnlocking  the Potential: Deep dive into ocean of Ceramic Magnets.pptx
Unlocking the Potential: Deep dive into ocean of Ceramic Magnets.pptx
 
VIRUSES structure and classification ppt by Dr.Prince C P
VIRUSES structure and classification ppt by Dr.Prince C PVIRUSES structure and classification ppt by Dr.Prince C P
VIRUSES structure and classification ppt by Dr.Prince C P
 
Orientation, design and principles of polyhouse
Orientation, design and principles of polyhouseOrientation, design and principles of polyhouse
Orientation, design and principles of polyhouse
 
9953056974 Young Call Girls In Mahavir enclave Indian Quality Escort service
9953056974 Young Call Girls In Mahavir enclave Indian Quality Escort service9953056974 Young Call Girls In Mahavir enclave Indian Quality Escort service
9953056974 Young Call Girls In Mahavir enclave Indian Quality Escort service
 
Boyles law module in the grade 10 science
Boyles law module in the grade 10 scienceBoyles law module in the grade 10 science
Boyles law module in the grade 10 science
 
Behavioral Disorder: Schizophrenia & it's Case Study.pdf
Behavioral Disorder: Schizophrenia & it's Case Study.pdfBehavioral Disorder: Schizophrenia & it's Case Study.pdf
Behavioral Disorder: Schizophrenia & it's Case Study.pdf
 
Biological Classification BioHack (3).pdf
Biological Classification BioHack (3).pdfBiological Classification BioHack (3).pdf
Biological Classification BioHack (3).pdf
 
Recombinant DNA technology (Immunological screening)
Recombinant DNA technology (Immunological screening)Recombinant DNA technology (Immunological screening)
Recombinant DNA technology (Immunological screening)
 
Animal Communication- Auditory and Visual.pptx
Animal Communication- Auditory and Visual.pptxAnimal Communication- Auditory and Visual.pptx
Animal Communication- Auditory and Visual.pptx
 
zoogeography of pakistan.pptx fauna of Pakistan
zoogeography of pakistan.pptx fauna of Pakistanzoogeography of pakistan.pptx fauna of Pakistan
zoogeography of pakistan.pptx fauna of Pakistan
 
Nightside clouds and disequilibrium chemistry on the hot Jupiter WASP-43b
Nightside clouds and disequilibrium chemistry on the hot Jupiter WASP-43bNightside clouds and disequilibrium chemistry on the hot Jupiter WASP-43b
Nightside clouds and disequilibrium chemistry on the hot Jupiter WASP-43b
 
NAVSEA PEO USC - Unmanned & Small Combatants 26Oct23.pdf
NAVSEA PEO USC - Unmanned & Small Combatants 26Oct23.pdfNAVSEA PEO USC - Unmanned & Small Combatants 26Oct23.pdf
NAVSEA PEO USC - Unmanned & Small Combatants 26Oct23.pdf
 
Disentangling the origin of chemical differences using GHOST
Disentangling the origin of chemical differences using GHOSTDisentangling the origin of chemical differences using GHOST
Disentangling the origin of chemical differences using GHOST
 
SOLUBLE PATTERN RECOGNITION RECEPTORS.pptx
SOLUBLE PATTERN RECOGNITION RECEPTORS.pptxSOLUBLE PATTERN RECOGNITION RECEPTORS.pptx
SOLUBLE PATTERN RECOGNITION RECEPTORS.pptx
 

Introduction to SQL

  • 1. Sol Genomics Network Databases and SQL syntax workshop UPLB January 2016 Noe Fernandez-Pozo
  • 2. Sol Genomics Network • Relational and not relational databases • PostgreSQL and SQL syntax • Table relationships and constraints Class Content
  • 3. Sol Genomics Network Relational Databases Databases structured to recognize relations among stored items of information.
  • 5. Sol Genomics Network SGN Database An ontology-based modular schema for representing genome-associated biological information genes, genomes, sequences, maps, markers, users, expression data, phenotipic data, breeding data, blast management … https://solgenomics.net +
  • 6. Sol Genomics Network Non Relational Databases Non-relational databases, also called NoSQL databases. • GBS • Breeding data • Phenotypic data • Variation data
  • 7. Sol Genomics Network Indexed Files • BLAST databases • Bowtie indexes • JBrowse
  • 8. Sol Genomics Network SQL Language http://www.postgresql.org The world’s most advanced open source database http://www.postgresql.org/docs/9.4/static/sql-commands.html
  • 9. Sol Genomics Network Connect to a database for the first time sudo -u postgres psql postgres install postgreSQL sudo aptitude install postgresql connect for the first time password user change user password du list roles postgreSQL Terminal UNIX Terminal
  • 10. Sol Genomics Network Connect to a PostgreSQL Database psql --help psql help man psql psql manual
  • 11. Sol Genomics Network Connect to a PostgreSQL database psql -h host —U user Connect to the database psql -h localhost —U bioinfo -d pineapple_backup Connect to the database using bioinfo user psql -h localhost —U postgres Connect to the database using postgres user
  • 12. Sol Genomics Network Create and alter a role du list roles CREATE ROLE bioinfo WITH LOGIN ENCRYPTED PASSWORD 'bioinfo' CREATEDB; create role with permission to create databases DROP ROLE bioinfo; delete role bioinfo ALTER ROLE bioinfo CREATEROLE CREATEDB REPLICATION SUPERUSER; grant all permissions to bioinfo user http://www.postgresql.org/docs/9.4/static/sql-alterrole.html
  • 13. Sol Genomics Network SQL syntax • Create, edit and delete databases and schemas • Import and export databases • Create, edit and delete tables • Import tables from a file • Transactions: begin, rollback and commit • Insert data and update data in databases • Explore databases, schemas and tables • Select and conditions: limit, offset, distinct, where, etc. • Basic table joining
  • 15. Sol Genomics Network Basic Commands ? show help h SQL syntax help h create database SQL syntax help l List databases c mydb Connect to a database q quit psql http://www.postgresql.org/docs/9.4/static/sql-commands.html
  • 16. Sol Genomics Network Basic Commands dn list schemas from the database dt list all tables from public schema dt sgn.* list all tables from sgn schema d blast_db list all tables from sgn schema o file.txt send output to file
  • 18. Sol Genomics Network Create Database CREATE DATABASE db_name; create a database CREATE DATABASE db_name WITH OWNER user1 ENCODING ‘UTF8’; create a database and define owner and encoding l list all databases CREATE DATABASE pineapple_db; create a database called pineapple_db
  • 19. Sol Genomics Network Grant Permissions GRANT ALL PRIVILEGES ON DATABASE db_name TO user1; grant permissions to an user on a database SELECT ("read") UPDATE ("write") INSERT ("append") DELETE TRUNCATE REFERENCES CREATE CONNECT TEMPORARY ALL PRIVILEGES
  • 20. Sol Genomics Network Grant Permissions rolename=xxxx -- privileges granted to a role =xxxx -- privileges granted to PUBLIC r -- SELECT ("read") w -- UPDATE ("write") a -- INSERT ("append") d -- DELETE D -- TRUNCATE x -- REFERENCES t -- TRIGGER X -- EXECUTE U -- USAGE C -- CREATE c -- CONNECT T -- TEMPORARY arwdDxt -- ALL PRIVILEGES (for tables, varies for other objects) * -- grant option for preceding privilege /yyyy -- role that granted this privilege dp mytable Access privileges Schema | Name | Type | Access privileges | Column access privileges --------+---------+-------+-----------------------+-------------------------- public | mytable | table | bioinfo=arwdDxt/bioinfo | col1: : =r/bioinfo : bioinfo_rw=rw/bioinfo : admin=arw/bioinfo
  • 21. Sol Genomics Network ALTER DATABASE db_name RENAME TO new_db_name; rename database db_name to new_db_name Edit a Database ALTER DATABASE db_name OWNER TO new_owner; change database owner
  • 22. Sol Genomics Network How To Delete a Database DROP DATABASE db_name; delete a database DROP DATABASE pineapple_db; delete a database called pineapple_db
  • 23. Sol Genomics Network Dump a database pg_dump -U user -h host -W db_name > db_file back up a database pg_dump -U postgres -h localhost pineapple_db > pineapple_dump.sql back up a database called pineapple_db ask for password
  • 24. Sol Genomics Network Import a Dumped Database cat pineapple_dump.sql | psql -U postgres -h localhost -d pineapple_db import a database CREATE DATABASE pineapple_db; create a database
  • 25. Sol Genomics Network Exercises I 1. Print in a file the table info (not the data) for all the tables in pineapple_backup 2. Create and delete a user with your name (no bioinfo) 3. Create a database called new_pineapple 4. Rename that database to pineapple_demo 5. Export the database pineapple_backup in a file called pineapple_backup.sql 6. Import the database pineapple_backup into pineapple_demo
  • 26. Sol Genomics Network type column title column file_base column primary key column Table Estructure blast_db_id | file_base | title | type -------------+------------------------------+----------------------------------------------+------------ 1 | unigene/Capsicum_combined | Capsicum annuum (pepper) Unigenes | nucleotide 2 | unigene/Ipomoea_batatas | Ipomoea batatas (sweet potato) Unigenes | nucleotide 3 | unigene/Nicotiana_sylvestris | Nicotiana sylvestris (wood tobacco) Unigenes | nucleotide 4 | unigene/Petunia_hybrida | Petunia hybrida Unigenes | nucleotide 5 | genbank/nt | NCBI NT comprehensive nucleotide database | nucleotide Columns
  • 27. Sol Genomics Network Table Estructure Row blast_db_id | file_base | title | type -------------+------------------------------+----------------------------------------------+------------ 1 | unigene/Capsicum_combined | Capsicum annuum (pepper) Unigenes | nucleotide 2 | unigene/Ipomoea_batatas | Ipomoea batatas (sweet potato) Unigenes | nucleotide 3 | unigene/Nicotiana_sylvestris | Nicotiana sylvestris (wood tobacco) Unigenes | nucleotide 4 | unigene/Petunia_hybrida | Petunia hybrida Unigenes | nucleotide 5 | genbank/nt | NCBI NT comprehensive nucleotide database | nucleotide
  • 28. Sol Genomics Network UNIQUE NOT NULL nucleotide or protein Constraints blast_db_id | file_base | title | type -------------+------------------------------+----------------------------------------------+------------ 31 | unigene/Capsicum_combined | Capsicum annuum (pepper) protein sequences | protein 71 | unigene/Ipomoea_batatas | Ipomoea batatas (sweet potato) Unigenes | nucleotide 70 | unigene/Nicotiana_sylvestris | Nicotiana sylvestris (wood tobacco) Unigenes | nucleotide 29 | unigene/Petunia_hybrida | Petunia hybrida Unigenes | nucleotide 15 | genbank/nt | NCBI NT comprehensive nucleotide database | nucleotide • NOT NULL Constraint: Ensures that a column cannot have NULL value. • UNIQUE Constraint: Ensures that all values in a column are different. • PRIMARY Key: Uniquely identifies each row/record in a database table. • FOREIGN Key: Constrains data based on columns in other tables. • CHECK Constraint: The CHECK constraint ensures that all values in a column satisfy certain conditions.
  • 29. Sol Genomics Network Database Schema Relationships and Normalization gene gene_id gene_name gene_description organism_name sequence sequence_length sequence_type primary_key gene_id | gene_name | gene_description | organism_name | sequence | sequence_length | sequence_type ---------+-----------+------------------+---------------+----------------+--------------—-—+-----------—-- 1 | Aco000001 | 60S ribosomal | Pineapple | ATGTCGTCGATTTA | 432 | nucleotide 2 | Aco000002 | 26S proteasome | Pineapple | ATGAATTGCGAGAC | 512 | nucleotide 3 | Aco000003 | microtubule | Pineapple | ATGGATGATGCGCA | 765 | nucleotide 4 | Aco000004 | DNA polymerase | Pineapple | MSSIIDKTKRTKKA | 180 | protein 5 | Aco000005 | Ubiquitin | Pineapple | MDDAPVPVAEPTLM | 214 | protein 6 | Aco000001 | 60S ribosomal | Pineapple | MSSIIDKTKRTKKA | 142 | protein 7 | Aco000002 | 26S proteasome | Pineapple | MDDAPVPVAEPTLM | 174 | protein
  • 30. Sol Genomics Network One To Many gene gene_id name description organism_id sequence sequence_id sequence type length gene_id organism organism_id scientific_name common_name 1 * 1 * has many has many foreign_key primary_key gene_id | name | description | organism_id ---------+-----------+----------------+------------- 1 | Aco000001 | 60S ribosomal | 1 2 | Aco000002 | 26S proteasome | 1 3 | Aco000003 | microtubule | 1 4 | Aco000004 | DNA polymerase | 1 5 | Aco000005 | Ubiquitin | 1 organism_id | scientific_name | common_name -------------+-----------------+------------- 1 | Ananas comosus | Pineapple sequence_id | sequence | length | type | gene_id -----------—+----------------+--------+-----------—+—---—---— 1 | ATGTCGTCGATTTA | 432 | nucleotide | 1 2 | ATGAATTGCGAGAC | 512 | nucleotide | 2 3 | ATGGATGATGCGCA | 765 | nucleotide | 3 4 | MSSIIDKTKRTKKA | 180 | protein | 1 5 | MDDAPVPVAEPTLM | 214 | protein | 2
  • 31. Sol Genomics Network One To Many gene_id | name | description | organism_id ---------+-----------+----------------+------------- 1 | Aco000001 | 60S ribosomal | 1 2 | Aco000002 | 26S proteasome | 1 3 | Aco000003 | microtubule | 1 4 | Aco000004 | DNA polymerase | 1 5 | Aco000005 | Ubiquitin | 1 organism_id | scientific_name | common_name -------------+-----------------+------------- 1 | Ananas comosus | Pineapple gene_id | gene_name | gene_description | organism_name | sequence | sequence_length | sequence_type ---------+-----------+------------------+---------------+----------------+--------------—-—+-----------—-- 1 | Aco000001 | 60S ribosomal | Pineapple | ATGTCGTCGATTTA | 432 | nucleotide 2 | Aco000002 | 26S proteasome | Pineapple | ATGAATTGCGAGAC | 512 | nucleotide 3 | Aco000003 | microtubule | Pineapple | ATGGATGATGCGCA | 765 | nucleotide 4 | Aco000004 | DNA polymerase | Pineapple | MSSIIDKTKRTKKA | 180 | protein 5 | Aco000005 | Ubiquitin | Pineapple | MDDAPVPVAEPTLM | 214 | protein sequence_id | sequence | length | type | gene_id -----------—+----------------+--------+-----------—+—---—---— 1 | ATGTCGTCGATTTA | 432 | nucleotide | 1 2 | ATGAATTGCGAGAC | 512 | nucleotide | 2 3 | ATGGATGATGCGCA | 765 | nucleotide | 3 4 | MSSIIDKTKRTKKA | 180 | protein | 1 5 | MDDAPVPVAEPTLM | 214 | protein | 2
  • 32. Sol Genomics Network Many To Many blast_db blast_db_id name description path group group_order BLAST databases classified in categories
  • 33. Sol Genomics Network Many To Many Relationship blast_db_blast_db_group blast_db_blast_db_group_id blast_db_id blast_db_group_id blast_db_group blast_db_group_id name ordinal blast_db blast_db_id name description path 1 * * 1 foreign_key primary_key primary_key primary_key
  • 34. Sol Genomics Network Create a Schema CREATE SCHEMA schema_name; create a schema CREATE SCHEMA IF NOT EXISTS schema_name AUTHORIZATION user_name; create a schema schema_name owned by user_name if it does not exist already
  • 35. Sol Genomics Network ALTER SCHEMA name RENAME TO new_name; rename schema name to new_name Edit a Schema ALTER SCHEMA name OWNER TO new_owner; change schema owner
  • 36. Sol Genomics Network How To Delete a Schema DROP SCHEMA schema_name CASCADE; delete a schema DROP SCHEMA blast RESTRICT; delete a schema called blast Refuse to drop the schema if it contains any objects. This is the default.
  • 37. Sol Genomics Network Create a New Table CREATE TABLE table_name (); create an empty table CREATE TABLE sgn.blast_db (); create an empty table blast_db in sgn schema
  • 38. Sol Genomics Network Create a Table CREATE TABLE gene ( gene_id bigserial PRIMARY KEY, name varchar(80) UNIQUE NOT NULL, description text, length integer, sequence text, organism_id bigserial REFERENCES organism (organism_id) ); large autoincrementing integer the value is a number row unique id link to another table row id this column cannot be empty gene gene_id name description length sequence organism_id
  • 39. Sol Genomics Network Create a Table CREATE TABLE gene ( gene_id bigserial PRIMARY KEY, name varchar(80) UNIQUE NOT NULL, description text, length integer, sequence text, organism_id bigserial REFERENCES organism (organism_id) ); value limited to 80 variable characters values cannot be repeated variable characters unlimited length gene gene_id name description length sequence organism_id
  • 41. Sol Genomics Network Edit Tables ALTER TABLE mytable ADD COLUMN mycolumn varchar(30); add a column of type varchar to a table ALTER TABLE gene DROP COLUMN sequence RESTRICT; drop a column from a table ALTER TABLE gene ALTER COLUMN name TYPE varchar(40); change column type ALTER TABLE gene RENAME COLUMN name TO gene_name; rename a column
  • 42. Sol Genomics Network Delete a Table Using Drop DROP TABLE table_name CASCADE; delete a table DROP TABLE gene RESTRICT; delete a table called gene Refuse to drop the table if any objects depend on it. This is the default.
  • 43. Sol Genomics Network Delete all rows from a table TRUNCATE table_name CASCADE; delete rows from a table TRUNCATE gene RESTART IDENTITY; empty the table gene and restart primary id index TRUNCATE gene, blast_db; empty all the rows from tables gene and blast_db
  • 44. Sol Genomics Network Delete a Table DELETE FROM table_name; empty a table DELETE FROM gene WHERE column=‘value’; delete the rows from table gene based on a condition
  • 45. Sol Genomics Network DropVs.TruncateVs Delete DROP TABLE removes tables from the database. Only the table owner, the schema owner, and superuser can drop a table. To empty a table of rows without destroying the table, use DELETE or TRUNCATE. To drop a table that is referenced a foreign-key constraint of another table, CASCADE must be specified. (CASCADE will only remove the foreign-key constraint, not the other table entirely.) DROP TABLE -- remove a table TRUNCATE -- empty a table or set of tables TRUNCATE quickly removes all rows from a set of tables. Very useful on large tables. DELETE -- delete rows of a table based on a condition DELETE deletes rows that satisfy the WHERE clause from the specified table. If the WHERE clause is absent, the effect is to delete all rows in the table. The result is a valid, but empty table.
  • 46. Sol Genomics Network Create New Tables From SQL File psql -U username -d myDataBase -W -a -f myInsertFile create tables from a file psql -U bioinfo -d pineapple_demo -h localhost -a -f gene_tables.sql create tables from gene_tables.sql file in pineapple_demo database ask for password print input from file
  • 47. Sol Genomics Network Exercises II 1. Create a database called ananas 2. Create a table called “Genes” with the columns: • name • description • sequence 3. Rename the table “Genes” to “gene” 4. Remove the column “sequence” 5. Add a column named organism_id 6. What are the “gene” table column types? (integer, text…) 7. Drop the table “gene”
  • 48. Sol Genomics Network Exercises II 8. Use truncate to delete all the sequences from pineapple_demo (created in Exercises I) 9. Write in a file the code to create the next tables and load them into a database called ananas gene gene_id name description organism_id sequence sequence_id sequence length type gene_id organism organism_id scientific_name common_name 1 * 1 * has many has many
  • 49. Sol Genomics Network Database Schema gene gene_id name description organism_id sequence sequence_id sequence length type gene_id organism organism_id scientific_name common_name 1 * 1 * has many has many psql -U bioinfo -d pineapple_demo -h localhost -a -f gene_tables.sql psql -U bioinfo -d pineapple_demo -h localhost -a -f blastdb_tables.sql
  • 50. Sol Genomics Network Insert Rows INSERT INTO mytable (col1,col2) VALUES (‘val1’,’val2’); insert values into a table INSERT INTO gene (name,description) VALUES (‘Solyc01g001’,’unknown’); insert gene name and description into gene table
  • 51. Sol Genomics Network Update Rows UPDATE mytable SET col1=‘val1’ WHERE col2=‘val2’; change column values from a row UPDATE gene SET name = ‘Solyc01g001’ WHERE gene_id=1; set gene name to Solyc01g001 for the row with gene_id 1 UPDATE mytable SET a=5, b=3, c=1 WHERE a>0; change several column values from a row
  • 52. Sol Genomics Network Delete Rows DELETE FROM mytable WHERE column=‘value’; delete the rows from table gene based on a condition DELETE FROM gene WHERE length<=‘100’; delete genes smaller than 100 nucleotides DELETE FROM gene WHERE name=‘Solyc01g001’; delete gene named Solyc01g001 gene gene_id name description length
  • 53. Sol Genomics Network Transactions BEGIN; INSERT INTO gene (name,description) VALUES (‘Solyc01g001’,’unknown’); COMMIT; commit a transaction BEGIN; UPDATE gene SET name=‘Solyc01g001’ WHERE gene_id=1; ROLLBACK; undo a transaction
  • 54. Sol Genomics Network Exercises III 1. Insert into the tables organism, gene and sequence the first two sequences from the file pineapple_5k_proteins.fasta from the folder ~/Desktop/Data 2. Create a database called pineapple_copy and import the data from pineapple_backup.sql file created in Exercises I 3. Use transactions to delete the sequences longer than 100 amino acids from pineapple_copy
  • 55. Sol Genomics Network Database Schema gene gene_id name description organism_id sequence sequence_id sequence length type gene_id organism organism_id scientific_name common_name 1 * 1 * scripts to upload data. Eg: load_pineapple_fasta.pl has many has many
  • 56. Sol Genomics Network SQL query commands
  • 57. Sol Genomics Network Querying a Table SELECT * FROM mytable; query all the data from the table SELECT name,description FROM gene; get the name and description from all the genes gene gene_id name description organism_id
  • 58. Sol Genomics Network Select - Where SELECT * FROM mytable WHERE col1=‘val1’; query all the rows from a table for a condition SELECT name,description FROM gene WHERE name=‘Aco000001’; get the name and description from gene Aco000001 gene gene_id name description organism_id
  • 59. Sol Genomics Network Limit and Offset SELECT * FROM mytable LIMIT 10; display the first 10 entries found SELECT name FROM gene OFFSET 10; display the last 10 gene names found in table gene
  • 60. Sol Genomics Network Select - Distinct SELECT DISTINCT col1 FROM mytable; get the different entries for col1 on mytable SELECT DISTINCT description FROM gene; get the different descriptions from the gene table gene gene_id name description organism_id
  • 61. Sol Genomics Network Count SELECT COUNT(*) FROM mytable; count rows from table SELECT COUNT(DISTINCT description) FROM gene; count the different descriptions from gene table SELECT COUNT(name) FROM gene; count the gene names gene gene_id name description organism_id
  • 62. Sol Genomics Network Sort Query Results SELECT * FROM mytable ORDER BY col1; get all the rows from mytable sorted by column 1 SELECT sequence_id,length FROM sequence ORDER BY length ASC; get all the sequence_id values sorted by sequence length in descendant order sequence sequence_id sequence length type gene_id SELECT sequence_id,length FROM sequence ORDER BY length DESC; ascendant order
  • 63. Sol Genomics Network In SELECT * FROM mytable WHERE col1 IN (‘val1’,’val2’); query all the rows for several values from a column SELECT * FROM gene WHERE gene_id IN (1,2); get the rows for the genes with id 1 and 2 gene gene_id name description organism_id
  • 64. Sol Genomics Network Comparison Operators In addition to the comparison operators, the special BETWEEN construct is available: WHERE col_name BETWEEN x AND y is equivalent to WHERE col_name >= x AND col_name <= y Notice that BETWEEN treats the endpoint values as included in the range. NOT BETWEEN does the opposite comparison: WHERE col_name NOT BETWEEN x AND y is equivalent to WHERE col_name < x OR col_name > y
  • 66. Sol Genomics Network Like SELECT * FROM mytable WHERE col1 LIKE ‘ribosomal’; return all the rows when col is equal to ribosomal SELECT * FROM gene WHERE description ILIKE ‘ribosomal%’; return all the rows with description starting with ribosomal SELECT * FROM gene WHERE description NOT LIKE ‘%ribosomal%’; return all the rows with description not containing ribosomal case insensitive search
  • 67. Sol Genomics Network Like and iLike LIKE case sensitive comparison iLIKE case insensitive comparison _ one character wildcard % wildcard LIKE ‘ribosomal’ LIKE ‘ribosomal%’ LIKE ‘%ribosomal’ LIKE ‘%ribosomal%’ LIKE ‘Ribosomal%’ LIKE ‘_ibosomal%’ iLIKE ‘%ribosomal%’ NOT LIKE ‘%ribosomal’ SELECT * FROM gene WHERE description LIKE ‘ribosomal’; See the results and count the output for
  • 68. Sol Genomics Network Join Tables SELECT * FROM table1 JOIN table2 USING(common_id); join two tables by a common id SELECT * FROM table1 JOIN table2 ON(id1=id2) where …; join two tables using two ids with equivalent values
  • 69. Sol Genomics Network Exercises IV 1. Find the 10 longest genes in pineapple_backup 2. Find the 10 shortest genes in pineapple_backup 3. How many different descriptions are in pineapple_backup 4. How many genes are in in pineapple_backup 5. What is the description for the gene Aco005884? 6. What is the description for the gene with id 4341? 7. What is the gene with the first description alphabetically? 8. And the last one?
  • 70. Sol Genomics Network Exercises IV 9. How many gene description start with A (uppercase A) 10. How many different descriptions start with A 11. What is the name, description and length of the longest gene starting with A? 12. What are the genes with length between 118 and 120? 13. And their descriptions? 14. What is the longest protein containing ribosomal in its description? (case insensitive) 15. What are the genes smaller than 50 or longer than 3000 amino acids?
  • 71. Sol Genomics Network Exercises IV 16. What are the descriptions for the genes Aco000443.1 and Aco000775.1? 17. Save in a file all the organism, gene and sequence information for the entries with gene ids 427 and 752