mysql - intro to database

19
MYSQL – INTRO TO DATABASE Prepared by Chester Chin

Upload: chester-chin

Post on 15-Apr-2017

135 views

Category:

Technology


0 download

TRANSCRIPT

Page 1: MySQL - Intro to Database

MYSQL – INTRO TO DATABASEPrepared by Chester Chin

Page 2: MySQL - Intro to Database

Structured Query Languageprogramming language for getting information from

and updating a database.

What does “SQL” Means?

Page 3: MySQL - Intro to Database

Relate SQL like a smart Excel or Access

•Speed, speed and more speed. • No programming language out there can outperform SQL when it comes

to bulk operations.

•Data integrity • SQL has many tools to help make sure the data stored conforms to rules

designed by the system architects.

•Availability & scalability • allows multiple users to work on the same dataset

Advantage of SQL

Page 4: MySQL - Intro to Database

In SQL Language:SELECT *

FROM Book WHERE price > 100.00

ORDER BY title;

A quick look at it

In Human Language:I want a list all of books in the order of alphabetical order according to title where the price is more than 100.

Page 5: MySQL - Intro to Database

CHECKLIST – Before We Start

• MYSQL 5.5 Command Line Client

• Type every command

• MYSQL Workbench CE

• Graphical User Interface(GUI)

• Make sure you have this two installed

Page 6: MySQL - Intro to Database

KEYWORDS

Database Tables Rows & Columns

Excel File Excel Sheets Rows & Columns

Page 7: MySQL - Intro to Database

LETSSTART LOAD MYSQL Command Line Client

Page 8: MySQL - Intro to Database

COMMONMISTAKES

;Missing Semicolon

‘ `Confusion over ‘ & `` (Located at top left corner)‘ (Located beside ENTER)

Page 9: MySQL - Intro to Database

SHOWDATABASES – CommandLine TYPE:mysql> show databases;

RESULT:

+--------------------+ | Database | +--------------------+ | information_schema | | mysql | +--------------------+ 2 rows in set (0.00 sec)

Page 10: MySQL - Intro to Database

USEDATABASES – CommandLine TYPE:mysql> use mysql;

RESULT:+---------------------------+ | Tables_in_mysql | +---------------------------+ | columns_priv | | db | | func | | help_category | | help_keyword | | help_relation | | help_topic | ……….AND MORE+---------------------------+ 17 rows in set (0.00 sec)

Page 11: MySQL - Intro to Database

CREATEDATABASE - testdbMysql> create DATABASE testdbMysql > show DATABASES;

Page 12: MySQL - Intro to Database

CREATINGTABLES

NOTE : When you create a ‘TABLE’, you need to create AT LEAST ONE column.

Mysql>CREATE TABLE `newtable` ( `firstcolumn` VARCHAR(20) NOT NULL, PRIMARY KEY (`firstcolumn`));

HUMAN LANGUAGE:

Hey, Create a table call ‘newtable’ and create a column named ‘firstcolumn’ that can fit 20 character and must not be empty which is also a primary key.

Page 13: MySQL - Intro to Database

INSERTINGVALUES

Try type the same thing again. What happened?

INSERT INTO `newtable` (`firstcolumn`) VALUES ('1111');

HUMAN LANGUAGE:

Hey, please insert the value ‘1111’ into the ‘firstcolumn’ or the table ‘newtable’

Page 14: MySQL - Intro to Database

KEYTERMSPrimary Key : ONLY UNIQUE VALUE, NO REPEAT VALUE

VARCHAR : Variable-length character

VARCHAR(10) : Variable-length character, Max 10 character

INT : Integer only

….Many More, however for this level lets just fixed a few.

NOT NULL : Cannot store empty value

Page 15: MySQL - Intro to Database

EXERCISECREATE a database ‘exercisedb’CREATE a table ‘exercisetable’CREATE a varchar(20) column ‘firstcolumn’ and make it a primary key.INSERT any value into column ‘firstcolumn’ [10 times]

INSERT INTO `newtable` (`firstcolumn`) VALUES ('1111');

Mysql>CREATE TABLE `newtable` ( `firstcolumn` VARCHAR(20) NOT NULL, PRIMARY KEY (`firstcolumn`));

Cheat Sheet

Page 16: MySQL - Intro to Database

SELECTSTATEMENT

SELECT * FROM newtable;

* ALL Column available in this table

Page 17: MySQL - Intro to Database

COMMANDLINE - LIMITATIONIf the exercise challenge change to this question. What do you think?

INSERT any value into column ‘firstcolumn’ [300 times]

Page 18: MySQL - Intro to Database

MYSQLWORKBENCH – GRAPHICAL WAY

Page 19: MySQL - Intro to Database

That’s All, Thanks For Your Time. ^.^[email protected]

Drop me an email if you have inputs for me to improve.