MYSQL – INTRO TO DATABASEPrepared by Chester Chin
Structured Query Languageprogramming language for getting information from
and updating a database.
What does “SQL” Means?
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
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.
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
KEYWORDS
Database Tables Rows & Columns
Excel File Excel Sheets Rows & Columns
LETSSTART LOAD MYSQL Command Line Client
COMMONMISTAKES
;Missing Semicolon
‘ `Confusion over ‘ & `` (Located at top left corner)‘ (Located beside ENTER)
SHOWDATABASES – CommandLine TYPE:mysql> show databases;
RESULT:
+--------------------+ | Database | +--------------------+ | information_schema | | mysql | +--------------------+ 2 rows in set (0.00 sec)
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)
CREATEDATABASE - testdbMysql> create DATABASE testdbMysql > show DATABASES;
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.
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’
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
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
SELECTSTATEMENT
SELECT * FROM newtable;
* ALL Column available in this table
COMMANDLINE - LIMITATIONIf the exercise challenge change to this question. What do you think?
INSERT any value into column ‘firstcolumn’ [300 times]
MYSQLWORKBENCH – GRAPHICAL WAY
That’s All, Thanks For Your Time. ^.^[email protected]
Drop me an email if you have inputs for me to improve.