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 1Implementing the SQL queries
using MySQL-I
Session 6
Trang 2MySQL 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 4MySQL Database / Session 6 / Slide 4 of 48
Trang 5View 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 6MySQL Database / Session 6 / Slide 6 of 48
View Database with LIKE
Trang 7View Tables- I
To view a list of tables of a database,
the syntax is:
SHOW TABLES [FROM database_name] [LIKE
clause];
Trang 8MySQL Database / Session 6 / Slide 8 of 48
Trang 9View Tables using FROM clause
Show the tables of the EMPLOYEE
database
SHOW TABLES FROM EMPLOYEE;
Trang 10MySQL 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 11View 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 12MySQL Database / Session 6 / Slide 12 of 48
Trang 13View Columns using LIKE clause
Show columns that
starts with the
Trang 14MySQL 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 15View Index Keys-II
Show the index
Trang 16MySQL Database / Session 6 / Slide 16 of 48
View Default Variables
Show the values
of the system
variables
SHOW VARIABLES;
Trang 17View Default Variables using
LIKE clause-I
To view only those variables that match
the specified pattern, the syntax is:
SHOW VARIABLES [LIKE clause];
Trang 18MySQL 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 19View Server Status
Show the server
status
SHOW STATUS;
Trang 20MySQL 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 21View Table Status-II
Show the status of
all the tables of
the EMPLOYEE
database
SHOW TABLE STATUS
FROM EMPLOYEE;
Trang 22MySQL 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 23View rights of a user-II
Show the list
Trang 24MySQL 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 25Altering 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 26MySQL 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 27Display the data from a table-II
Display all records of the EMP_DETAILS
table
SELECT * FROM EMP_DETAILS;
Trang 28MySQL 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 29Using SELECT with DISTINCT
Trang 30MySQL 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 31Display selected records-II
Trang 32MySQL Database / Session 6 / Slide 32 of 48
Display records using Arithmetic Operator
Trang 33Display records using
Trang 34MySQL Database / Session 6 / Slide 34 of 48
Display records using
Trang 35Display records using Logical
Trang 36MySQL 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 39Alter 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 41Alter table by adding Primary
key-I
To add a primary key to the
column of a table, the syntax
Trang 42MySQL Database / Session 6 / Slide 42 of 48
Alter table by adding Primary
Trang 43Alter 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 44MySQL 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 45Delete 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 46MySQL Database / Session 6 / Slide 46 of 48
Delete a table along with its
Trang 47Delete a table along with its
table definition-III
Remove SAMPLE table from EMPLOYEE database
DROP TABLE SAMPLE;
Trang 48MySQL 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