MYSQL
BITM 2701 PROFESSOR MARINO
WHAT IS SQL?
 Developed by IBM is San Jose CA.
 Originally called (and still commonly referred to as Sequel)
 SQL stands for Structured Query Language
 MySQL is a relational database management system
WHY SQL OVER ACCESS?
 Access is client side, SQL is server side
 SQL can be used online, which offers more “power” – works with HTTP, HTML, PHP, etc.
 Access may freeze, SQL is more reliable
 Access requires payment for MS Office, SQL offers free options
WHY IS CONNECTING TO THE WEB RELEVANT?
 With SQL the Database is on a server
 Individuals can connect to the database via the server to query results they are seeking
 Individuals can also edit, add, delete, and retrieve data based on settings
THE PROCESS
 Client (browser) requests access to the Server (where the database is)
 The Server responds granting access to the database
PHPMYADMIN & MYSQL
 MySQL can be controlled through a simple command-line interface; however, we can use phpMyAdmin
as an interface to MySQL.
 phpMyAdmin is a very powerful tool; it provides many facilities for customizing a database management
system.
THREE MAIN DATA TYPES IN SQL
 In MySQL there are three main types :
 text
 number
 Date/Time.
TEXT FIELDS
CHAR(size) Holds a fixed length string (can contain letters, numbers, and special characters). The fixed size
is specified in parenthesis. Can store up to 255 characters
VARCHAR(size) Holds a variable length string (can contain letters, numbers, and special characters). The
maximum size is specified in parenthesis. Can store up to 255 characters. Note: If you put a
greater value than 255 it will be converted to a TEXT type
TINYTEXT Holds a string with a maximum length of 255 characters
TEXT Holds a string with a maximum length of 65,535 characters
MEDIUMTEXT Holds a string with a maximum length of 16,777,215 characters
LONGTEXT Holds a string with a maximum length of 4,294,967,295 characters
ENUM(x,y,z,etc.) Let you enter a list of possible values. You can list up to 65535 values in an ENUM list. If a value
is inserted that is not in the list, a blank value will be inserted.Note: The values are sorted in the
order you enter them.
You enter the possible values in this format: ENUM('X','Y','Z')
NUMBER FIELDS
TINYINT(size) -128 to 127 normal. 0 to 255 UNSIGNED*. The maximum number of digits may be specified in
parenthesis
SMALLINT(size) -32768 to 32767 normal. 0 to 65535 UNSIGNED*. The maximum number of digits may be
specified in parenthesis
MEDIUMINT(size) -8388608 to 8388607 normal. 0 to 16777215 UNSIGNED*. The maximum number of digits may
be specified in parenthesis
INT(size) -2147483648 to 2147483647 normal. 0 to 4294967295 UNSIGNED*. The maximum number of
digits may be specified in parenthesis
BIGINT(size) -9223372036854775808 to 9223372036854775807 normal. 0 to 18446744073709551615
UNSIGNED*. The maximum number of digits may be specified in parenthesis
FLOAT(size,d) A small number with a floating decimal point. The maximum number of digits may be specified in
the size parameter. The maximum number of digits to the right of the decimal point is specified in
the d parameter
DOUBLE(size,d) A large number with a floating decimal point. The maximum number of digits may be specified in
the size parameter. The maximum number of digits to the right of the decimal point is specified in
the d parameter
DECIMAL(size,d) A DOUBLE stored as a string , allowing for a fixed decimal point. The maximum number of
digits may be specified in the size parameter. The maximum number of digits to the right of the
decimal point is specified in the d parameter
DATE/TIME FIELDS
DATE() A date. Format: YYYY-MM-DDNote: The supported range is from '1000-01-01' to '9999-12-31'
DATETIME() *A date and time combination. Format: YYYY-MM-DD HH:MM:SSNote: The supported range is
from '1000-01-01 00:00:00' to '9999-12-31 23:59:59'
TIMESTAMP() *A timestamp. TIMESTAMP values are stored as the number of seconds since the Unix epoch
('1970-01-01 00:00:00' UTC). Format: YYYY-MM-DD HH:MM:SSNote: The supported range is from
'1970-01-01 00:00:01' UTC to '2038-01-09 03:14:07' UTC
TIME() A time. Format: HH:MM:SSNote: The supported range is from '-838:59:59' to '838:59:59'
YEAR() A year in two-digit or four-digit format.Note: Values allowed in four-digit format: 1901 to 2155.
Values allowed in two-digit format: 70 to 69, representing years from 1970 to 2069
PROS
 Able to handle large databases that can be
accessed over the Web.
 Flexible and secure password system to protect
your data - powerful security system
 Fast, reliable, easy to use, and affordable!
 Relational database management system
 Stability
 MySQL allows users to connect to a specific
database on the server and issue requests.
 Concurrent access
 This system can run on virtually on any platform
– UNIX and Windows
 MySQL also comes with a source code
 MySQL is used at the enterprise level because of
its security.
CONS
 MySQL has no built-in method for doing db size limits
 MySQL requires that you either:
 code the data integrity into your product or
 you right some scripts to go through the logs and check that integrity was maintained
WHAT CAN SQL DO?
 Create Queries
 Offers multi-line commands – separate by using a comma (,) and end by using a semi-colon (;)
 Create a Database
 Create a Table
 Showing Tables/Describing Tables/Deleting Tables
 Loading Data
 Selecting Data (Select – From – Where)
 Sorting Data
NULLS
 NULL means missing value or unknown value.
 To test for NULL, you cannot use the arithmetic comparison operators, such as =, < or <>.
 Rather, you must use the IS NULL and IS NOT NULL operators instead.
PATTERN MATCHING
 MySQL provides:
 standard SQL pattern matching; and
 regular expression pattern matching, like those used by Unix utilities such as vi, grep and sed.
 SQL Pattern matching:
 To perform pattern matching, use the LIKE or NOT LIKE comparison operators
 By default, patterns are case insensitive.
 Special Characters:
 _ Used to match any single character.
 % Used to match an arbitrary number of characters.
REGULAR EXPRESSION MATCHING
 The other type of pattern matching provided by MySQL uses extended regular expressions.
 When you test for a match for this type of pattern, use the REGEXP and NOT REGEXP operators (or RLIKE
and NOT RLIKE, which are synonyms).
REGULAR EXPRESSIONS
 Some characteristics of extended regular expressions are:
 . matches any single character.
 A character class [...] matches any character within the brackets. For example, [abc] matches a, b, or c. To name a
range of characters, use a dash. [a-z] matches any lowercase letter, whereas [0-9] matches any digit.
 * matches zero or more instances of the thing preceding it. For example, x* matches any number of x characters,
[0-9]* matches any number of digits, and .* matches any number of anything.
 To anchor a pattern so that it must match the beginning or end of the value being tested, use ^ at the beginning
or $ at the end of the pattern.
SQL KEYWORDS
 avg : Average
 min : Minimum
 max: Maximum
 sum : Total
 count : Count

 group by: group the output by
 having: applied after the groups are formed so
aggregate functions can be used
 Select, distinct
 Select, all
 +,-,*, and / operators
 And, Or, & Not
 Rename
 Ordering
 Union & Union All
 Except & Except, all
 Joins
 Modifying Data
DATA DEFINITION LANGUAGE
 A data definition language or data description language (DDL) is a syntax similar to a
computer programming language for defining data structures
 SQL – DML (Data Manipulation Language) allows the user/administrator to add, delete, modify and
query data that is already in database tables.
 SQL – DDL (Data Definition Language) allows the user/administrator to create, delete and change the
structure of the tables and their inter-connection.
 DDL doesn’t evolve querying and DML does a lot more that just querying. However SQL is the
combination of DML and DDL.

MSAvMySQL.pptx

  • 1.
  • 2.
    WHAT IS SQL? Developed by IBM is San Jose CA.  Originally called (and still commonly referred to as Sequel)  SQL stands for Structured Query Language  MySQL is a relational database management system
  • 3.
    WHY SQL OVERACCESS?  Access is client side, SQL is server side  SQL can be used online, which offers more “power” – works with HTTP, HTML, PHP, etc.  Access may freeze, SQL is more reliable  Access requires payment for MS Office, SQL offers free options
  • 4.
    WHY IS CONNECTINGTO THE WEB RELEVANT?  With SQL the Database is on a server  Individuals can connect to the database via the server to query results they are seeking  Individuals can also edit, add, delete, and retrieve data based on settings
  • 5.
    THE PROCESS  Client(browser) requests access to the Server (where the database is)  The Server responds granting access to the database
  • 6.
    PHPMYADMIN & MYSQL MySQL can be controlled through a simple command-line interface; however, we can use phpMyAdmin as an interface to MySQL.  phpMyAdmin is a very powerful tool; it provides many facilities for customizing a database management system.
  • 7.
    THREE MAIN DATATYPES IN SQL  In MySQL there are three main types :  text  number  Date/Time.
  • 8.
    TEXT FIELDS CHAR(size) Holdsa fixed length string (can contain letters, numbers, and special characters). The fixed size is specified in parenthesis. Can store up to 255 characters VARCHAR(size) Holds a variable length string (can contain letters, numbers, and special characters). The maximum size is specified in parenthesis. Can store up to 255 characters. Note: If you put a greater value than 255 it will be converted to a TEXT type TINYTEXT Holds a string with a maximum length of 255 characters TEXT Holds a string with a maximum length of 65,535 characters MEDIUMTEXT Holds a string with a maximum length of 16,777,215 characters LONGTEXT Holds a string with a maximum length of 4,294,967,295 characters ENUM(x,y,z,etc.) Let you enter a list of possible values. You can list up to 65535 values in an ENUM list. If a value is inserted that is not in the list, a blank value will be inserted.Note: The values are sorted in the order you enter them. You enter the possible values in this format: ENUM('X','Y','Z')
  • 9.
    NUMBER FIELDS TINYINT(size) -128to 127 normal. 0 to 255 UNSIGNED*. The maximum number of digits may be specified in parenthesis SMALLINT(size) -32768 to 32767 normal. 0 to 65535 UNSIGNED*. The maximum number of digits may be specified in parenthesis MEDIUMINT(size) -8388608 to 8388607 normal. 0 to 16777215 UNSIGNED*. The maximum number of digits may be specified in parenthesis INT(size) -2147483648 to 2147483647 normal. 0 to 4294967295 UNSIGNED*. The maximum number of digits may be specified in parenthesis BIGINT(size) -9223372036854775808 to 9223372036854775807 normal. 0 to 18446744073709551615 UNSIGNED*. The maximum number of digits may be specified in parenthesis FLOAT(size,d) A small number with a floating decimal point. The maximum number of digits may be specified in the size parameter. The maximum number of digits to the right of the decimal point is specified in the d parameter DOUBLE(size,d) A large number with a floating decimal point. The maximum number of digits may be specified in the size parameter. The maximum number of digits to the right of the decimal point is specified in the d parameter DECIMAL(size,d) A DOUBLE stored as a string , allowing for a fixed decimal point. The maximum number of digits may be specified in the size parameter. The maximum number of digits to the right of the decimal point is specified in the d parameter
  • 10.
    DATE/TIME FIELDS DATE() Adate. Format: YYYY-MM-DDNote: The supported range is from '1000-01-01' to '9999-12-31' DATETIME() *A date and time combination. Format: YYYY-MM-DD HH:MM:SSNote: The supported range is from '1000-01-01 00:00:00' to '9999-12-31 23:59:59' TIMESTAMP() *A timestamp. TIMESTAMP values are stored as the number of seconds since the Unix epoch ('1970-01-01 00:00:00' UTC). Format: YYYY-MM-DD HH:MM:SSNote: The supported range is from '1970-01-01 00:00:01' UTC to '2038-01-09 03:14:07' UTC TIME() A time. Format: HH:MM:SSNote: The supported range is from '-838:59:59' to '838:59:59' YEAR() A year in two-digit or four-digit format.Note: Values allowed in four-digit format: 1901 to 2155. Values allowed in two-digit format: 70 to 69, representing years from 1970 to 2069
  • 11.
    PROS  Able tohandle large databases that can be accessed over the Web.  Flexible and secure password system to protect your data - powerful security system  Fast, reliable, easy to use, and affordable!  Relational database management system  Stability  MySQL allows users to connect to a specific database on the server and issue requests.  Concurrent access  This system can run on virtually on any platform – UNIX and Windows  MySQL also comes with a source code  MySQL is used at the enterprise level because of its security.
  • 12.
    CONS  MySQL hasno built-in method for doing db size limits  MySQL requires that you either:  code the data integrity into your product or  you right some scripts to go through the logs and check that integrity was maintained
  • 13.
    WHAT CAN SQLDO?  Create Queries  Offers multi-line commands – separate by using a comma (,) and end by using a semi-colon (;)  Create a Database  Create a Table  Showing Tables/Describing Tables/Deleting Tables  Loading Data  Selecting Data (Select – From – Where)  Sorting Data
  • 14.
    NULLS  NULL meansmissing value or unknown value.  To test for NULL, you cannot use the arithmetic comparison operators, such as =, < or <>.  Rather, you must use the IS NULL and IS NOT NULL operators instead.
  • 15.
    PATTERN MATCHING  MySQLprovides:  standard SQL pattern matching; and  regular expression pattern matching, like those used by Unix utilities such as vi, grep and sed.  SQL Pattern matching:  To perform pattern matching, use the LIKE or NOT LIKE comparison operators  By default, patterns are case insensitive.  Special Characters:  _ Used to match any single character.  % Used to match an arbitrary number of characters.
  • 16.
    REGULAR EXPRESSION MATCHING The other type of pattern matching provided by MySQL uses extended regular expressions.  When you test for a match for this type of pattern, use the REGEXP and NOT REGEXP operators (or RLIKE and NOT RLIKE, which are synonyms).
  • 17.
    REGULAR EXPRESSIONS  Somecharacteristics of extended regular expressions are:  . matches any single character.  A character class [...] matches any character within the brackets. For example, [abc] matches a, b, or c. To name a range of characters, use a dash. [a-z] matches any lowercase letter, whereas [0-9] matches any digit.  * matches zero or more instances of the thing preceding it. For example, x* matches any number of x characters, [0-9]* matches any number of digits, and .* matches any number of anything.  To anchor a pattern so that it must match the beginning or end of the value being tested, use ^ at the beginning or $ at the end of the pattern.
  • 18.
    SQL KEYWORDS  avg: Average  min : Minimum  max: Maximum  sum : Total  count : Count   group by: group the output by  having: applied after the groups are formed so aggregate functions can be used  Select, distinct  Select, all  +,-,*, and / operators  And, Or, & Not  Rename  Ordering  Union & Union All  Except & Except, all  Joins  Modifying Data
  • 19.
    DATA DEFINITION LANGUAGE A data definition language or data description language (DDL) is a syntax similar to a computer programming language for defining data structures  SQL – DML (Data Manipulation Language) allows the user/administrator to add, delete, modify and query data that is already in database tables.  SQL – DDL (Data Definition Language) allows the user/administrator to create, delete and change the structure of the tables and their inter-connection.  DDL doesn’t evolve querying and DML does a lot more that just querying. However SQL is the combination of DML and DDL.