MySQL Servidor de Bases de Datos Software Libre Ambientes Windows & Unix.

Slides:



Advertisements
Similar presentations
SQL (I) Tema 3.
Advertisements

Exercise 2 Relational Calculus
Fundamentals of Database Systems Fourth Edition El Masri & Navathe
Disk Controller To disk subsystem Rotational Delay Seek time Disk Block Block Size Disk Characteristics Capacity Rotational Speed (RPM) Seek Time Interface.
SQL DESIGN AND IMPLEMENTATION CONTENT SOURCES: ELAMSARI AND NAVATHE, FUNDAMENTALS OF DATABASE MANAGEMENT SYSTEMSELAMSARI AND NAVATHE, FUNDAMENTALS OF.
Defined by Edgar Codd in 1970 Defined by Edgar Codd in 1970 Considered ingenious but impractical Considered ingenious but impractical Conceptually simple.
COMPANY schema EMPLOYEE
OUTLINE OF THE LECTURE PART I GOAL: Understand the Data Definition Statements in Fig 4.1 Step1: Columns of the Tables and Data types. Step2: Single column.
SQL Lecture 10 Inst: Haya Sammaneh. Example Instance of Students Relation  Cardinality = 3, degree = 5, all rows distinct.
Database technology Lecture 2: Relational databases and SQL
Data Definition Languages Atif Farid Mohammad UNCC.
Overview Begin 6:00 Quiz15 mins6:15 Review Table Terms25 mins6:40 Short Break10 mins6:50 SQL: Creating Tables60 mins7:50 Break10 mins8:00 Lab – Creating.
Copyright © 2007 Ramez Elmasri and Shamkant B. Navathe Slide 8- 1.
Exploring Microsoft Access 2003 Chapter 4 Proficiency: Relational Databases, External Data, Charts, Pivot, and the Switchboard.
CIT 381 Data Types - data types - create table statement - constraints.
SQL SQL (Structured Query Language) is used to define, query, and modify relational databases Every relational database system understands SQL SQL is standard:
- relation schema, relations - database schema, database state
Review Database Application Development Access Database Development ER-diagram Forms Reports Queries.
Oracle8 - The Complete Reference. Koch & Loney1 Chapter 14. Changing Data: Insert, Update, Delete Presented by Victor M. Matos.
SQL Winter 2006Ron McFadyen Outline: SQL DDL - creating schemas - modifying schemas DML - select-from-where clause - group by, having, order by.
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 Jan. 2012Yangjun Chen ACS Outline: SQL Chapter 8 – 3rd ed. (Chap. 8 – 4 th, 5 th ed.; Chap. 4, 5, 6 th ed.) DDL - creating schemas - modifying.
Relational Data Model Sept. 2014Yangjun Chen ACS Outline: Relational Data Model Relational Data Model -relation schema, relations -database schema,
관계 연산자 & SQL. Selection SELECT * FROM r WHERE A=B AND D>5.
SQL The relational DB Standard CS-450 Dr. Ali Obaidi.
DAT702.  Standard Query Language  Ability to access and manipulate databases ◦ Retrieve data ◦ Insert, delete, update records ◦ Create and set permissions.
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.
Copyright © 2007 Ramez Elmasri and Shamkant B. Navathe Slide 8- 1 CREATE/DROP/ALTER TABLE Data types : char, varchar, decimal, date CREATE TABLE DEPARTMENT.
Logical DB Design 5. 1 CSE2132 Database Systems Week 5 Lecture Logical Database Design.
FEN  Queries: SELECT  Data Manipulation: INSERT, UPDATE, DELETE SQL: Structured Query Language – Part 2.
Riyadh Philanthropic Society For Science Prince Sultan College For Woman Dept. of Computer & Information Sciences CS 340 Introduction to Database Systems.
Copyright © 2007 Ramez Elmasri and Shamkant B. Navathe Chapter 8 SQL-99: Schema Definition, Constraints, and Queries and Views.
Review: Application of Database Systems
Other SQL Query Examples
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.
SQL Chapters 4, 5 (ed. 7 Chaps. 6,7). SQL or SEQUEL (Structured English Query Language) Based on relational algebra First called ‘Square’ Developed in.
Relational Algebra - Chapter (7th ed )
Onsdag The concepts in a relation data model SQL DDL DML.
Retrieve the names of all employees in department 5 who work more than 10 hours per week on the ‘ProductX’ project. p10ssn ← (Π essn (σ hours > 10 (works-on.
How to build ER diagrams
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.
 Employee (fname, minit, lname, ssn, bdate, address, sex, salary, superssn, dno)  Department (dname, dnumber, mgrssn, mgrstartdate) 
CSCI DBMS Environment1 The Database System Environment Dr. Awad Khalil Computer Science Department AUC.
Riyadh Philanthropic Society For Science Prince Sultan College For Woman Dept. of Computer & Information Sciences CS 340 Introduction to Database Systems.
NOEA/IT - FEN: Databases/SQL1 SQL – part 1 SQL: DDL and DML.
DatabaseDatabase cs453 Lab5 1 Ins.Ebtesam AL-Etowi.
1 CS 430 Database Theory Winter 2005 Lecture 15: How to Convert an ER Model to Relations.
Prince Sultan University Dept. of Computer & Information Sciences CS 340 Introduction to Database Systems.
Relational Model E.F. Codd at IBM 1970 Chapter 3 (ed. 7 – Chap. 5)
Announcements Written Homework 1 due Nov 2 –See course web page –Exercises 5.12, 5.15, 6.17, 6.20, 6.22 (a,c,f only). Today –continue with SQL (chapter.
There are two types of MySQL instructions (Data Definition Language) DDL: Create database, create table, alter table,,,. (Data Manipulation Language) DML.
1Fundamentals of Database Systems 기본키에 밑줄을 그은 COMPANY 관계 데이타베이스 스키마 FNAMEMINITLNAMESSNBDATEADDRESSSEXSALARYSUPERSSNDNO EMPLOYEE DNAMEDNUMBERMGRSSNMGRSTARTDATE.
FEN Introduction to the database field:  SQL: Structured Query Language Seminar: Introduction to relational databases.
Constraints and Views Chap. 3-5 continued (7 th ed. 5-7)
The SQL Database Grammar
Chapter 4 Basic SQL.
Database Design The Relational Model Text Ch5
376a. Database Design Dept. of Computer Science Vassar College
376a. Database Design Dept. of Computer Science Vassar College
11/9/2018.
Outline: Relational Data Model
Joining Tables ضم الجداول وإستخراج مناظر views منها الهدف : 1- استخراج المعلومات من جدولين أو اكثر بالإستفادة من الرابط بينهما وبإستخدام SQL 2- شروط قواعد.
Company Requirements.
لغة قواعد البيانات STRUCTURED QUERY LANGUAGE SQL))
CS4222 Principles of Database System
SQL-99: Schema Definition, Constraints, and Queries and Views
ISC321 Database Systems I Chapter 4: SQL: Data definition, Constraints, and Basic Queries and Updates Fall 2015 Dr. Abdullah Almutairi.
OLTP Will be talking about On Line Transaction Processing OLTP for most of this course Operational databases As opposed to OLAP On Line Analytical Processing.
Presentation transcript:

MySQL Servidor de Bases de Datos Software Libre Ambientes Windows & Unix

Activación de "MySQL” C:\mysql\bin> mysql Listar las bases de datos mysql > show databases; mysql > show databases; | Tables in database01 | | table01 | | table02 | rows in set (0.00 sec) 2 rows in set (0.00 sec)

Crear una BD simple y desplegar su estructura Crear una nueva BD llamada database01 mysql> create database database01; Database "database01" created. Todo lo que hace esta instrucción es crear un nuevo subdirectorio en c:\mysql\data. Todo lo que hace esta instrucción es crear un nuevo subdirectorio en c:\mysql\data. Abrir la BD mysql> use database01 Database changed Database changed

Crear una tabla mysql> create table table01 ( field01 integer, field02 char(10)); Query OK, 0 rows affected (0.00 sec) Encerrar toda la lista de atributos entre paréntesis. Encerrar toda la lista de atributos entre paréntesis. Comas son usadas como separadores de atributos. Comas son usadas como separadores de atributos. Todas las instrucciones de SQL son terminadas por ; Todas las instrucciones de SQL son terminadas por ;

Listar las tablas mysql> show tables; | Tables in database01 | | table01 | | table02 |

Listar los campos en una tabla mysql> show columns from table01; mysql > desc table01; | Field | Type | Null | Key | Default | Extra | | field01 | int(11) | YES | | | | | field02 | char(10) | YES | | | |

Poner datos en una Tabla Insertar un registro mysql> insert into table01 (field01,field02) values (1,'first'); Query OK, 1 row affected (0.00 sec) Encerrar la lista de atributos entre paréntesis. Encerrar los valores a ser insertados entre paréntesis. Comas son usadas entre cada campo y cada variable. Un espacio es usado después de la coma entre campos.

Listar todos los registros en una tabla mysql> select * from table01; | field01 | field02 | | 1 | first |

Añadiendo Campos (columnas)... un campo a la vez mysql> alter table table01 add column field03 char(20); Query OK, 1 row affected (0.04 sec) Records: 1 Duplicates: 0 Warnings: 0...más de un campo a la vez mysql> alter table table01 add column field04 date, add column field05 time; Query OK, 1 row affected (0.04 sec) Records: 1 Duplicates: 0 Warnings: 0 "add column" tiene que ser aplicada por cada columna. Comas son usadas entre cada instrucción add column. Un espacio debe ser usado después de las comas.

Esquema COMPANY PROJECT pnamepnumberplocationdnum DEPT_LOCATION dnumberdlocation EMPLOYEE fnameminitlnamessnbdateaddresssexsalarysuperssndno DEPARTMENT dnamednumbermgrssnmgrstartdate DEPENDENT essndependent_namesexbdaterelationship WORKS_ON essnpnohours FK

CREATE TABLE EMPLOYEE (FNAMEVARCHAR(10), mint char(1), lname varchar(10), SSNCHAR(9) NOT NULL, SSNCHAR(9) NOT NULL, BDATEDATE, address varchar(30), sex char(1), salary float, BDATEDATE, address varchar(30), sex char(1), salary float, SUPERSSNCHAR(9), SUPERSSNCHAR(9), DNOINTEGER DEFAULT 1, DNOINTEGER DEFAULT 1, PRIMARY KEY(SSN), PRIMARY KEY(SSN), FOREIGN KEY(DNO) REFERENCES DEPARTMENT FOREIGN KEY(DNO) REFERENCES DEPARTMENT ON DELETE SET DEFAULT ON UPDATE CASCADE, ON DELETE SET DEFAULT ON UPDATE CASCADE, FOREIGN KEY(SUPERSSN) REFERENCES EMPLOYEE FOREIGN KEY(SUPERSSN) REFERENCES EMPLOYEE ON DELETE SET NULL ON UPDATE CASCADE); ON DELETE SET NULL ON UPDATE CASCADE); CREATE TABLE DEPARTMENT CREATE TABLE DEPARTMENT (DNAMEVARCHAR(10)NOT NULL, DNUMBERINTEGER NOT NULL, DNUMBERINTEGER NOT NULL, MGRSSNCHAR(9), MGRSSNCHAR(9), MGRSTARTDATECHAR(10), MGRSTARTDATECHAR(10), PRIMARY KEY(DNUMBER), PRIMARY KEY(DNUMBER), UNIQUE(DNAME), UNIQUE(DNAME), FOREIGN KEY(MGRSSN) REFERENCES EMPLOYEE FOREIGN KEY(MGRSSN) REFERENCES EMPLOYEE ON DELETE SET DEFAULT ON UPDATE CASCADE); ON DELETE SET DEFAULT ON UPDATE CASCADE);

CREATE TABLE project ( pname char(15) not null, pname char(15) not null, pnumber char(5) not null, pnumber char(5) not null, plocation char(10), plocation char(10), dnum integer default 1, dnum integer default 1, primary key(pnumber), primary key(pnumber), unique(pname), unique(pname), foreign key(dnum) references department foreign key(dnum) references department on delete set default on update cascade); on delete set default on update cascade); CREATE TABLE dept_locations ( CREATE TABLE dept_locations ( dnumber integer default 1 not null, dnumber integer default 1 not null, dlocation char(10) not null, dlocation char(10) not null, primary key(dnumber, dlocation), primary key(dnumber, dlocation), foreign key(dnumber) references department foreign key(dnumber) references department on delete set default on update cascade); on delete set default on update cascade);

CREATE TABLE works_on( essn char(9) not null, essn char(9) not null, pno char(5) not null, pno char(5) not null, hours float, hours float, primary key(essn, pno), primary key(essn, pno), foreign key(essn) references employee foreign key(essn) references employee on delete cascade on update cascade, on delete cascade on update cascade, foreign key(pno) references project foreign key(pno) references project on delete cascade on update cascade); on delete cascade on update cascade); CREATE TABLE dependent( essn char(9) not null, essn char(9) not null, dependent_name varchar(10) not null, dependent_name varchar(10) not null, sex char(1), sex char(1), bdate date, bdate date, relationship varchar(10), relationship varchar(10), primary key(essn, dependent_name), primary key(essn, dependent_name), foreign key(essn) references employee foreign key(essn) references employee on delete cascade on update cascade ); on delete cascade on update cascade );

INSERT INTO project VALUES ('ProductX', '1', 'Bellaire', 5) ; INSERT INTO project VALUES ('ProductY', '2', 'Sugarland', 5); INSERT INTO project VALUES ('ProductY', '2', 'Sugarland', 5); INSERT INTO project VALUES ('ProductZ', '3', 'Houston', 5); INSERT INTO project VALUES ('ProductZ', '3', 'Houston', 5); INSERT INTO project VALUES ('Computerization', '10', 'Stafford', 4); INSERT INTO project VALUES ('Computerization', '10', 'Stafford', 4); INSERT INTO project VALUES ('Reorganization', '20', 'Houston', 1); INSERT INTO project VALUES ('Reorganization', '20', 'Houston', 1); INSERT INTO project VALUES ('Newbenefits', '30', 'Stafford', 4); INSERT INTO project VALUES ('Newbenefits', '30', 'Stafford', 4); INSERT INTO dept_locations VALUES (1, 'Houston'); INSERT INTO dept_locations VALUES (1, 'Houston'); INSERT INTO dept_locations VALUES (4, 'Stafford'); INSERT INTO dept_locations VALUES (4, 'Stafford'); INSERT INTO dept_locations VALUES (5, 'Bellaire') ; INSERT INTO dept_locations VALUES (5, 'Bellaire') ; INSERT INTO dept_locations VALUES (5, 'Sugarland'); INSERT INTO dept_locations VALUES (5, 'Sugarland'); INSERT INTO dept_locations VALUES (5, 'Houston') ; INSERT INTO dept_locations VALUES (5, 'Houston') ;

INSERT INTO employee VALUES ('John', 'B', 'Smith', ' ', '09-Jan- 1955', 'Houston,TX', 'M', 30000, ' ', 5); INSERT INTO employee VALUES ('Frank', 'T', 'Wong', ' ', '08-DEC- 1945', 'Houston,TX', 'M', 40000, ' ', 5) ; INSERT INTO employee VALUES ('Frank', 'T', 'Wong', ' ', '08-DEC- 1945', 'Houston,TX', 'M', 40000, ' ', 5) ; INSERT INTO employee VALUES ('Alicia', 'J', 'Zelaya', ' ', '19-JUL- 1958', 'Spring,TX', 'F', 25000, ' ', 4) ; INSERT INTO employee VALUES ('Alicia', 'J', 'Zelaya', ' ', '19-JUL- 1958', 'Spring,TX', 'F', 25000, ' ', 4) ; INSERT INTO employee VALUES ('Jennifer', 'S', 'Wallace', ' ', '20- JUN-1931', 'Bellaire,TX', 'F', 43000, ' ', 4) ; INSERT INTO employee VALUES ('Jennifer', 'S', 'Wallace', ' ', '20- JUN-1931', 'Bellaire,TX', 'F', 43000, ' ', 4) ; INSERT INTO employee VALUES ('Ramesh', 'K', 'Narayan', ' ', '15- SEP-1952', 'Humble,TX', 'M', 38000, ' ', 5); INSERT INTO employee VALUES ('Joyce', 'A', 'English', ' ', '31-JUL- 1962', 'Houston, TX', 'F', 25000, ' ', 5); INSERT INTO employee VALUES ('Joyce', 'A', 'English', ' ', '31-JUL- 1962', 'Houston, TX', 'F', 25000, ' ', 5); INSERT INTO employee VALUES ('Ahmad', 'V', 'Jabbar', ' ', '29- MAR-1959', 'Houston,TX', 'M', 25000, ' ', 4) ; INSERT INTO employee VALUES ('Ahmad', 'V', 'Jabbar', ' ', '29- MAR-1959', 'Houston,TX', 'M', 25000, ' ', 4) ; INSERT INTO employee VALUES ('James', 'E', 'Borg', ' ', '10-NOV- 1927', 'Houston,TX', 'M', 55000, null, 1); INSERT INTO employee VALUES ('James', 'E', 'Borg', ' ', '10-NOV- 1927', 'Houston,TX', 'M', 55000, null, 1); INSERT INTO department VALUES ('Research', 5, ' ', '22-MAY- 1978'); INSERT INTO department VALUES ('Research', 5, ' ', '22-MAY- 1978'); INSERT INTO department VALUES ('Administration', 4, ' ', '01-JAN- 1985'); INSERT INTO department VALUES ('Administration', 4, ' ', '01-JAN- 1985'); INSERT INTO department VALUES ('Headquarters', 1, ' ', '19-JUN- 1971') ; INSERT INTO department VALUES ('Headquarters', 1, ' ', '19-JUN- 1971') ;

INSERT INTO dependent VALUES (' ','Alice','F','05-APR-76','Daughter') ; INSERT INTO dependent VALUES (' ','Theodore','M','25-OCT-73','Son') ; INSERT INTO dependent VALUES (' ','Theodore','M','25-OCT-73','Son') ; INSERT INTO dependent VALUES (' ','Joy','F','03-MAY-48','Spouse') ; INSERT INTO dependent VALUES (' ','Joy','F','03-MAY-48','Spouse') ; INSERT INTO dependent VALUES (' ','Abner','M','29-FEB-32','Spouse') ; INSERT INTO dependent VALUES (' ','Abner','M','29-FEB-32','Spouse') ; INSERT INTO dependent VALUES (' ','Michael','M','01-JAN-78','Son') ; INSERT INTO dependent VALUES (' ','Michael','M','01-JAN-78','Son') ; INSERT INTO dependent VALUES (' ','Alice','F', '31-DEC-78','Daughter'); INSERT INTO dependent VALUES (' ','Elizabeth','F','05-MAY- 57','Spouse') ; INSERT INTO dependent VALUES (' ','Elizabeth','F','05-MAY- 57','Spouse') ; INSERT INTO works_on VALUES (' ', '1', 32.5) ; INSERT INTO works_on VALUES (' ', '1', 32.5) ; INSERT INTO works_on VALUES (' ', '2', 7.5) ; INSERT INTO works_on VALUES (' ', '2', 7.5) ; INSERT INTO works_on VALUES (' ', '3', 40.0) ; INSERT INTO works_on VALUES (' ', '3', 40.0) ; INSERT INTO works_on VALUES (' ', '1', 20.0) ; INSERT INTO works_on VALUES (' ', '1', 20.0) ; INSERT INTO works_on VALUES (' ', '2', 20.0) ; INSERT INTO works_on VALUES (' ', '2', 20.0) ; INSERT INTO works_on VALUES (' ', '2', 10.0) ; INSERT INTO works_on VALUES (' ', '2', 10.0) ; INSERT INTO works_on VALUES (' ', '3', 10.0) ; INSERT INTO works_on VALUES (' ', '3', 10.0) ; INSERT INTO works_on VALUES (' ', '10', 10.0) ; INSERT INTO works_on VALUES (' ', '10', 10.0) ; INSERT INTO works_on VALUES (' ', '30', 30.0) ; INSERT INTO works_on VALUES (' ', '10', 10.0) ; INSERT INTO works_on VALUES (' ', '10', 10.0) ; INSERT INTO works_on VALUES (' ', '10', 35.0) ; INSERT INTO works_on VALUES (' ', '10', 35.0) ; INSERT INTO works_on VALUES (' ', '30', 5.0) ; INSERT INTO works_on VALUES (' ', '30', 5.0) ; INSERT INTO works_on VALUES (' ', '30', 20.0) ; INSERT INTO works_on VALUES (' ', '20', 15.0) ; INSERT INTO works_on VALUES (' ', '20', 15.0) ; INSERT INTO works_on VALUES (' ', '20', null) ; INSERT INTO works_on VALUES (' ', '20', null) ;