Presentation is loading. Please wait.

Presentation is loading. Please wait.

CHAPTER 1: INTRODUCTION TO SQL

Similar presentations


Presentation on theme: "CHAPTER 1: INTRODUCTION TO SQL"— Presentation transcript:

1 CHAPTER 1: INTRODUCTION TO SQL
SQL is a relational database management system language or syntax that is use to create, manipulate, and query dataset or data. In MYSQL, there are three forms of SQL DDL :- Data Definition /Description Language DML :- Data Manipulation Language DCL :- Data Control Language

2 DATA DEFINITION/DESCRIPTION LANGUAGE
DDL is an SQL Syntax or language that is use to create view or describe a table or database. Example is command CREATE, SHOW, & DESCRIBE

3 DATA MANIPULATION LANGUAGE (DML)
As the name implies, this is an SQL Syntax that is used to store, view, retrieve, and manipulate or modify data. Example of store is INSERT command, view and retrieve is SELECT, and manipulate/modify are ALTER, ALIAS, DELETE, & DROP etc.

4 DATA CONTROL LANGUAGE (DCL)
This is an SQL Syntax that is use to restrict unauthorized users from gaining access to the database. Note however that this same language is use to permit authorized users to gaining access to a database. e.g. PERMISSION NO PERMISSION GRANT (Access to view) REVOKE (withdraw access)

5 INTRO TO MySQL MYSQL is an acronym and a personalized acronym meaning My Structured Query Language. This is a relational database management system that is usually deployed as a free software, and it is also an open source software. Aside MySQL, other popular relation database management system are; SQL Server, Oracle, MS-Access, MSQLite.

6 DEVELOPMENT ENVIRONMENT FOR MYSQL
Basically we have three development/platform environment for MYSQL; MYSQL Monitor e.g. Console GUI Alternatives e.g. MySQL CC Web-based administration e.g. PhPMyAdmin

7 MySQL Data Types Integer Character and String Binary and Text Decimal
Float and Double Enum and Set Date and Time

8 MySQL Engines 5 types MyISAM ISAM InnoDB Merge Heap

9 Cont’d MyISAM Table : This format is use for speed and reliability. It supports tables in excess of 4GB in size and it can also be used for the purpose of compressing files.

10 Cont’d ISAM :- This is the predecessor of MyISAM . It is primarily used for compatibility purpose.

11 Cont’d InnoDB:- This is the successor of MyISAM table type. It is the most sophisticated table in MySQL. It support transaction and foreign keys and also allows multi user access. In a nutshell, InnoDB helps in a fast query execution and also help in preventing data corruption.

12 Cont’d HEAP:- This table type is use for creating and designing temporary table though extremely fast. Table designed using this table type is only available when server is running and automatically erases when server shut down.

13 Cont’d MERGE:- As the name implies this table is use to merge a collection of MyISAM table together to give one singular table.

14 Back to DDL… DDL : A Language used to define/describe a table or database. Example is command CREATE, SHOW, DESCRIBE and USE.

15 CREATE: Used to create DATABASE and TABLE. For instance: E.g.
Back to DDL…CREATE CREATE: Used to create DATABASE and TABLE. For instance: E.g. mysql>>create database (db name); mysql>>create database mydb;

16 CREATE: Used to create DATABASE and TABLE. For instance: E.g.
Back to DDL…CREATE CREATE: Used to create DATABASE and TABLE. For instance: E.g. mysql>>create table (table name); mysql>>create table studtable;

17 Back to DDL…USE USE: Having created a database, it becomes necessary to set pointer to such database whenever it is to be used. To achieve this, the SQL syntax USE is employed. E.g. mysql>>USE database name; mysql>>USE mydb; This makes the specified database to be the most active. Upon this, tables can now be created unto it and stored table can also now be accessed.

18 Back to DDL…SHOW SHOW: Used to show/reveal/present the available DATABASES and TABLES in a system. For instance and assuming you have many databases in your system: E.g. mysql>>SHOW databases; Will presents you all the available databases created on your system.

19 Back to DDL…SHOW SHOW: Used to show/reveal/present the available DATABASES and TABLES in a system. For instance and assuming you have many tables in your system: E.g. mysql>>SHOW tables; Will presents you all the available tables created on your system under a particular databases.

20 Back to DDL…DESCRIBE DESCRIBE: As the name sounds, this is used to view the detail description of your table e.g. fields and their data types. E.g. mysql>>DESCRIBE (table name); mysql>>DESCRIBE studtable; Will presents you all the details of the specified tables in terms of its size, data created, data types etc.

21 ILLUSTRATING DDL & DATA TYPES
Creating Creating Tables: In creating tables in MySQL, we use the syntax: CREATE e.g. >create table (tablename)(, >Field1 Field-data type (size), >Field2 Field-data type (size), >Last-Field3 Field-data type (size) //NO COMMA >);

22 Example Personaldata File (for holding people’s data) To create this
>create table pfile(, >names varchar(15), >address varchar(25), >id_no char(11), >age int(2), >sex enum(‘M’, ‘F’) >);

23 DML Insert Inserting Values into created tables: To do this, we used the syntax: INSERT…INTO…VALUES to populate data unto a table/file. This we do after table creation. e.g. >insert into pfile(names, address, id_no, dob, sex) values(‘Ade’, ‘22, Oroke’, ‘AAUA031213’,45,’F’); This you can do repeatedly with your keystrokes (up, down, left & right arrows as the case may be, then you edit).

24 DML Cont’d Select Clause: This is used for viewing and retrieving of stored data/files. The various types are: Select-All-From clause (the most used) Select-Specific-From clause Select-All-From-Where clause Select-Specific-From-Where clause

25 Examples I To view data stored into pfile,
>//use Select-All-From clause e.g. >Select *………. The * means All Back to the code proper……. >Select * From pfile; //not case sensitive anyway //any output there…….ok, QED I suppose

26 Examples II – what if I want to be specific on the fields to view?
To view such data stored into pfile (e.g. name and address only) >//use Select-Specific-From clause e.g. >Select name………be careful about d spelling to avoid avoidable error(s) How can I…….??? Simply describe the table to view and ascertain their correct spelling. >describe pfile; //something should be on your screen now….

27 Ok, back to the code now…. >select names, address from pfile; QED ……right output? Yes! …..try out more (e.g. names, age, address) etc.

28 Another version of the filtration
My data no doubt consists of male and female. Assuming I have the intention of reaching out to male friends only, how would I? Of course, the direct answer could have been: filter names & their addresses from the pfile table. But the clause is: ‘only male friends’.

29 Solution to the ‘puzzle’
The English-like solution statement is: ‘I want a situation WHEREby I select only male friends’. So, I got a clue (……SELECT-FROM-WHERE clause), let me try out the codes: >select names, address from pfile where sex=‘male’; //any luck? Try out more on your own…..

30 Other versions of the WHERE clause
Aside the WHERE-Assignment Clause (e.g. Where age=…..), also more proficiently used is the WHERE-LOGICAL Clause. This includes: WHERE >, WHERE< etc.

31 RELATED PROBLEM I want to know friends that are aging. WHY? May be I just want to know their job status. They should be nearing retirement now & we should plan for that. Shouldn’t we? So, if yes, how do I? Very simple my friend: >select * from pfile where age>=60;

32 END OF TODAY’S LECTURE


Download ppt "CHAPTER 1: INTRODUCTION TO SQL"

Similar presentations


Ads by Google