Presentation is loading. Please wait.

Presentation is loading. Please wait.

ISD3 Lecture 4 - Databases, SQL and MySQL. dept deptno dname location emp empno ename not null job not null hiredate sal comm manager The EMP DEPT database.

Similar presentations


Presentation on theme: "ISD3 Lecture 4 - Databases, SQL and MySQL. dept deptno dname location emp empno ename not null job not null hiredate sal comm manager The EMP DEPT database."— Presentation transcript:

1 ISD3 Lecture 4 - Databases, SQL and MySQL

2 dept deptno dname location emp empno ename not null job not null hiredate sal comm manager The EMP DEPT database

3 A managerial view Which Database to use for my application? –Functional capabilities – what parts of the SQL standard are supported –Advanced functionality – Object-relational, OLAP, GIS.. –Limitations – on the number of tables, size of tables, and size of fields –Cost – initial and ongoing –Ecology – availability of tools, staff, training, –Performance - for different tasks –Security –Backup and recovery

4 SQL Standard conformance SQL1 – SQL-89 – Access default standard SQL2 – SQL-92 - join syntax - most common level to be supported – MYSQL but limited SQL3 – SQL-99 - object relational features – Oracle 9i, Postgres SQL4 – SQL-03 - more advances- Standard about to be released

5 Basic SQL Basic DDL CREATE TABLE, ALTER TABLE, DROP TABLE with basic column types – number, character, date Basic DML SELECT … calculated fields, FROM multiple tables, WHERE condition, basic functions, basic aggregation (GROUP, HAVING) INSERT INTO T VALUES(…) UPDATE T SET X=6 WHERE X=5, DELETE FROM T WHERE X=5 REPLACE

6 Join and Sub-select SELECT * FROM emp,dept WHERE dept.deptno=emp.deptno SELECT * FROM FROM emp INNER JOIN dept ON dept.deptno=emp.deptno SELECT * FROM emp INNER JOIN dept USING deptno SELECT * FROM emp NATURAL JOIN dept SELECT dname FROM dept WHERE deptno in (SELECT deptno FROM EMP WHERE job=’analyst’) SELECT DISTINCT dname FROM emp NATURAL JOIN dept WHERE job=’analyst’

7 Extended Data types Time and Date Currency Unicode character strings BLOBs for images, sound Points and lines for geometry (GIS)

8 Data integrity Primary key CONSTRAINT emp_pk PRIMARY KEY (empno) Not Null Ename NOT NULL Foreign Key CONSTRAINT emp-deptfk FOREIGN KEY (deptno) REFERENCES dept –NO ACTION, CASCADE, SET NULL, SET DEFAULT Field Validation CONSTRAINT emp_sal CHECK (sal <6000) CONSTRAINT emp_job CHECK (job IN (‘analyst,’salesman’, ‘manager’, ‘president’, ‘clerk’))

9 Views CREATE VIEW empvw1 as SELECT empno, ename, job, hiredate, dname, location FROM emp NATURAL JOIN dept WHERE job <> ‘PRESIDENT’ SELECT * FROM empvw1 WHERE job=’Clerk UPDATE empvw1 set job=’manager’ where empno = 7566 UPDATE empvw1 set dname=’Accounts’ where empno = 7566

10 Transactions ATOMIC and ISOLATED UPDATE EMP SET sal=sal*1.1 WHERE job <>’Clerk’ UPDATE EMP SET sal=800 WHERE empno=7866 SELECT sum(sal) from emp;

11 Recovery and Backup

12 Stored Procedures E.g listing an employee’s superiors. Where to do processing: –On the database server Stored procedures written in say PL/SQL Reduces traffic between the client and the server Binds you to a specific DBMS –In the application Repeating code in different scripts

13 Triggers Actions performed when database changes On update to emp, if new sal > old sal, update counts set no=no+1 where type=’salincrease’

14 Non-first normal tables CHILD TABLE –empchild(empno, childname) –SELECT childname –FROM emp NATURAL JOIN empchild WHERE empno = 7566 –SLOW Non-atomic field e.g. –Set type in MySQL –E.g service days of the week

15 MySQL GNU General Public License (GPL) Developed by David Axmark, Allan Larsson and Michael "Monty" Widenius Supported by MySQL AB – a Swedish company - both open and commercial licences MySQL limitations –No subselect (included in 4.1) –No Foreign key handling –No check –Transaction control only in one file type –No stored procedures –No user defined types –Only aggregate type is SET –Table replication for retrieval performance

16 User defined types Object – Relational database e.g. currency with currency code and value User defined data types – to treat the combined colums as a single unit Functions (stored procedures) to process the data type -


Download ppt "ISD3 Lecture 4 - Databases, SQL and MySQL. dept deptno dname location emp empno ename not null job not null hiredate sal comm manager The EMP DEPT database."

Similar presentations


Ads by Google