1. Trang chủ
  2. » Mẫu Slide

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

38 309 0

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

THÔNG TIN TÀI LIỆU

Thông tin cơ bản

Định dạng
Số trang 38
Dung lượng 314 KB

Các công cụ chuyển đổi và chỉnh sửa cho tài liệu này

Nội dung

MySQL Database / Session 4 / Slide 5 of 38Naming 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 ‘_

Trang 1

Using MySQL

Session 2

Trang 2

 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

Trang 3

MySQL Database / Session 4 / Slide 3 of 38

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

Trang 4

integrity and indexing

Trang 5

MySQL Database / Session 4 / Slide 5 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

Trang 6

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

Trang 7

MySQL Database / Session 4 / Slide 7 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 ( );

Trang 8

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>

Trang 9

MySQL Database / Session 4 / Slide 9 of 38

Creating Database-II

 To create a EMPLOYEE

database,enter the following

at the command prompt:

CREATE DATABASE

EMPLOYEE;

Trang 10

Data Types Classification

Trang 11

MySQL Database / Session 4 / Slide 11 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

Trang 12

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

Trang 13

MySQL Database / Session 4 / Slide 13 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

Trang 14

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

Trang 15

MySQL Database / Session 4 / Slide 15 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

Trang 16

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

Trang 17

MySQL Database / Session 4 / Slide 17 of 38

String Data Types- III

LONGTEXT: Stores large text values whose exceeds

Trang 18

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'

Trang 19

MySQL Database / Session 4 / Slide 19 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

Trang 20

Date Data Type - III

TIME- Stores time

Trang 21

MySQL Database / Session 4 / Slide 21 of 38

Date Data Types - IV

TIMESTAMP- Stores the timestamp

Format: YYYY-MM-DDhhmmss

Storage: 4

Trang 22

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

Trang 23

MySQL Database / Session 4 / Slide 23 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

Trang 24

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

Trang 25

MySQL Database / Session 4 / Slide 25 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

Trang 26

Features of non-transaction safe

tables

 Faster than the transaction-safe tables as no

transaction overhead is required

 Lesser disk space is required

 Lesser memory required for updates

 Example of non-transaction safe are HEAP, ISAM,

MERGE, and MyISAM

Trang 27

MySQL Database / Session 4 / Slide 27 of 38

Creating Table-III

 The syntax for creating a table is:

CREATE [TEMPORARY] TABLE [IF NOT

EXISTS]table create_clause, )

table_options] [IGNORE [REPLACE] select]

Trang 28

Creating Table -IV

 To create a EMP_DETAILS table, enter the following at the

command prompt:

CREATE TABLE EMP_DETAILS(E_ID INT(3),E_FNAME

CHAR(10), E_LNAME CHAR(15), E_ADDRESS

CHAR(15),E_PHONE_NO INT(6));

Trang 29

MySQL Database / Session 4 / Slide 29 of 38

Viewing the Table Structure

 The syntax to view the structure

is:

DESCRIBE table

[column]

 To view the structure of the table

created, enter the following at the

command prompt:

DESC EMP_DETAILS;

Trang 30

Normalization - I

 Data is structured in a table to minimize duplication and

inconsistency in data

 Involves breaking down of a table into two or tables and

defining relationships between them

 Improves the clarity in the database

Trang 31

MySQL Database / Session 4 / Slide 31 of 38

Normalization - II

Entity - Represents an object about which we want to

store the information

Attributes - Represents the component of entity type

Domain -Defines the range for the attributes

Relationship - Represents association between

entities

Trang 32

Defining Keys

 Keys are used to describe the relation between

columns These keys uniquely identify a record

 Types of keys:

Primary key: is a column in the table which is

used as the unique identifier

Composite key: is a primary key having more than

one attribute

Foreign key: is a key in table which is also the

Primary Key in another table

Trang 33

MySQL Database / Session 4 / Slide 33 of 38

Forms of Normalization - I

 Different forms of normalization are applied on a database

 A database is in the first normal form if:

 All attributes are atomic

 All columns have only one instance

 A database is in 2NF if:

 It is in the first normal form

 All non key attributes entirely depend on the unique

identifier of the entity

Trang 34

Forms of Normalization - II

 A database is in 3NF if:

 It is in the second form

 No attribute is dependent on non-key attribute

 A database in the Boyce-Codd normal if:

 It is in the third normal form

 Only one unique identifier exists

Trang 35

MySQL Database / Session 4 / Slide 35 of 38

Database Concepts-I

 Referential integrity feature prevents users or

applications from entering inconsistent data

 To implement referential integrity, foreign key must

exits

 Indexing is used on databases to make the find and

search operations faster

 Indexes can be defined while creating the table

 A field on which the search is to be performed is

indexed Several fields in a table can also be indexed at a time

 Indexing reduces the speed of updating a database

Trang 36

Summary - I

 Databases are used to store information

 Relational Databases consists of several tables

 A table consists of rows and columns

 Data types are classified as numeric, String, Date and Complex

 Numeric data types are used to store numerical data

 String data types holds data that consists of characters from a-z and numbers from 0-9

 Date data type column have date values entered as

string values in the form of 'YYYY-MM-DD' format

Trang 37

MySQL Database / Session 4 / Slide 37 of 38

Summary - II

 Normalization is the process in which the

redundancies in the database are removed

 A Primary key is a field in the table which is used as

the unique identifier

 An entity is said to be in the first normal form if all

the attributes are single valued

 An entity is said to be in the second normal form, if

it is in the first normal and all non key attributes

entirely depend on the unique identifier of the entity

Trang 38

Summary - III

normal form if it is already in the third normal form and only one unique identifier exists

data of related tables

sort operations in the database

Ngày đăng: 30/11/2016, 22:10

TỪ KHÓA LIÊN QUAN

w