BTEC Higher National Diploma (HND) in Computing is a two-year vocational qualification that provides students with a solid grounding in computing and IT-related subjects. The program is designed to equip students with the practical skills and theoretical knowledge needed to pursue a successful career in the field of computing.
Throughout the course, students will cover a range of topics, including programming, networking, database management, web development, and software engineering. They will also learn about project management, business communication, and the legal and ethical issues surrounding the use of technology.
The course is delivered through a combination of lectures, practical workshops, and project work. Students will have the opportunity to work individually and in teams on a range of practical projects that will help them develop their skills and knowledge in real-world scenarios.
At the end of the course, students will have developed a portfolio of work that showcases their skills and knowledge to potential employers. They will also have the option to progress onto a top-up degree program or enter the workforce directly.
Overall, the BTEC Higher National Diploma in Computing is an excellent choice for students who want to pursue a career in the fast-paced and dynamic field of computing. It provides a solid foundation of knowledge and skills that will set them on the path to success.
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
BTEC- HND In Computing-Creating Table_Week6.pptx
1. BTEC- HND In Computing
Module Name: Database Design & Development
Unit Number: 4
Week 7
Creating Tables
1
HND-Database Design & Development
2. Unit Learning Outcomes
• LO1. Use an appropriate design tool to design a relational
database system for a substantial problem.
• LO2. Develop a fully functional relational database system,
based on an existing system design.
• LO3. Test the system against user and system requirements.
• LO4. Produce technical and user documentation.
HND-Database Design & Development 2
3. Objectives
BE ABLE TO IDENTIFY:
• The basic concepts and principles of SQL
• The different components of SQL
• How to use SQL (DDL) to perform basic create
operations
o Create
o Insert
o Modify
o Delete data
How to use SQL(DML) to perform basic database queries
HND-Database Design & Development 3
4. Relational Tables Can Answer
Many Queries
HND-Database Design & Development 4
Student Enrolment Course
•How many courses are there & what are their names?
• Which students are enrolled for Java?
• How many students take 3 or more courses?
5. SQL - Structured Query
Language
• SQL was developed at IBM around 1975...
• SQL is a declarative language - says what not how
• SQL is a powerful language,
• SQL is an abstract & portable interface to RDMBs
HND-Database Design & Development 5
6. Structured Query Language
(contd.)
3 COMPONENETS
o Data Definition Language (DDL) for creating a DB
o Data Control Language (DCL) for administering a
DB
o Data Manipulation Language (DML) to insert,
delete and modify data in a table
HND-Database Design & Development 6
7. SQL Syntax
SQL uses English keywords & user-defined names
HND-Database Design & Development 7
CREATE TABLE Staff (
StaffNo INTEGER,
Salary FLOAT,
Lname CHAR(20)
);
INSERT INTO Staff VALUES (32, 25000.0, 'Smith');
By convention, keywords are upper-case
Text data is enclosed using single quotes (‘ ' ‘)
Round brackets (‘(‘) are used to group related items
Commas (‘,’) separate items in a list
Statements are terminated with a semicolon (‘;’)
8. SQL Terminology
SQL does not use formal relational terminology
Formal Informal (SQL)
Relation Table
Tuple Row
Attribute Column
Cardinality No. of rows
Degree No. of columns
Relationships Foreign keys
Constraints Assertions
HND-Database Design & Development 8
9. Structured Query Language
(contd.)
• Creating tables…
o Tables can be created using CREATE TABLE
statement
o There are different data types available in SQL2
HND-Database Design & Development 9
10. Structured Query Language
(contd.)
• Integer (INT, INTEGER & SMALLINT)
• Real numbers (FLOAT, REAL, DOUBLE)
• Formatted numbers DECIMAL(i,j) or DEC(i,j) or NUMERIC(i,j)
• Character strings
o Fixed length: CHAR(n) or CHARACTER(n)
o Variable length: VARCHAR(n)
• Date and Time: DATE and TIME data types are supported in
SQL2
HND-Database Design & Development 10
14. Structured Query Language
(contd.)
• Other candidate keys…
o UNIQUE - identifies an individual tuple uniquely in a relation or table. A table
can have more than one unique key unlike primary key. Unique key constraints
can accept only one NULL value for column.
HND-Database Design & Development 14
CREATE TABLE Student (
Stdid CHAR (10) PRIMARY KEY
Name CHAR(20),
Address CHAR(25),
Age INTEGER,
Gpa REAL,
NIC CHAR(10) UNIQUE);
15. Structured Query Language
(contd.)
• Referential Integrity Constraints
o FOREIGN KEY………REFERENCES
• Student (stdId, name ,address , age , gpa)
• Grade( subjectId, stdId , grade)
HND-Database Design & Development 15
CREATE TABLE Grade
(
subjectId CHAR(4),
stdId CHAR(10),
grade CHAR(2),
PRIMARY KEY(subjectId, stdId),
FOREIGN KEY(stdId) REFERENCES Student
)
16. Structured Query Language
(contd.)
• Alternative
o FOREIGN KEY
HND-Database Design & Development 16
CREATE TABLE Grade (
subjectId CHAR(4),
stdId CHAR(10) REFERENCES Student(stdId),
grade CHAR(2),
PRIMARY KEY(subjectId,stdid)
);
17. Structured Query Language
(contd.)
• The use of a constraint name allows identification of a
constraint which can be dropped later (using the ALTER
TABLE command)
HND-Database Design & Development 17
CREATE TABLE Grade (
subjectId CHAR(4),
stdId CHAR(10) ,
grade CHAR(2),
PRIMARY KEY(subjectId,stdid),
CONSTRAINT fk_Grade FOREIGN KEY(stdid)
REFERENCES Student(stdId)
);
18. Structured Query Language
(contd.)
• Specifying NOT NULL constraints…
o NOT NULL
HND-Database Design & Development 18
CREATE TABLE Student (
Name CHAR(20) NOT NULL,
Address CHAR(25),
Age INTEGER,
Gpa REAL
);
19. Structured Query Language
(contd.)
• Specifying default values…
o DEFAULT - is used to set a default value for a column.
o The default value will be added to all new records, if no other value is specified.
HND-Database Design & Development 19
CREATE TABLE Student (
Name CHAR(20),
Address CHAR(25) DEFAULT ‘Malabe’,
Age INTEGER,
Gpa REAL
);
20. Structured Query Language
(contd.)
• Specifying valid values…
o CHECK constraints - is used to limit the value range that can be placed in a
column.
HND-Database Design & Development 20
CREATE TABLE Emp (
….
age INT CHECK (age BETWEEN 0 AND 120),
….);
21. Structured Query Language
(contd.)
• Referential Triggered Action:
o Operations
• ON UPDATE
• ON DELETE
o Actions
• SET NULL
• CASCADE
• SET DEFAULT
HND-Database Design & Development 21
22. Structured Query Language
(contd.)
ON DELETE CASCADE
• It specifies that the child data is deleted when the
parent data is deleted.
ON UPDATE
• Optional. It specifies what to do with the child data
when the parent data is updated. You have the options of
NO ACTION, CASCADE, SET NULL, or SET DEFAULT.
HND-Database Design & Development 22
23. Structured Query Language
(contd.)
NO ACTION
• It is used in conjunction with ON DELETE or ON
UPDATE. It means that no action is performed with the
child data when the parent data is deleted or updated.
Cascade
• It is used in conjunction with ON DELETE or ON
UPDATE. It means that the child data is either deleted or
updated when the parent data is deleted or updated.
HND-Database Design & Development 23
24. Structured Query Language
(contd.)
SET NULL
• It is used in conjunction with ON DELETE or ON
UPDATE. It means that the child data is set to NULL
when the parent data is deleted or updated.
SET DEFAULT
• It is used in conjunction with ON DELETE or ON
UPDATE. It means that the child data is set to their
default values when the parent data is deleted or
updated.
HND-Database Design & Development 24
25. Structured Query Language
(contd.)
HND-Database Design & Development 25
CREATE TABLE Employee (
NIC VARCHAR(10) PRIMARY KEY,
name VARCHAR(50) UNIQUE NOT NULL,
address VARCHAR(25) DEFAULT 'Colombo',
works_in INTEGER,
CONSTRAINT fk_EmpDept FOREIGN KEY (works_in)
REFERENCES Dept ON DELETE CASCADE
ON UPDATE NO ACTION
);
26. Structured Query Language
(contd.)
• Dropping tables
DROP TABLE Employee [RESTRICT|CASCADE]
o RESTRICT drops if no other constraints (such as foreign
keys or views exist)
o CASCADE drops all constraints & views that reference it
* SQL Server 2000 has only RESTRICT option which is the
default
HND-Database Design & Development 26
27. Structured Query Language
(contd.)
• Altering tables…
o ALTER TABLE can be used to add or drop a column,
change a column definition, and adding or dropping
table constraints
The new column has null values. Hence, NOT NULL
cannot be used here
HND-Database Design & Development 27
ALTER TABLE Employee ADD Job VARCHAR(12)
28. Structured Query Language
(contd.)
Dropping a column…
Changing column definition…
Dropping a constraint
HND-Database Design & Development 28
ALTER TABLE Employee DROP COLUMN Job
ALTER TABLE Employee ALTER COLUMN job vachar(50)
ALTER TABLE Employee DROP fk_EmpDept
29. Structured Query Language
(contd.)
• We can modify data using the following three commands:
INSERT, DELETE and UPDATE
• INSERT statement:
o Inserting a single row
• *The order of values must be the same as in the
CREATE TABLE statement
HND-Database Design & Development 29
INSERT INTO Dept VALUES (1, 'Sales', 'BoC Merchant Tower')
30. Structured Query Language
(contd.)
Inserting to user-specified columns
• * Only the columns are specified are filled with values.
Unspecified columns are filled with NULL if there is no
default values.
HND-Database Design & Development 30
INSERT INTO Employee (NIC, name, works_in)
VALUES ('781111111V', 'Ajith Perera', 1)
31. Structured Query Language
(contd.)
• Inserting multiple rows…
INSERT INTO Employees
<Select statement>*
*we’ll learn the select statement in detail later
HND-Database Design & Development 31
32. Structured Query Language
(contd.)
• Deleting tuples from tables…
o Deleting all records
o Deleting only specified records
DELETE FROM <table>
WHERE <selection-condition>
o Completely removing a table is a DDL operation
HND-Database Design & Development 32
DELETE FROM Dept
DELETE FROM Dept WHERE dno = 2
DROP TABLE Staff
33. Structured Query Language
(contd.)
• Updating tuples in a table
UPDATE <table>
SET <column> = <expression>
WHERE <selection condition>
HND-Database Design & Development 33
34. Structured Query Language
(contd.)
• Updating all tuples
• Updating selected tuples
UPDATE Employee
SET works_in = 2
WHERE NIC = ‘781111111V’
HND-Database Design & Development 34
UPDATE Employee SET works_in = 1
35. Exercises…
• Consider the following schema:
Student(StudentNo:Integer; name:varchar(50),
major:char(4); GPA:float)
Write SQL statements to perform the following
1. Create the above table
2. Insert the following information:
HND-Database Design & Development 35
StudentNo Name Major GPA
1 Sampath EE 3.5
2 Nishani CSE 34
36. Exercises… (contd.)
3. Update Sampath’s GPA to 3.7.
4. Delete student table
5. Add a column address (i.e. address: varchar(50) ) to the
Student table.
6. Change the data type of address column into varchar(100).
7. Add a checking rule to GPA column, GPA values should
between 0 and 4.
8. Remove the check constraint added to the GPA column.
9. Create table Major(majorId , description).
10. Change student table to reflect Primary Key.
HND-Database Design & Development 36
37. Summary
• SQL is the standard query language for RDBMS
• Three main categories of SQL
o DDL, Data Definition Language
o DCL, Data Control Language
o DML, Data Manipulation Language
• CREATE belongs to DDL
HND-Database Design & Development 37