0% found this document useful (0 votes)
5 views

New Session 8

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views

New Session 8

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 25

Session 10

Agenda:
Introduction to languages in SQL
Creating tables and Data types
INTRODUCTION TO MYSQL
• Fast & Easy-to-use RDBMS for many small and big businesses.
• It is developed by MySQL AB, Swedish company.
• MySQL is becoming so popular because of many good reasons:
• MySQL is a open source.
• MySQL is a very powerful
• MySQL uses SQL.
• MySQL works on many operating systems and with many languages including PHP,
PERL, C, C++, JAVA, etc.
• MySQL works very quickly and works well even with large data sets.
• MySQL is very friendly to PHP.
• MySQL supports large databases, up to 50 million rows or more in a table. The default
file size limit for a table is 4GB, you can increase to a theoretical limit of 8 million
terabytes (TB).
• MySQL is customizable. Programmers to modify the MySQL software to fit their own
specific environments.
INSTALATION OF SQL IN LAPTOPS
CONNET MYSQL SERVER IN LAB
• mysql –h 10.45.9.2 –u username –p
• password:
• use db___________;
Administrative MySQL Commands

• USE Databasename : This will be used to select a particular database in MySQL work area.

• SHOW DATABASES: Lists the databases that are accessible by the MySQL DBMS.

• SHOW TABLES: Shows the tables in the database once a database has been selected with the
use command.

• SHOW COLUMNS FROM tablename: Shows the attributes, types of attributes, key
information, whether NULL is permitted, defaults, and other information for a table.

• SHOW INDEX FROM tablename: Presents the details of all indexes on the table, including the
PRIMARY KEY.
SQL statements
• DDL – Data Definition Language
CREATE
ALTER
DROP
TRUNCATE
• DML - Data Manipulation Language
SELECT
INSERT
UPDATE
DELETE
• DCL - Data Control Language
GRANT
REVOKE
DATA DEFINITION LANGAUAGE
Data types

• Numeric
• Date and time
• String types.
DDL Statements for Tables : Create Table
• CREATE [TEMPORARY] TABLE [IF NOT EXISTS] tbl_name
(create_definition,...) [table_options] [partition_options]
DDL Statements for Tables : Create Table
• Create a table DEPT with the following fields
mysql> CREATE TABLE DEPT(
DEPTNO INT, Not Null Constraint
DNAME VARCHAR(10) ,
LOC VARCHAR(10) NOT NULL, Primary Key
Constraint
PRIMARY KEY(DEPTNO),
Unique Key
UNIQUE(DNAME)); Constraint
DDL Statements for Tables : Create Table
• Create a table EMP with the following fields
mysql> CREATE TABLE EMP(
EMPNO INT,
ENAME VARCHAR(10) NOT NULL,
JOB VARCHAR(10),
MGR INT ,
HIREDATE DATE,
SAL FLOAT(7,2) DEFAULT 100.00, Default
COMM FLOAT(7,2), Constraint
DEPTNO INT NOT NULL ,
PRIMARY KEY(EMPNO),
Foreign key
CONSTRAINT emp_mgr FOREIGN KEY(MGR) REFERENCES EMP(EMPNO), Constraint
CONSTRAINT emp_dept FOREIGN KEY(DEPTNO) REFERENCES DEPT(DEPTNO)
);
DESCRIBE
SQL command DESCRIBE can be used to list details of the columns created in a table.
mysql> DESC EMP;
To see table constraint names
• Mysql> use information_schema;
mysql> select constraint_name,table_name from table_constraints
where table_name='emp';

You might also like