MySQL. To start go to Login details: login: labuser password:macimd15 – There.

Slides:



Advertisements
Similar presentations
May 26, 2005MySQL Tutorial - 11 MySQL Tutorial 1 – How to Use MySQL CSCI 2140 TA: Jiye Li May 26, 2005
Advertisements

SQL Lecture 10 Inst: Haya Sammaneh. Example Instance of Students Relation  Cardinality = 3, degree = 5, all rows distinct.
Fall 2005 ICS184/EECS116 – Notes 08 1 ICS 184/EECS116: Introduction to Data Management Lecture Note 8 SQL: Structured Query Language -- DDL.
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.
MySQL-Database Teppo Räisänen Oulu University of Applied Sciences School of Business and Information Management.
CIT 381 Data Types - data types - create table statement - constraints.
Using Relational Databases and SQL Steven Emory Department of Computer Science California State University, Los Angeles Lecture 9: Data Definition Language.
CS 104 Introduction to Computer Science and Graphics Problems Introduction to Database (2) Basic SQL 12/05/2008 Yang Song.
Murali Mani SQL DDL and Oracle utilities. Murali Mani Datatypes in SQL INT (or) INTEGER FLOAT (or) REAL DECIMAL (n, m) CHAR (n) VARCHAR (n) DATE, TIME.
SQL Keys and Constraints Justin Maksim. Key Declaration Key constraint defined within the CREATE TABLE command Key can be declared using either the PRIMARY.
5 Chapter 5 Structured Query Language (SQL1) Revision.
Structured Query Language. Brief History Developed in early 1970 for relational data model: –Structured English Query Language (SEQUEL) –Implemented with.
Kirkwood Center for Continuing Education Introduction to PHP and MySQL By Fred McClurg, Copyright © 2010 All Rights Reserved. 1.
Your Oracle Account UserName is the same as your UWP username Followed Not case sensitive Initial Password: UWPstudent Password is case sensitive.
1 CSE 480: Database Systems Lecture 9: SQL-DDL Reference: Read Chapter of the textbook.
Oracle Data Definition Language (DDL)
Session 5: Working with MySQL iNET Academy Open Source Web Development.
Chapter 5 Introduction to SQL. Structured Query Language = the “programming language” for relational databases SQL is a nonprocedural language = the user.
ASP.NET Programming with C# and SQL Server First Edition
ZEIT2301 Design of Information Systems SQL: Creating a Database School of Engineering and Information Technology Dr Kathryn Merrick.
Structured Query Language. Brief History Developed in early 1970 for relational data model: –Structured English Query Language (SEQUEL) –Implemented with.
CS 3630 Database Design and Implementation. Your Oracle Account UserName is the same as your UWP username Followed Not case sensitive Initial.
CHAPTER:14 Simple Queries in SQL Prepared By Prepared By : VINAY ALEXANDER ( विनय अलेक्सजेंड़र ) PGT(CS),KV JHAGRAKHAND.
Chapter 8 Part 1 SQL-99 Schema Definition, Constraints, Queries, and Views.
Ms. Hatoon Al-Sagri CCIS – IS Department SQL-99 :Schema Definition, Constraints, Queries, and Views 1.
Chapter 7 SQL HUANG XUEHUA. SQL SQL server2005 introduction Install components  management studio.
Introduction to MySQL Lab no. 10 Advance Database Management System.
CSC 2720 Building Web Applications Database and SQL.
Oracle Data Definition Language (DDL) Dr. Bernard Chen Ph.D. University of Central Arkansas Fall 2008.
-Software School of Hunan University-
SQL Data Definition Language (DDL) Using Microsoft SQL Server 1SDL Data Definition Language (DDL)
SQL SQL Server : Overview SQL : Overview Types of SQL Database : Creation Tables : Creation & Manipulation Data : Creation & Manipulation Data : Retrieving.
Kirkwood Center for Continuing Education Introduction to PHP and MySQL By Fred McClurg, Copyright © 2015, Fred McClurg, All Rights.
SQL FUNDAMENTALS SQL ( Structured Query Language )
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.
SQL: DDL. SQL Statements DDL - data definition language –Defining and modifying data structures (metadata): database, tables, views, etc. DML - data manipulation.
Recap of SQL Lab no 8 Advance Database Management System.
Intro to SQL| MIS 2502  Spacing not relevant › BUT… no spaces in an attribute name or table name  Oracle commands keywords, table names, and attribute.
SQL Basics. What is SQL? SQL stands for Structured Query Language. SQL lets you access and manipulate databases.
MySQL More… 1. More on SQL In MySQL, the Information Schema is the “Catalog” in the SQL standard SQL has three components: Data definition Data manipulation.
CREATE TABLE CREATE TABLE statement is used for creating relations Each column is described with three parts: column name, data type, and optional constraints.
Prince Sultan University Dept. of Computer & Information Sciences CS 340 Introduction to Database Systems.
Sql DDL queries CS 260 Database Systems.
Week 8-9 SQL-1. SQL Components: DDL, DCL, & DML SQL is a very large and powerful language, but every type of SQL statement falls within one of three main.
©Silberschatz, Korth and Sudarshan1 Structured Query Language (SQL) Data Definition Language Domains Integrity Constraints.
>> Introduction to MySQL. Introduction Structured Query Language (SQL) – Standard Database Language – Manage Data in a DBMS (Database Management System)
Altering Tables and Constraints Database Systems Objectives Add and modify columns. Add, enable, disable, or remove constraints. Drop a table. Remove.
Relational Database Management System(RDBMS) Structured Query Language(SQL)
At the end of this lesson, you will be able to: Describe constraints Create and maintain constraints.
Constraints and Views Chap. 3-5 continued (7 th ed. 5-7)
LECTURE FOUR Introduction to SQL DDL with tables DML with tables.
 MySQL  DDL ◦ Create ◦ Alter  DML ◦ Insert ◦ Select ◦ Update ◦ Delete  DDL(again) ◦ Drop ◦ Truncate.
Chapter 5 Introduction to SQL.
Managing Tables, Data Integrity, Constraints by Adrienne Watt
MySQL-Database Jouni Juntunen Oulu University of Applied Sciences
SQL: Schema Definition and Constraints Chapter 6 week 6
Insert, Update and the rest…
ORACLE SQL Developer & SQLPLUS Statements
لغة قواعد البيانات STRUCTURED QUERY LANGUAGE SQL))
CS4222 Principles of Database System
CS122 Using Relational Databases and SQL
Oracle Data Definition Language (DDL)
SQL-1 Week 8-9.
Session - 6 Sequence - 1 SQL: The Structured Query Language:
Database Design: Relational Model
ISC321 Database Systems I Chapter 4: SQL: Data definition, Constraints, and Basic Queries and Updates Fall 2015 Dr. Abdullah Almutairi.
MySQL Database System Installation Overview SQL summary
CS122 Using Relational Databases and SQL
Session - 6 Sequence - 1 SQL: The Structured Query Language:
Presentation transcript:

MySQL

To start go to Login details: login: labuser password:macimd15 – There are 2 existing databases that can be used (test & labuser) & you may create a new database – You can import a pre-existing set of database tables (definition & data) – You can export a created database at the end of your user session (table definitions & data)

Main PhpMyAdmin Menu

PhpMyadmin Database Menu

Table creation Tables can be created using the create table form Tables can also be created using an SQL CREATE TABLE STATEMENT CREATE TABLE emp ( eno char(3), ename char(12), salary decimal(7,2), supno char(3), dno char(3) NOT NULL, PRIMARY KEY (eno), FOREIGN KEY (dno) REFERENCES dept (dno) ) ENGINE=InnoDB ; Basic table creation statement has keywords CREATE TABLE with the tablename (emp here), then In round brackets Pairs of values columnname datatype delimited by commas With semicolon as termination symbol

Table creation issues Columns (attributes) can be specified as NOT NULL (allows null values) except for the primary key Primary Key specified as – PRIMARY KEY (columnname) Foreign Key specified as – FOREIGN KEY (columnname) REFERENCES Tablename(PK column) Data Types – Text (char(size), varchar) – Integers (tinyint, smallint, mediumint, int, bigint) – Floating point numbers (Decimal(Length, Decimal Places), Float, Double) – Date/Time (Data, DateTime, Time)

SQL Queries Retrieval – Based on SELECT.....FROM....WHERE..... Clauses – e.g. SELECT ename, salary FROM EMP WHERE dno = 'd1'; Get the names and salary of employees in department ‘dno’ Insert record(s) – Can be done using the INSERT record form – Can be done using the INSERT INTO tablename VALUES ( ) – e.g. INSERT INTO EMP VALUES ('e35', 'woods', 25000, 'e5', 'd3'); Add a new record into EMP with eno 'e35', ename 'woods', salary 25000, supervisor number 'e5', department number 'd3'

SQL Queries (2) Update a record(s) – UPDATE tablename SET column = newvalue WHERE column compared with value – e.g. UPDATE EMP SET salary = WHERE eno = 'e35'; Change the salary of employee number 35 to £30,000

SQL Queries (3) Delete a record(s) – DELETE FROM tablename WHERE column compared with value – DELETE FROM EMP WHERE eno = 'e35'; Delete the employee record where employee number = 'e35'

SQL Query Interface

Query Result

Table Structure Screen

Insert Record Screen

Export Table screen

Import Table Screen

-- phpMyAdmin SQL Dump Table structure for table `EMP`-- CREATE TABLE IF NOT EXISTS `emp` ( `eno` char(3) NOT NULL, `ename` char(12) DEFAULT NULL, `salary` decimal(7,2) DEFAULT NULL, `supno` char(3) DEFAULT NULL, `dno` char(3) NOT NULL, PRIMARY KEY (`eno`), FOREIGN KEY (`dno`) REFERENCES `dept` (`dno`) ) ENGINE=InnoDB, DEFAULT CHARSET=latin1; Dumping data for table `EMP`-- INSERT INTO `EMP` (`eno`, `ename`, `salary`, `supno`, `dno`) VALUES ('e1', 'armstrong', ' ', '', 'd1'), ('e10', 'jones', ' ', 'e1', 'd3'), ('e11', 'kelly', ' ', 'e7', 'd2'), ('e12', 'mccoy', ' ', 'e3', 'd1'), ('e13', 'neeson', ' ', 'e19', 'd1'), ('e14', 'oliver', ' ', 'e17', 'd3'), ('e15', 'pearse', ' ', 'e21', 'd1'), ('e16', 'quinn', ' ', 'e2', 'd1'), ('e17', 'roberts', ' ', 'e4', 'd3'), ('e18', 'smyth', ' ', 'e21', 'd3'), ('e19', 'trainor', ' ', 'e7', 'd1'); Sample table definition and data exported to a.sql file

Alter Table commands Change table type (defauly MyISAM to innodb) ALTER TABLE emp ENGINE=innodb Add primary key ALTER TABLE emp ADD PRIMARY KEY (eno) Add foreign key ALTER TABLE emp ADD CONSTRAINT c1 FOREIGN KEY (dno) REFERENCES dept (dno)

Referential Integrity Requires the following – Table type as innodb (rather than default MyISAM) – Primary keys must be applied – Any data entered must be consistent (all FK values must match existing PK values) – Best applied before entering data Can be applied using – CREATE TABLE statement – ALTER TABLE statement – Relation View of phpMyAdmin table form

Referential Integrity Implications INSERT: Can’t add a foreign key (FK) value unless the corresponding primary key (PK) value already exists DELETE: Can’t delete a record with a PK matching some FK elsewhere unless all records containing that FK value are first deleted (cascading delete) UPDATE: Can’t change a PK value where corresponding FK values exist, or change a FK to any value where the corresponding PK value does not already exists