Microsoft SQL Server 2014 Data Definition Language (DDL) and Database Management
Core Learning Objectives
Identify Steps in Table Management: Recognize and systematically execute the necessary procedures to manage database tables.
Understand Data Definition Language (DDL): Master the core principles, syntax, and operational capabilities of DDL within Microsoft SQL Server 2014.
Execute Database Operations: Perform database table operations including creating, modifying, deleting structures, and populating data using structured query commands.
Data Definition Language (DDL) Fundamentals
Definition: Data Definition Language (DDL) is a standard set of SQL commands used to define, alter, and manage database structures and schemas.
Scope of Objects: DDL commands act directly upon database structures, including databases, tables, views, functions, and user entities.
Four Basic DDL Commands:
USE: Selects an active database within the SQL schema.
CREATE: Constructs new database objects such as tables, views, and functions.
ALTER: Modifies the existing structure of a database object.
DROP: Deletes existing objects from the database entirely.
Core DDL Commands and Syntaxes
USE Command
Purpose: Selects an existing database in the SQL schema to make it the active database context for subsequent queries.
Syntax:
USE [Database Name]
```
* **Example**:
sql USE Mapagpunyagi_FirstName ```
CREATE Command
Purpose: Creates database objects, specifically tables, views, and functions.
Syntax for Creating a Table:
CREATE TABLE [table name] (
[column name] [data type] [null | not null],
[column name] [data type] [null | not null],
[column name] [data type] [null | not null]
)
```
* **Component Breakdown**:
* **CREATE TABLE**: The DDL command specifying the creation of a table object.
* **[table name]**: The identifier assigned to the new table.
* **Column name**: The identifier for an individual field within the table.
* **Data type**: Defines the type of data the specified column can store (e.g., `int`, `nvarchar(50)`, `decimal(5,2)`).
* **[null | not null]**: An optional constraint specifying whether a column accepts `NULL` values or requires mandatory entries.
* **Example Code**:
sql CREATE TABLE studentprofile ( Student_ID int null, Student_name nvarchar(50) not null, Student_address nvarchar(50) null, Average decimal(5,2) ) ```
Design View Representation:
Student_ID: Data Typeint, Allow Nulls =Yes(NULL)Student_name: Data Typenvarchar(50), Allow Nulls =No(NOT NULL)Student_address: Data Typenvarchar(50), Allow Nulls =Yes(NULL)Average: Data Typedecimal(5, 2), Allow Nulls =Yes(NULL)
Datasheet View / Edit Top 200 Rows Dataset:
Entry 1:
Student_ID=1001,Student_name=Juan Dela Cruz,Student_address=Bahrain,Average=90.75Entry 2:
Student_ID=1002,Student_name=John Javellana,Student_address=Manila,Average=90.12Entry 3:
Student_ID=1003,Student_name=Mark Luis,Student_address=Manila,Average=100.72(also recorded as100.77)Entry 4:
Student_ID=1004,Student_name=John Estrada,Student_address=Bahrain,Average=999.99
ALTER Command
Purpose: Modifies the structure of an existing database table without destroying the existing data object.
Adding Columns:
Syntax:
sql ALTER TABLE [table name] ADD [column name] [data type] [null | not null], [column name] [data type] [null | not null]; Example:
sql ALTER TABLE studentprofile ADD username nvarchar(50); Design View Impact: Adds
username(nvarchar(50), Allow Nulls =Yes).Datasheet View Impact: Existing records display
NULLfor the newusernamecolumn.
Dropping Columns:
Syntax:
sql ALTER TABLE [table name] DROP COLUMN [column name]; Example:
sql ALTER TABLE student_info DROP COLUMN Student_address;
Altering/Modifying Column Attributes:
Syntax:
sql ALTER TABLE [table name] ALTER COLUMN [column name] [data type]; Example:
sql ALTER TABLE student_info ALTER COLUMN Student_ID int NOT NULL;
DROP Command
Purpose: Permanently deletes existing objects (such as tables) from the database schema.
Syntax:
DROP TABLE [table name]
```
* **Example**:
sql DROP TABLE student info ```
Command Scramble Reference Key
RODP DROP (Scramble Reference ID: 995 / 95)
EARLT ALTER (Scramble Reference ID: 996)
EAECRT CREATE (Scramble Reference ID: 95)
SEU USE
YNSATX SYNTAX (Scramble Reference ID: 95)
Assessment Schema and Key
Activity Table Schema Specifications (Pages 72–76)
student_number:nvarchar(50), Allow Null:NoSLastname:nvarchar(50), Allow Null:NoSFirstname:nvarchar(50), Allow Null:NoSMiddlename:nvarchar(50), Allow Null:YesStudent contact number:nvarchar(50), Allow Null:NoSAddress1:nvarchar(50), Allow Null:NoSAddress2:nvarchar(50), Allow Null:NoGuardian:nvarchar(50), Allow Null:NoGuardianaddress:nvarchar(50), Allow Null:NoGuardianphone:Int(4), Allow Null:No
Activity Answer Key
A or D
D
A
C
A
B
B
A
C
D
Student Information System Database Specifications (PeTa 1.1)
Database Task Name: Performance Task 1.1 (PeTa 1.1) - Pages 66 to 71
Database Title: Student Information System Database
Table Schemas
Table 1: studentprofile Schema
Studentnumber:nvarchar(50)SLastname:nvarchar(50)SFirstname:nvarchar(50)SMiddlename:nvarchar(50)[Student contact number]:nvarchar(50)SAddress1:nvarchar(50)SAddress2:nvarchar(50)Guardian:nvarchar(50)Guardianaddress:nvarchar(50)Guardianphone:nvarchar(50)
Table 2: teacherprofile Schema
Subjectcode:nvarchar(50)Teachercode:nvarchar(50)TFname:nvarchar(50)TLname:nvarchar(50)TAddress:nvarchar(50)TPhone:nvarchar(50)LoadUnit:int(Allow Nulls:NOT NULL)
Table 3: student_section Schema
Studentnumber:nvarchar(50)Section:nvarchar(50)Room:nvarchar(50)
Table 4: subject_profile Schema
Subjectcode:nvarchar(50)Subjectdescription:nvarchar(50)[lec units]:int
Master Datasets
Dataset for studentprofile Table
Row 1:
Studentnumber:1001Slastname:MapanooSFirstname:Ma. ElizaSMiddlename:DulayStudent contact number:09175021234SAddress1:Carmona, CaviteSAddress2:Binan, LagunaGuardian:Merlin L. MapanooGuardianaddress:Binan, LagunaGuardianphone:09175023456
Row 2:
Studentnumber:1002Slastname:FloresSFirstname:TyroneSMiddlename:Nyte CatagStudent contact number:09177419821SAddress1:San Pablo City, LagunaSAddress2:Alaminos, LagunaGuardian:Monica C. FloresGuardianaddress:San Pablo City...Guardianphone:09177418732
Row 3:
Studentnumber:1003Slastname:CataagSFirstname:Andrei JacobSMiddlename:BondoyStudent contact number:09236579841SAddress1:Lipa City, BatangasSAddress2:San Pablo CityGuardian:Joy B. Cataag IIIGuardianaddress:Lipa City, Batan..Guardianphone:09233246512
Row 4:
Studentnumber:1004Slastname:MapanooSFirstname:Nevin JoshuaSMiddlename:LauritoStudent contact number:09392358909SAddress1:Sta. Rosa, LagunaSAddress2:Carmona, CaviteGuardian:Mariecris L InfanteGuardianaddress:Binan, LagunaGuardianphone:09175023457
Row 5:
Studentnumber:1005Slastname:InfanteSFirstname:Nell JonardSMiddlename:MapanooStudent contact number:09272358909SAddress1:Sta. Rosa, LagunaSAddress2:Carmona, CaviteGuardian:Mariecris L. InfanteGuardianaddress:Binan, LagunaGuardianphone:09175023458
Dataset for teacherprofile Table
Row 1:
Subjectcode:MATH101|Teachercode:ALMMAR|TFname:Mario|TLname:Almeda|TAddress:Calamba, Laguna|TPhone:09171234567|LoadUnit:15Row 2:
Subjectcode:ENGLISH101|Teachercode:CALEDG|TFname:Edgar|TLname:Calero|TAddress:Lipa, Batangas|TPhone:09123456789|LoadUnit:15Row 3:
Subjectcode:FILIPINO101|Teachercode:BRITER|TFname:Teresa|TLname:Briones|TAddress:Calauan, Laguna|TPhone:09234567890|LoadUnit:15Row 4:
Subjectcode:LANGUAGE101|Teachercode:NUQLYD|TFname:Lydia|TLname:Nuque|TAddress:Tiaong, Quezon|TPhone:09326540987|LoadUnit:15Row 5:
Subjectcode:MAPEH101|Teachercode:ORCMIC|TFname:Michael|TLname:Orcullo|TAddress:Sta. Rosa, Laguna|TPhone:09189638521|LoadUnit:12Row 6:
Subjectcode:READING101|Teachercode:GONLEI|TFname:Leilani|TLname:Gonzales|TAddress:Cabuyao, Laguna|TPhone:09192587410|LoadUnit:15Row 7:
Subjectcode:RELIGION101|Teachercode:TANMEL|TFname:Melissa|TLname:Tan|TAddress:San Pablo City, Laguna|TPhone:09209876521|LoadUnit:9Row 8:
Subjectcode:SCIENCE101|Teachercode:AQULIN|TFname:Linda|TLname:Aquino|TAddress:Candelaria, Quezon|TPhone:09169516985|LoadUnit:15Row 9:
Subjectcode:SIBIKA101|Teachercode:FLOVER|TFname:Vergilio|TLname:Flores|TAddress:San Pablo City, Laguna|TPhone:09063215874|LoadUnit:12
Dataset for student_section Table
Row 1:
Studentnumber:1001|Section:SHS - G8|Room:306Row 2:
Studentnumber:1002|Section:BHS - G8|Room:307Row 3:
Studentnumber:1003|Section:BHS - G8|Room:307Row 4:
Studentnumber:1004|Section:SHS - G8|Room:306Row 5:
Studentnumber:1005|Section:SHS - G8|Room:306Row 6:
Studentnumber:1006|Section:BHS - G8|Room:307Row 7:
Studentnumber:1007|Section:SHS - G8|Room:306
Dataset for subject_profile Table
Row 1:
Subjectcode:ENGLISH101|Subjectdescription:English Communication and Skills|lec units:3Row 2:
Subjectcode:FILIPINO101|Subjectdescription:Panitikan|lec units:3Row 3:
Subjectcode:LANGUAGE101|Subjectdescription:Language|lec units:3Row 4:
Subjectcode:MAPEH101|Subjectdescription:Music, Art, and PE|lec units:3Row 5:
Subjectcode:MATH101|Subjectdescription:Mathematics|lec units:3Row 6:
Subjectcode:READING101|Subjectdescription:Reading Comprehension|lec units:3Row 7:
Subjectcode:SCIENCE101|Subjectdescription:Science and Health|lec units:3Row 8:
Subjectcode:SIBIKA101|Subjectdescription:Sibika at Kultura|lec units:3