What Is MySQL
What Is MySQL
RDBMS is the basis for SQL and for all modern database systems like MS SQL
Server, IBM DB2, Oracle, MySQL, and Microsoft Access.
RDBMS Terminology
Column − One column (data element) contains data of one and the same
kind, for example the column postcode.
Row − A row (= tuple, entry or record) is a group of related data, for example
the data of one subscription.
Primary Key − A primary key is unique. A key value cannot occur twice in
one table. With a key, you can only find one row. AutoNumber guarantees
uniqueness but does not carry any useful information
Foreign Key − A foreign key is the linking pin between two tables. No
uniqueness constraint for foreign keys
What is MySQL?
MySQL is the most popular Open Source Relational SQL Database Management System
that is developed and supported by Oracle Corporation. MySQL is one of the best
RDBMS being used for developing various web-based software applications.
Why MySQL?
1. Allows users to access data in relational database management systems.
3. Allows users to define the data in database and manipulate that data.
4. Allows to embed within other languages using SQL modules, libraries &
pre-compilers.
MySQL Database
MySQL is a fast, easy-to-use RDBMS being used for many small and big businesses.
MySQL is developed, marketed and supported by MySQL AB, which is a Swedish
company. MySQL is becoming so popular because of many good reasons:-
MySQL is released under an open-source license. So you have nothing to
pay to use it.
MySQL is very friendly to PHP, the most appreciated language for web
development.
In MySQL there are three main data types: string, numeric, and date and time.
In MySQL, a string can hold anything from plain text to binary data such as images or
files. Strings can be compared and searched based on pattern matching
by using the LIKE operator, regular expression, and full-text search.
A string object that can have 0 or more values, chosen from a list
SET(val1, val2, val3, ...)
of possible values. You can list up to 64 values in a SET list
2- Numeric data types:
In MySQL, you can find all SQL standard numeric types including exact number data
type and approximate numeric data types including integer, fixed-point and floating-
point.
All the numeric data types may have an extra option: UNSIGNED or ZEROFILL. If you
add the UNSIGNED option, MySQL disallows negative values for the column. If you add
the ZEROFILL option, MySQL automatically also adds the UNSIGNED attribute to the
column.
MySQL provides types for date and time as well as the combination of date and time. In
addition, MySQL supports the timestamp data type for tracking the changes in a row of a
table. If you just want to store years without dates and months, you can use the YEAR
data type.
MySQL Commands:
For Example:
CREATE DATABASE movies;
IF NOT EXISTS
A single MySQL server could have multiple databases. If you are not the only one accessing
the same MySQL server or if you have to deal with multiple databases there is a probability of
attempting to create a new database with name of an existing database . IF NOT EXISTS let
you to instruct MySQL server to check the existence of a database with a similar name prior to
creating database.
When IF NOT EXISTS is used database is created only if given name does not conflict with an
existing database's name. Without the use of IF NOT EXISTS MySQL throws an error.
Syntax:
CREATE TABLE [IF NOT EXISTS]`TableName` (`fieldname`
dataType [optio nal parameters]) ENGINE = storage Engine;
HERE
"CREATE TABLE" is the one responsible for the creation of the table in the
database.
"[IF NOT EXISTS]" is optional and only create the table if no matching
table name is found.
"`fieldName`" is the name of the field and "data Type" defines the nature of the
data to be stored in the field.
"[optional parameters]" additional information about a field
such as
" AUTO_INCREMENT" , NOT NULL etc.
For Example:
CREATE TABLE IF NOT EXISTS `MyFlixDB`.`Members` (
`membership_number` INT AUTOINCREMENT ,
`full_names` VARCHAR(150) NOT NULL ,
`gender` VARCHAR(6) ,
`date_of_birth` DATE ,
`physical_address` VARCHAR(255) ,
`postal_address` VARCHAR(255) ,
`contact_number` VARCHAR(75) ,
`email` VARCHAR(255) ,
PRIMARY KEY (`membership_number`) );