WIBR Bioinformatics, © Whitehead Institute, 2004 Relational Databases for Biologists Robert Latek, Ph.D. Sr. Bioinformatics Scientist Whitehead Institute.

Slides:



Advertisements
Similar presentations
MySQL Access Privilege System
Advertisements

Creating Tables. 2 home back first prev next last What Will I Learn? List and provide an example of each of the number, character, and date data types.
Day 3 - Basics of MySQL What is MySQL What is MySQL How to make basic tables How to make basic tables Simple MySQL commands. Simple MySQL commands.
Let’s try Oracle. Accessing Oracle The Oracle system, like the SQL Server system, is client / server. For SQL Server, –the client is the Query Analyser.
Introduction to Structured Query Language (SQL)
System Administration Accounts privileges, users and roles
Introduction to Structured Query Language (SQL)
A Guide to MySQL 3. 2 Objectives Start MySQL and learn how to use the MySQL Reference Manual Create a database Change (activate) a database Create tables.
Structured Query Language SQL: An Introduction. SQL (Pronounced S.Q.L) The standard user and application program interface to a relational database is.
DAT702.  Standard Query Language  Ability to access and manipulate databases ◦ Retrieve data ◦ Insert, delete, update records ◦ Create and set permissions.
Introduction To Databases IDIA 618 Fall 2014 Bridget M. Blodgett.
MySQL Dr. Hsiang-Fu Yu National Taipei University of Education
A Guide to SQL, Eighth Edition Chapter Three Creating Tables.
Session 5: Working with MySQL iNET Academy Open Source Web Development.
ASP.NET Programming with C# and SQL Server First Edition
Analysis of SQL injection prevention using a proxy server By: David Rowe Supervisor: Barry Irwin.
PHP Programming with MySQL Slide 8-1 CHAPTER 8 Working with Databases and MySQL.
 SQL stands for Structured Query Language.  SQL lets you access and manipulate databases.  SQL is an ANSI (American National Standards Institute) standard.
Class #2: Introduction to MySQL (Continued) Where clause (continued) Aggregate Functions Creating users Backing up your database Indexes (if time) Importing.
WIBR Bioinformatics, © Whitehead Institute, 2004 Relational Databases for Biologists: Efficiently Managing and Manipulating Your Data Robert Latek, Ph.D.
Dbwebsites 2.1 Making Database backed Websites Session 2 The SQL… Where do we put the data?
Constraints  Constraints are used to enforce rules at table level.  Constraints prevent the deletion of a table if there is dependencies.  The following.
Chapter 7 Working with Databases and MySQL PHP Programming with MySQL 2 nd Edition.
Chapter 7 Working with Databases and MySQL PHP Programming with MySQL 2 nd Edition.
CHAPTER:14 Simple Queries in SQL Prepared By Prepared By : VINAY ALEXANDER ( विनय अलेक्सजेंड़र ) PGT(CS),KV JHAGRAKHAND.
Chapter 7 SQL HUANG XUEHUA. SQL SQL server2005 introduction Install components  management studio.
Introduction to MySQL Lab no. 10 Advance Database Management System.
NMED 3850 A Advanced Online Design January 12, 2010 V. Mahadevan.
1 Structured Query Language (SQL). 2 Contents SQL – I SQL – II SQL – III SQL – IV.
7 1 Chapter 7 Introduction to Structured Query Language (SQL) Database Systems: Design, Implementation, and Management, Seventh Edition, Rob and Coronel.
SQL Basics. 5/27/2016Chapter 32 of 19 Naming SQL commands are NOT case sensitive SQL commands are NOT case sensitive But user identifier names ARE case.
Chapter 5 MYSQL Database. Introduction to MYSQL MySQL is the world's most popular open-source database. Open source means that the source code, the programming.
Most information comes from Chapter 3, MySQL Tutorial: 1 MySQL: Part.
6 1 Lecture 8: Introduction to Structured Query Language (SQL) J. S. Chou, P.E., Ph.D.
Open Source Server Side Scripting ECA 236 Open Source Server Side Scripting MySQL – Inserting Data.
A Guide to MySQL 3. 2 Introduction  Structured Query Language (SQL): Popular and widely used language for retrieving and manipulating database data Developed.
Oracle & SQL Introduction. Database Concepts Revision DB? DBMS? DB Application? Application Programs? DBS? Examples of DBS? Examples of DBMS? 2Oracle.
SQL Basics. What is SQL? SQL stands for Structured Query Language. SQL lets you access and manipulate databases.
SQL Structured Query Language 1. Data Definition Language (DDL) is used to manage table and define data structure i.e. CREATE, ALTER, DROP Data Control.
What’s a database? Data stored in a structured format that lends itself to easy manipulation and recall.
Creating DDL and Database Event Triggers. 2 home back first prev next last What Will I Learn? Describe events that cause DDL and database event triggers.
WIBR Bioinformatics, © Whitehead Institute, 2004 Relational Databases for Biologists Robert Latek, Ph.D. Sr. Bioinformatics Scientist Whitehead Institute.
ITEC 3220A Using and Designing Database Systems Instructor: Prof. Z. Yang Course Website: 3220a.htm
SQL has several parts: Major ones: DDL – Data Definition Language {Defining, Deleting, Modifying relation schemas} DML – Data Manipulation Language {Inserting,
Task #1 Create a relational database on computers in computer classroom 308, using MySQL server and any client. Create the same database, using MS Access.
Chapter 8 Manipulating MySQL Databases with PHP PHP Programming with MySQL 2 nd Edition.
>> Introduction to MySQL. Introduction Structured Query Language (SQL) – Standard Database Language – Manage Data in a DBMS (Database Management System)
1 MySQL and SQL. 2 Topics  Introducing Relational Databases  Terminology  Managing Databases MySQL and SQL.
There are two types of MySQL instructions (Data Definition Language) DDL: Create database, create table, alter table,,,. (Data Manipulation Language) DML.
Relational Database Management System(RDBMS) Structured Query Language(SQL)
Distribution of Marks For Second Semester Internal Sessional Evaluation External Evaluation Assignment /Project QuizzesClass Attendance Mid-Term Test Total.
Starting with Oracle SQL Plus. Today in the lab… Connect to SQL Plus – your schema. Set up two tables. Find the tables in the catalog. Insert four rows.
Web Application Design. Data –What data is available? –How do we store it or how is it stored in the DB? Schema Data types Etc. –Where is the data?
LM 5 Introduction to SQL MISM 4135 Instructor: Dr. Lei Li.
Introduction to MySQL  Working with MySQL and MySQL Workbench.
Lec-7. The IN Operator The IN operator allows you to specify multiple values in a WHERE clause. SQL IN Syntax SELECT column_name(s) FROM table_name WHERE.
Marketing Analytics: Database Query with MySQL Disclaimer: All logos, photos, etc. used in this presentation are the property of their respective copyright.
3 A Guide to MySQL.
Controlling User Access
Insert, Update and the rest…
Prepared by : Moshira M. Ali CS490 Coordinator Arab Open University
Open Source Server Side Scripting Permissions & Users
Unix System Administration
Using SQL Server through Command Prompt
Structured Query Language (Data definition Language)
Chapter 7 Working with Databases and MySQL
Chapter 8 Working with Databases and MySQL
CS1222 Using Relational Databases and SQL
MySQL Dr. Hsiang-Fu Yu National Taipei University of Education
Copyright © 2013 – 2018 by Curt Hill
Presentation transcript:

WIBR Bioinformatics, © Whitehead Institute, 2004 Relational Databases for Biologists Robert Latek, Ph.D. Sr. Bioinformatics Scientist Whitehead Institute for Biomedical Research Session 3 Building And Modifying A Database With SQL

WIBR Bioinformatics, © Whitehead Institute, 2004 Session 3 Outline SQL Query Review Creating Databases Creating Tables Altering Table Structure Inserting Data Deleting Data Updating/Modifying Data Automating Repetitive Tasks

WIBR Bioinformatics, © Whitehead Institute, 2004 Connecting To MySQL If No Local MySQL, In Terminal Window –% ssh hebrides.wi.mit.edu -l username Connect to MySQL Database Server –% mysql -u username -p -D db4bio –mysql> SQL Commands Are Case-Insensitive Tables And Attributes Are Case- Sensitive

WIBR Bioinformatics, © Whitehead Institute, 2004 SELECT > SELECT * FROM Data LIMIT5; > SELECT DISTINCT species FROM LocusDescr; | affyId | exptId | level | | AFFX-MurIL2_at | hs-cer-1 | 20 | | AFFX-MurIL10_at | hs-cer-1 | 8 | | AFFX-MurIL4_at | hs-cer-1 | 77 | | AFFX-MurFAS_at | hs-cer-1 | 30 | | AFFX-BioB-5_at | hs-cer-1 | 258 | | species | | Hs | | Mm |

WIBR Bioinformatics, © Whitehead Institute, 2004 WHERE And ORDER BY > SELECT * FROM RefSeqs WHERE linkId BETWEEN 50 AND 100 LIMIT 5; > SELECT * FROM RefSeqs WHERE linkId BETWEEN 50 AND 100 ORDER BY ntRefSeq DESC LIMIT5; | linkId | ntRefSeq | aaRefSeq | | 50 | NM_ | NP_ | | 51 | NM_ | NP_ | | 52 | NM_ | NP_ | | 53 | NM_ | NP_ | | 54 | NM_ | NP_ | | linkId | ntRefSeq | aaRefSeq | | 70 | NM_ | NP_ | | 81 | NM_ | NP_ | | 91 | NM_ | NP_ | | 86 | NM_ | NP_ | | 52 | NM_ | NP_ |

WIBR Bioinformatics, © Whitehead Institute, 2004 GROUP BY And HAVING > SELECT * FROM Data GROUP BY affyId HAVING level < AVG(level) LIMIT 5; | affyId | exptId | level | | _at | mm-hrt-1 | 5 | | _at | mm-hrt-1 | 20 | | _at | mm-hrt-1 | 154 | | _at | mm-hrt-1 | 660 | | _at | mm-hrt-1 | 585 | | uId | | Hs | | Hs | | Hs | | Hs | | Hs | > SELECT uId FROM UniSeqs GROUP BY uId HAVING count(gbId)>1 LIMIT 5;

WIBR Bioinformatics, © Whitehead Institute, 2004 Table Joining > SELECT DISTINCT Unigenes.uId, GO_Descr.description AS GO_description FROM Unigenes, LocusLinks, Ontologies, GO_Descr WHERE Unigenes.linkId=LocusLinks.linkId AND LocusLinks.linkId=Ontologies.linkId AND Ontologies.goAcc=GO_Descr.goAcc LIMIT 5; | uId | GO_description | | Hs | calcium ion binding | | Hs | protein carrier | | Hs | arylamine N-acetyltransferase | | Hs.2 | arylamine N-acetyltransferase | | Hs | serine protease inhibitor |

WIBR Bioinformatics, © Whitehead Institute, 2004 CREATE DATABASE Allows You To Create A New Database On The Database Server > SHOW DATABASES; > CREATE DATABASE mfdb; > SHOW DATABASES; > USE mfdb; | Database | | anno | | cpa | | db4bio | | go | | goaway | | ideker | | mirna | | mysql | | sirna2 | | test | | wibrunix |

WIBR Bioinformatics, © Whitehead Institute, 2004 Access Privileges Restrict Access And Prevent Accidental Alteration Of Important Information Can Limit What Individual Users Can See And Do On Particular Databases And Specific Tables Access Privileges Are Stored In The mysql Database > GRANT ALL PRIVILEGES ON db4bio.* TO IDENTIFIED BY “password”; > GRANT SELECT,INSERT ON db4bio.Data TO IDENTIFIED BY “pass2”;

WIBR Bioinformatics, © Whitehead Institute, 2004 CREATE TABLE Translate An E-R Diagram (Schema) Into a Functioning Database Descriptions gbId description > CREATE TABLE Descriptions ( gbIdVARCHAR(20)NOT NULL, descriptionVARCHAR(100), PRIMARY KEY (gbId) ); | Field | Type | Null | Key | Default | Extra | | gbId | varchar(20) | | PRI | | | | description | varchar(100) | YES | | NULL | |

WIBR Bioinformatics, © Whitehead Institute, 2004 CREATE TABLE Targets affyId gbId species > CREATE TABLE Targets ( affyIdVARCHAR(20)NOT NULL, gbIdVARCHAR(20)NOT NULL, speciesVARCHAR(20), PRIMARY KEY (affyId, gbId) ); | Field | Type | Null | Key | Default | Extra | | affyId | varchar(20) | | PRI | | | | gbId | varchar(20) | | PRI | | | | species | varchar(20) | YES | | NULL | |

WIBR Bioinformatics, © Whitehead Institute, 2004 ALTER TABLE Modify A Table’s Attributes –Attribute Names, Type, Null, Key, Default –Add Or Drop Attributes > ALTER TABLE Data CHANGE level level DOUBLE; > ALTER TABLE Data RENAME level expression; > ALTER TABLE Data ADD PRIMARY KEY (exptId); > ALTER TABLE Data DROP COLUMN affyId; > ALTER TABLE Data ADD date TIMESTAMP; > DROP TABLE Data;

WIBR Bioinformatics, © Whitehead Institute, 2004 INSERT INTO Finally, Add Data Into Tables > INSERT INTO Data (level, exptId, affyId)EXPLICIT ORDER VALUES (215, “hs-hrt-1”, “100008_at”); > INSERT INTO DataIMPLIED ORDER VALUES (“100008_at”, “hs-hrt-1”, 215); > INSERT INTO Data2 (affyId2,level2)DATA COPYING SELECT Data.affyId, Data.level FROM Data WHERE Data.level < 250;

WIBR Bioinformatics, © Whitehead Institute, 2004 DELETE FROM Delete Data From Tables Similar Syntax As SELECT > DELETE FROM Data WHERE exptId=“hs-hrt-1”; > DELETE FROM SourcesBE CONSISTENT WHERE exptId= “hs-hrt-1”;

WIBR Bioinformatics, © Whitehead Institute, 2004 UPDATE Modify Data Already Stored In A Table Again, Similar Syntax As SELECT > UPDATE Data MODIFY SET exptId=“hs-hrt-2” WHERE exptId=“hs-hrt-1”; > UPDATE SourceFIX SET exptId= “ms-hrt-1”, source=“Mm” WHERE exptId=“hs-hrt-1”; > UPDATE Data INTERNAL SET level=level*2 NORMALIZATION WHERE exptId=“hs-hrt-1”;

WIBR Bioinformatics, © Whitehead Institute, 2004 Read Rows From A Text File Into A Table And Vice Versa LOAD DATA And Export > LOAD DATA LOCAL INFILE “data.txt” INTO TABLE db4bio.Data FIELDS TERMINATED BY ‘\t’ ENCLOSED BY ‘’ ESCAPED BY’\\’(ASSUMED) LINES TERMINATED BY ‘\n’;(ASSUMED) > LOAD DATA LOCAL INFILE “data.txt” INTO TABLE db4bio.Data FIELDS TERMINATED BY ‘,’; > SELECT * INTO OUTFILE “data.txt” FIELDS TERMINATED BY ‘,’ FROM Data;

WIBR Bioinformatics, © Whitehead Institute, 2004 Automating Repetitive Tasks Use.SQL Files To Perform SQL Commands Automatically Automatically Create A Series Of Tables % mysql -h hebrides.wi.mit.edu -u guest -p -D databasename < create.sql Feed A Complicated Query To The Database And Receive The Results In A Text File % mysql -h hebrides.wi.mit.edu -u web -p -D db4bio query1.out

WIBR Bioinformatics, © Whitehead Institute, 2004 Summary Difference Design Databases With E-R Diagrams Data Mine Using Combinations Of SELECT/FROM With WHERE, GROUP BY, HAVING, ORDER BY, And Aggregates Create And Implement Databases Input and Output Data From Databases Modify Existing Data Within Databases

WIBR Bioinformatics, © Whitehead Institute, 2004 Where To Go From Here? Consult SQL And MySQL Resources – –

WIBR Bioinformatics, © Whitehead Institute, 2004 Exercises Create Tables Input Data Modify/Delete Particular Data Accessing Your Database: –mysql -u guest -p -D YOURLASTNAME