Tải bản đầy đủ (.ppt) (38 trang)

slide môn học MySQL bài 2 using MySQL

Bạn đang xem bản rút gọn của tài liệu. Xem và tải ngay bản đầy đủ của tài liệu tại đây (502.48 KB, 38 trang )

Using MySQL
Session 2


Review - I










Binary distribution contains setup program that installs
every component for the server to start
Source distribution contains all the codes and support
files for making the files executable
MySQL is compatible with Solaris, Linux, Windows
9x/NT/2000/XP, Mac OS X, FressBSD, and AIX
operating systems
Configure script enables user to control the MySQL
distribution
To configure MySQL use various options of configure
on the command line
MySQL Database / Session 4 / Slide 2 of 38


Review - II







MySQL is configured using the combination of commandline options, configuration files, and environment
variables
Programs like mysql, mysqladmin, mysqld, mysqld_safe,
mysql.server, mysqldump, mysqlimport, mysqlshow,
mysqlcheck, myisamchk, and myisampack supports
option files of my.cnf file
To initiate MySQL at the startup, configure the operating
system to place MySQL server at the startup

MySQL Database / Session 4 / Slide 3 of 38


Objectives





List Naming Conventions used in MySQL
Create a Database and Tables
Use Data Types
Implement the concept of Referential
integrity and indexing

MySQL Database / Session 4 / Slide 4 of 38



Naming Conventions in MySQL






We can use the following for database and table names:
 Alphabets a-z or A-Z
 Digits (0-9)
 Characters such as ‘_ ‘ or ‘$’
We cannot use the following for the database and table name:
 Character ‘.’
 Separator characters such as ‘/’ or’\’

A name may start with a digit but it cannot contain of entire
digits
MySQL Database / Session 4 / Slide 5 of 38


Case Sensitivity in MySQL- I









The SQL statements and keywords are not case
sensitive
The case sensitivity of the database and table names
depends on the type of the operating system being
used
On a windows operating system the database name
and the table name are not case sensitive
On a UNIX operating system the database and table
names are case sensitive
MySQL Database / Session 4 / Slide 6 of 38


Case Sensitivity in MySQL - II




The column and the index name are not case
sensitive
We use one of the following SQL statements to
display the column ‘FNAME’ from a SAMPLE
table:
SELECT FNAME from SAMPLE ( );
SELECT fname from SAMPLE ( );

MySQL Database / Session 4 / Slide 7 of 38


Creating Database -I



Databases are used to store information. A database
consists of several tables.

 The syntax for creating a database is:
CREATE DATABASE [IF NOT EXISTS]
<dbname>

MySQL Database / Session 4 / Slide 8 of 38


Creating Database-II


To create a EMPLOYEE
database,enter the following
at the command prompt:
CREATE DATABASE
EMPLOYEE;

MySQL Database / Session 4 / Slide 9 of 38


Data Types Classification


Data types are classified into:
 Numeric
 String

 Date
 Complex

MySQL Database / Session 4 / Slide 10 of 38


Numeric Data Types - I



Numeric data types enables us to store numbers.
Types of Numeric data types:


BIGINT (length, decimal): Stores unsigned numbers
 Range: From 0 to 18,446,744,073,709,551,615 for
unsigned and from 9,223,372,036,854,775,808 to
9,223,372,036,854,775,807 for signed number
 Storage: 8

MySQL Database / Session 4 / Slide 11 of 38


Numeric Data Types - II


DOUBLE: Stores double precision floating point numbers
 Range: Between 1.7976931348623157E+308 and
-2.2250738585072014E-308,0 for a negative number
and between 2.2250738585072014E-308 and

1.7976931348623157E+308 for a positive number .
 Storage: 8



DECIMAL (length, decimal): Stores floating numbers
 Storage: Precision+2
 Synonyms: DEC, NUMERIC
MySQL Database / Session 4 / Slide 12 of 38


Numeric Data Types - III




INT: Stores integer numbers
 Range: Between 2,147,483,648 to 2,147,483,647for a signed
number and between 0 to 4,294,967,295 for a unsigned
number .
 Storage:4
 Synonyms: INTEGER
MEDIUMINT (length): Stores integer numbers
 Range: Between -8,388,608 to 8,388,607 for a signed number
and from 0 to 16,777,215 for a unsigned number
 Storage: 3
MySQL Database / Session 4 / Slide 13 of 38


Numeric Data Types - IV





SMALLINT (length): Stores integer numbers
 Range: From -32,768 to 32,767 for a signed number and
0 to 65,535 for an unsigned number
 Storage:2
TINYINT: Stores integer numbers
 Range: From -128 to 127 for a signed number and from
0 to 255 for an unsigned number
 Storage: 1

MySQL Database / Session 4 / Slide 14 of 38


String Data Types - I






A string is a sequence of characters. A string data type is
enclosed by a single quotes or double quotes.
Enables the user to enter:
 Alphabets from a-z, A-Z
 Numbers from 0-9
The length of a character string is the number of
characters in it


MySQL Database / Session 4 / Slide 15 of 38


String Data Types - II




CHAR (length): Stores maximum 255 characters
 Storage: Length
 Synonyms: CHARACTER, NCHAR, NATIONAL
CHAR, NATIONAL CHARACTER
MEDIUMTEXT: Stores medium-sized text whose size
up to 16MB
 Storage: Length+3

MySQL Database / Session 4 / Slide 16 of 38


String Data Types- III




LONGTEXT: Stores large text values whose exceeds
4GB
 Storage: Length+4
TEXT: Stores medium-sized text whose size up to
64KB

 Storage: Length+2

MySQL Database / Session 4 / Slide 17 of 38


Date Data Type-I






A date data type is used to store of various types of
date and time information. Birth dates of employees
are stored in date type column.
The date type has a specific format. While entering
data user should be careful about the format.
The default date format is: 'YYYY-MM-DD'

MySQL Database / Session 4 / Slide 18 of 38


Date Data Type – II




DATE- Stores a date type of data
 Format: YYYY-MM-DD
 Storage: 3

 Range: January 1,1000 to December 31,9999
DATETIME: Stores date and time
 Format: YYYY-MM-DD hh:mm:ss
 Storage: 8
 Range: 1000-01-01 00:00:00 to 9999-12-31
23:59:59
MySQL Database / Session 4 / Slide 19 of 38


Date Data Type - III




TIME- Stores time
 Format: hh:mm:ss
 Storage: 3
YEAR- Stores the year
 Format: YYYY
 Range: 1900 to 2155
 Storage: 1
MySQL Database / Session 4 / Slide 20 of 38


Date Data Types - IV


TIMESTAMP- Stores the timestamp
 Format: YYYY-MM-DDhhmmss
 Storage: 4


MySQL Database / Session 4 / Slide 21 of 38


Complex Data Types-I





Complex data type is a special string data type
Enables the user to list the possible values to be
inserted in a column
The complex data types are:



ENUM
SET

MySQL Database / Session 4 / Slide 22 of 38


Complex Data Types-II




SET- Stores a list of values from a predefined set of
values. Maximum of 64 values are stored in a SET data

type column.
 Storage: 1-8
ENUM- Stores one value out of a possible 65535
number of options in a predefined list of possible values
 Storage: 1,2

MySQL Database / Session 4 / Slide 23 of 38


Creating Tables-I




MySQL creates an ‘.frm’ file to hold the table and
column definitions. If we do not specify the table type
the default table type is MyISAM.
Types of tables:
 Transaction-safe
 Non-transaction

MySQL Database / Session 4 / Slide 24 of 38


Features of transaction tables










Provides safety from data loss
Enables user to combine many statements and
execute all the commands by issuing the COMMIT
command
Enables the user to ignore changes by issuing
ROLLBACK command
Provides better concurrency if many users are
simultaneously reading data from the table
Examples of transaction-safe tables are InnoDB
and BDB
MySQL Database / Session 4 / Slide 25 of 38


×