Method signatures

Method signatures define/describe:

  • the name/identifier of the method
  • the parameters of the method (identifier and data type)
  • the return type of the method eg void or int etc

Objectives

Students will be able to:

  • understand the difference between Data Definition Language and Data Manipulation Language
  • write SQL statements to define data structures or to manipulate data

Data Language Types in SQL

SQL

SQL can be split into different language types:

  • Data Definition Language - DDL
  • Data Manipulation Lanhuage - DML

Here is a breakdown in the diffferences between the two:

  DDL DML
purpose Defines or changes the structure of a database Retrieves or changes the data stored in the structures
Common SQL statements CREATE / ALTER / DROP SELECT / INSERT / UPDATE / DELETE

DDL I

We can use DDL to CREATE a new table in a database:

DDL II

During the design of the database, we can use DROP to delete a table or column, or ALTER to change the structure of a table eg:

DML I

Now that we have created some data structures (tables) in the database, we can manipulate the data using DML

Database Administrator Task

You are a database administrator.

Open your database software eg XAMPP and create a new database called SchoolBase

Now continue to the challenges.

Database Administrator Task 1 - CREATE the tables

Using Data Definition Language, create the following 2 database tables:

Students

Field Info
studentID INT(3), PRIMARY KEY
firstName VARCHAR(16)
lastName VARCHAR(16)
yearGroup INT(2)
email VARCHAR(36)

Clubs

Field Info
clubID INT(3), PRIMARY KEY
clubName VARCHAR(24)
Day VARCHAR(9)

SignUp

Field Info
signupID INT AUTO_INCREMENT PRIMARY KEY
clubID INT(4)
studentID INT(4)

Database Administrator Task 2 - INSERT values

Run the following SQL statements:

School Admin Request

School admin is contacting you, the database administrator, to handle the following requests.

Use your skills and knowledge of DDL and DML to handle the requests.

Request 1 - DML

The school has changed the name of the Robotics club to RoboClub

Request 2 - DML

Alex has left the Football club. Delete the appropriate record from the SignUp table. Kudos if you can do this using joins!

Request 3 - DDL

The school wants to record the location that each club is help in.

Add a new field/column to the Club table called Location. Choose an appropriate datatype.

Request 4 - DML

The following club locations have been confirmed:

Club Location
RoboClub Rm138
Football Field
Chess Library

Update the Club table to reflect these changes.

Request 5 - DML?

Select the last name and first name of every student in the RoboClub. Order by last name.

REFLECT

This activity was intended to introduce the difference between DDL and DML in SQL.

Hopefully, it also gave you a chance to review how to select specific data from a database.

This would have included using JOINS.

If you had wanted to restrict access to the database, you could have created some views instead.

The view would provide a layer of security between the user of the database and the database itself.

There are 2 types of view:

  • Virtual View - stores the underlying SQL but doesn't reveal it to the user. We can say it hides the complexity of the SQL from the user.
  • Materialized View (snapshot) - stores the SQL and the resulting dataset. The next time the view is executed, it can quickly return the stored dataset rather than having to interrogate the database again. Unfortunately, this may mean the returned dataset is out of date (stale).

Tags

ACIDpessimistic locking atomicity consistency isolation TCL durabilityDDL DMLCREATE ALTERUPDATE INSERT INTOBEGIN TRANSACTION COMMITROLLBACK