Sunteți pe pagina 1din 11

Course: Experiment No.

:
Name: Section:
Date Performed:
Date Submitted:
Instructor:


Laboratory Exercise No. 3
CONNECTING TO THE DATABASE AND DATA DEFINITION LANGUAGE

1. Objective(s):

The activity aims to introduce data definition language and its command

2. Intended Learning Outcomes (ILOs):

The students shall be able to: Construct a database and implement data definition language

3. Discussion
Date Definition Language or DDL is the part in SQL that constructs the database structure such as
creating the database, creating tables, modifying and deleting databases and tables.

4. Resources:

1 Desktop Computer
MYSQL

5. Procedure:
THE ORIGINAL TABLE
SCH_ID
(PK)
SCH_NA
ME
STU_ID
(PK)
STU_L
NAME
STU_F
NAME
PROG_I
D(PK)
PROG_
DESC
CRS
_ID
CRS_N
AME
PRO
F_ID
PROF_NA
ME
1 TIPMLA 303 Alday Angelo 1 CPE 1 LOGIC 301
ENGR.
CRUZ
1 TIPMLA 302 Oliva Dave 1 CPE 1 LOGIC 301
ENGR.
CRUZ
1 TIPMLA 720 Mokih Mikoh 1 CPE 1 LOGIC 301
ENGR.
CRUZ
1 TIPMLA 309 Gabion Jam 1 CPE 1 LOGIC 301
ENGR.
CRUZ
2 TIPQC 544 Castro Michael 1 CPE 1 LOGIC 301
ENGR.
CRUZ
2 TIPQC 567 Cruz Jeric 1 CPE 1 LOGIC 301
ENGR.
CRUZ
2 TIPQC 563
De
Guzman Mae 2 ECE 1 LOGIC 301
ENGR.
CRUZ
3
TIPLAG
UNA 453 Zabala Joseph 2 ECE 1 LOGIC 301
ENGR.
CRUZ
3
TIPLAG
UNA 235 Falcon Kevin 3 EE 1 LOGIC 301
ENGR.
CRUZ
3
TIPLAG
UNA 787
Hernand
ez Rhea 3 EE 1 LOGIC 301
ENGR.
CRUZ
1 TIPMLA 302 Oliva Dave 1 CPE 1 LOGIC 301
ENGR.
CRUZ
2 TIPQC 544 Castro Michael 1 CPE 2
CIRCU
ITS 302
ENGR.
BELTRAN
2 TIPQC 567 Cruz Jeric 1 CPE 2
CIRCU
ITS 302
ENGR.
BELTRAN
3
TIPLAG
UNA 787
Hernand
ez Rhea 3 EE 2
CIRCU
ITS 302
ENGR.
BELTRAN
3
TIPLAG
UNA 453 Zabala Joseph 2 ECE 2
CIRCU
ITS 302
ENGR.
BELTRAN
2 TIPQC 567 Cruz Jeric 1 CPE 3 ELECS 301
ENGR.
CRUZ
2 TIPQC 563
De
Guzman Mae 2 ECE 3 ELECS 301
ENGR.
CRUZ
3
TIPLAG
UNA 453 Zabala Joseph 2 ECE 3 ELECS 301
ENGR.
CRUZ
3
TIPLAG
UNA 235 Falcon Kevin 3 EE 3 ELECS 301
ENGR.
CRUZ
















HOW TO CONNECT TO MYSQL
1. Open the MYSQL command line client and type the password for the root user
2. If it is not available open a command prompt and locate the bin folder of MYSQL
3. Type the command
mysql h <hostname> u root p
then enter and it will prompt for a password
-u refers to username
-p refers to password
4. You should be in the line of mysql>
mysql > - this means mysql is ready to accept commands.


5. By default, the commands is
mysql u root p

6. You need to be in the bin path of mysql in running the commands

a. The Connection may differ if you will use xampp
C:\xampp\mysql\bin
b. For mysql server you can just run the mysql command line or you can locate that on the
path below
C:\Program Files\MySQL\MySQL Server 5.5\bin

7. Be sure that the sql server in xampp is running before connecting


COMMANDS FOR HELP
\? or for server side \help













Notes:
You can use (;) Semicolon to end each statement or \g
You can use \q or QUIT to quit or exit
There are some dbms created for database creation which does not require semicolon for sql query

OTHER FUNCTIONS
VERSIONS()
CURRENT_DATE()
NOW()
USER()
SQL QUERY are not case sensitive therefore you can write it in uppercase or in lowercase
We are to create the Normalized form that we finished before
To show the databases with s
Show databases;
Creating a database to create a database we need to execute a query
Syntax: CREATE DATABASE <DATABASE NAME>
Execute the query below
Create database MYDB;
Then try to show the database again using the show databases
Did you see the database MYDB?
If YES then we are able to create the database
If NO what are the possible concern regarding the error
Check the query stated that should be copied correctly regardless of the case
Check if the database already exist, thus create another file
Then if we you are able to create the database we need to have the tables which describes the database
itself
But before we can create the table first is we need to identify what database we should use on which
the table belongs.
To USE a database or SELECT a database
Syntax: USE <database name>
Execute the query below
USE MYDB
The output should be
Database changed

CREATE TABLE
In Creating a table this is the syntax
CREATE TABLE table_name
(
column_name1 data_type,
column_name2 data_type,
column_name3 data_type,
....
)
Then if there is a Primary key
CREATE TABLE table_name
(
column_name1 data_type,
column_name2 data_type,
column_name3 data_type,
...
primary key (column_name/s)
)


Given the syntax the query for the CRS table is this one kindly check
CREATE TABLE CRS (
CRS_ID int not null primary key,
CRS_NAME varchar(45)
);

The output of the program should be that the query is ok
To validate the program if the query has taken effect we need to check if the table CRS has been added
To Show the tables on a database
SHOW tables;
To describe the table or to know the characteristic of the table
The syntax is
SHOW COLUMNS FROM <tablename>
Or
DESCRIBE <tablename>
Therefore, if we want to know the characteristic
of CRS we will have the query
SHOW COLUMNS FROM CRS;








Create the table for the Professor, Program, and School since those have the same Layout with CRS
table.
Do not continue if you are not finish
Then after creating show the tables in the mydb database the database should have 4 tables already.
Next is to create the next table which is the student
However, the student has a foreign key
So heres OUR rule for declaring an index
Index name should be in the proper format
fk_<referencing table>_<referenced_table>_<column of referenced table>
so we will have here
fk_student_prog_prog_id
fk_student_school_sch_id

also do name the constraint of the foreign key, the constraint is the relationship of the referencing table
to the referenced table
for us not to remember a lot, we will just name the constraint according to the index.



Then for the crs_has_prof table
create table crs_has_prof(
CRS_CRS_ID int not null,
PROF_PROF_ID int not null,
PRIMARY KEY (CRS_CRS_ID, PROF_PROF_ID),
INDEX fk_crs_id (CRS_CRS_ID ASC),
INDEX fk_prof_id (prof_prof_ID ASC),
CONSTRAINT fk_crs_id
FOREIGN KEY (CRS_CRS_ID)
REFERENCES CRS(CRS_ID),
CONSTRAINT fk_prof_id
FOREIGN KEY (PROF_PROF_ID)
REFERENCES PROF(PROF_ID)
);
And for the stud_has_crs
create table STU_CRS(
STUDENT_STUD_ID int not null,
CRS_CRS_ID int not null,
PRIMARY KEY (STUDENT_STUD_ID,CRS_CRS_ID),
INDEX fk_STUD_ID (STUDENT_STUD_ID ASC),
INDEX fk_CRS_ID2 (CRS_CRS_ID ASC),
CONSTRAINT fk_STUD_ID
Foreign key (STUDENT_STUD_ID)
references STUDent(STUD_ID),
CONSTRAINT fk_CRS_ID2
Foreign key (CRS_CRS_ID)
references CRS(CRS_ID)
);
Now check if all the tables have been created accordingly. And describe the characteristic of each table

If ever you committed a mistake you can drop the table using drop command
DROP TABLE <table_name>;
And create another table

6. Data and Results:
List down all the data definition languages commands


7. Conclusion:
Based from the results of the experiment, what general rule can you apply for?

CONNECTING TO THE DATABASE
______________________________________________________________________________________________
______________________________________________________________________________________________
______________________________________________________________________________________

DATA DEFINITION LANGUAGE
______________________________________________________________________________________________
______________________________________________________________________________________________
______________________________________________________________________________________

PRIMARY KEY AND FOREIGN KEY
______________________________________________________________________________________________
______________________________________________________________________________________________
______________________________________________________________________________________

















8. Assessment (Rubric for Laboratory Performance):
CRITERIA
BEGINNER
1
ACCEPTABLE
2
PROFICIENT
3
SCORE
I. Laboratory Skills
Manipulative
Skills
Members do not
demonstrate needed
skills
Members occasionally
demonstrate the
needed skills
Members always
demonstrate the
needed skills

Experimental
Set - Up
Members are unable to
set-up the materials
Members are able to
set-up the materials
with supervision
Members are able to
set-up the materials
with minimum
supervision

Process Skills
Members do not
demonstrate targeted
process skills
Members occasionally
demonstrate targeted
process skills
Members always
demonstrated
targeted process
skills

Safety
Precaution
Members do not follow
safety precautions
Members follow safety
precautions most of the
time
Members follow
safety precautions at
all times

II. Work Habits
Time
Management/
Conduct of
Experiment
Members do not finish
on time with
incomplete data
Members finish on time
with incomplete data
Members finish
ahead of time with
complete data and
time to revise data

Cooperative and
Teamwork
Members do not know
their tasks and have no
defined responsibilities.
Group conflicts have to
be settled by the
teacher
Members have defined
responsibilities most of
the time. Group
conflicts are
cooperatively managed
most of the time
Members are on
tasks and have
defined
responsibilities at all
times. Group conflicts
are cooperatively
manages at all times

Neatness and
Orderliness
Messy workplace
during and after the
experiment
Clean and orderly
workplace with
occasional mess
during and after
experiment
Clean and orderly
workplace at all times
during and after the
experiment

Ability to do
independent
work
Members require
supervision by the
teacher
Members require
occasional supervision
by the teacher
Members do not
need to be
supervised by the
teacher

Other comments/observation:
TOTAL SCORE


RATING = (total score) x 100%
24


Evaluated By: Date:

S-ar putea să vă placă și