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

slide môn học MySQL bài 3 implementing the SQL queries using MySQL i

48 318 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 48
Dung lượng 1,44 MB

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 6 / Slide 10 of 48View Tables using LIKE clause  Show tables that begin with the letter ‘E’ from the EMPLOYEE database SHOW TABLES FROM EMPLOYEE LIKE ‘E %

Trang 1

Implementing the SQL queries

using MySQL-I

Session 6

Trang 2

MySQL Database / Session 6 / Slide 2 of 48

Databases are used to store information

Relational Databases consists of several tables

Data types are classified as numeric, String,

Date and Complex

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

Indexing a database facilitates a faster find

and sort operations in the database

Review

Trang 3

View and Alter the database

Select and Display the data from a table

Change the table definition

Delete a table along with its table

definition

Trang 4

MySQL Database / Session 6 / Slide 4 of 48

Trang 5

View Database with LIKE

clause-I

To view the list of databases that begin

or contain the specified character in the database name, the syntax is:

SHOW DATABASES [LIKE clause];

Trang 6

MySQL Database / Session 6 / Slide 6 of 48

View Database with LIKE

Trang 7

View Tables- I

To view a list of tables of a database,

the syntax is:

SHOW TABLES [FROM database_name] [LIKE

clause];

Trang 8

MySQL Database / Session 6 / Slide 8 of 48

Trang 9

View Tables using FROM clause

Show the tables of the EMPLOYEE

database

SHOW TABLES FROM EMPLOYEE;

Trang 10

MySQL Database / Session 6 / Slide 10 of 48

View Tables using LIKE clause

Show tables that

begin with the

letter ‘E’ from

the EMPLOYEE

database

SHOW TABLES FROM

EMPLOYEE LIKE ‘E

%’;

Trang 11

View Columns-I

To view the column structure of the

specified table from the specified

database, the syntax is:

SHOW COLUMNS FROM table_name [FROM

database_name] [LIKE clauses];

Trang 12

MySQL Database / Session 6 / Slide 12 of 48

Trang 13

View Columns using LIKE clause

Show columns that

starts with the

Trang 14

MySQL Database / Session 6 / Slide 14 of 48

View Index keys-I

To view the index of a table from a

database, the syntax is:

SHOW INDEX FROM table_name [FROM

database_name];

Trang 15

View Index Keys-II

Show the index

Trang 16

MySQL Database / Session 6 / Slide 16 of 48

View Default Variables

Show the values

of the system

variables

SHOW VARIABLES;

Trang 17

View Default Variables using

LIKE clause-I

To view only those variables that match

the specified pattern, the syntax is:

SHOW VARIABLES [LIKE clause];

Trang 18

MySQL Database / Session 6 / Slide 18 of 48

View Default Variables using

LIKE clause-II

Show variables that

matches with the

pattern ‘HAVE’

SHOW VARIABLES LIKE

‘HAVE%’;

Trang 19

View Server Status

Show the server

status

SHOW STATUS;

Trang 20

MySQL Database / Session 6 / Slide 20 of 48

View Table Status-I

To display more information about tables, the syntax is:

SHOW TABLE STATUS [FROM database_name]

[LIKE clauses];

Trang 21

View Table Status-II

Show the status of

all the tables of

the EMPLOYEE

database

SHOW TABLE STATUS

FROM EMPLOYEE;

Trang 22

MySQL Database / Session 6 / Slide 22 of 48

View rights of a user-I

To view a list of grants that can be

issued to duplicate grants for a user,

the syntax is:

SHOW GRANTS FOR user;

Trang 23

View rights of a user-II

Show the list

Trang 24

MySQL Database / Session 6 / Slide 24 of 48

Altering Database on the

To modify the character set of a database, the syntax is:

ALTER DATABASE database_name DEFAULT

CHARACTER SET charset_name;

Trang 25

Altering Database on the

file system-II

To modify the character set to swe7 of a temporary

database named as TEST

ALTER DATABASE TEST DEFAULT CHARACTER SET swe7;

Trang 26

MySQL Database / Session 6 / Slide 26 of 48

Display the data from a table-I

The SELECT command is used to retrieve

data from one or more tables To retrieve all the records of a table, the syntax is: SELECT [*] FROM table_name;

Trang 27

Display the data from a table-II

Display all records of the EMP_DETAILS

table

SELECT * FROM EMP_DETAILS;

Trang 28

MySQL Database / Session 6 / Slide 28 of 48

Using SELECT with DISTINCT

clause-I

To view distinct records of a table, the

syntax is:

SELECT DISTINCT column_name1,

column_name2 FROM table_name;

Trang 29

Using SELECT with DISTINCT

Trang 30

MySQL Database / Session 6 / Slide 30 of 48

Display selected records-I

To view selected columns of a table, the

syntax is:

SELECT column_name1, column_name2 FROM

table_name;

Trang 31

Display selected records-II

Trang 32

MySQL Database / Session 6 / Slide 32 of 48

Display records using Arithmetic Operator

Trang 33

Display records using

Trang 34

MySQL Database / Session 6 / Slide 34 of 48

Display records using

Trang 35

Display records using Logical

Trang 36

MySQL Database / Session 6 / Slide 36 of 48

Altering the table definition

The ALTER TABLE command is used to

modify the structure of a table The

syntax for altering a table is:

 

ALTER [IGNORE] TABLE table_name

alter_spec[, alter_spec ]

 

Trang 37

Alter table by adding column-I

To add a column in the existing table, the

syntax is:

ALTER TABLE table_name ADD [COLUMN]

create_definition [FIRST | AFTER

column_name]

 

Trang 38

MySQL Database / Session 6 / Slide 38 of 48

Alter table by adding column-II

Add a column CITY

to the EMP_DETAILS

table for entering

the name of the

Trang 39

Alter table by adding Index key-I

To add an index key to a column of a

table, the syntax is:

ALTER TABLE table_name ADD INDEX

[index_name] (index_column_name )

 

Trang 40

MySQL Database / Session 6 / Slide 40 of 48

Alter table by adding Index key-II

Trang 41

Alter table by adding Primary

key-I

To add a primary key to the

column of a table, the syntax

Trang 42

MySQL Database / Session 6 / Slide 42 of 48

Alter table by adding Primary

Trang 43

Alter table by renaming the table name-I

To rename a table from an old

table name to new table name, the

syntax is:

ALTER TABLE table_name RENAME

[AS] new_table_name  

Trang 44

MySQL Database / Session 6 / Slide 44 of 48

Alter table by renaming the table name-II

Rename the table name from SALARY_DETAILS to

EMP_SALARY

ALTER TABLE SALARY_DETAILS RENAME EMP_SALARY;  

Trang 45

Delete a table along with its

table definition-I

The DROP TABLE command is used to

remove or delete tables from a

database This command removes table

definition, all data, indexes,

triggers, constraints, and permission

specification for that table

Trang 46

MySQL Database / Session 6 / Slide 46 of 48

Delete a table along with its

Trang 47

Delete a table along with its

table definition-III

Remove SAMPLE table from EMPLOYEE database

DROP TABLE SAMPLE;

Trang 48

MySQL Database / Session 6 / Slide 48 of 48

For retrieving data from a table, the SELECT command is used

The DROP command is used to remove or delete

a table with its definitions from a database

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

TỪ KHÓA LIÊN QUAN