Loading, please wait ...
Open its course - Database Systems Labs
Advanced DDL and DML By Mukhtiar Zamin
Summary

Summary

4
Teachers with
Mukhtiar Zamin
19
Followers
For Learning
All
Visibility
Security Status
2
Contributions
By Teachers
Notes
  1. Students are auto-evaluated against related topics to ensure they learned it.

In this lab you will learn some advanced usage of few DDL and DML commands.

You will have to learn about the following in this lab: 

  • Insert 
  • Update 
  • Delete 
  • Adding comments on tables 
  • Create database 
  • Create tables 
  • Constraints 
  • Not null constraint 
  • Primary key 
  • Foreign key 
  • Alter table 
  • Drop statements 
  • Truncate table

Lab Tasks for All, By Mukhtiar Zamin

Create the table(s) for your semester project. 

  1. Use Insert command to add single and bulk records to the table. 
  2. Use UPDATE to update values for SINGLE and then multiple columns
  3. Use DELETE command to delete specific records from the table.
  4. Use TRUNCATE and DROP COMMANDS and describe the difference between both.
  5. Write examples from your semester project against each constraints below:
    1. NOT NULL 
    2. UNIQUE
    3. PRIMARY KEY
    4. FOREIGN KEY
    5. CHECK
    6. DEFAULT 
  6. Add one or more columns to a table
  7. Delete existing columns from a table
  8. Modify the data type for existing column 

Advanced Meta Data Queries for All, By Mukhtiar Zamin

Dependencies between Tables

WITH FK_Hierarchy AS (
    SELECT 
        fk.name AS FK_Name,
        OBJECT_NAME(fk.parent_object_id) AS ChildTable,
        c1.name AS ChildColumn,
        OBJECT_NAME(fk.referenced_object_id) AS ParentTable,
        c2.name AS ParentColumn
    FROM sys.foreign_keys fk
    INNER JOIN sys.foreign_key_columns fkc ON fk.object_id = fkc.constraint_object_id
    INNER JOIN sys.columns c1 ON fkc.parent_object_id = c1.object_id AND fkc.parent_column_id = c1.column_id
    INNER JOIN sys.columns c2 ON fkc.referenced_object_id = c2.object_id AND fkc.referenced_column_id = c2.column_id
)
SELECT * FROM FK_Hierarchy
WHERE ParentTable = 'YourTargetTable';

Objects Count and Sizes

-- Object counts
SELECT 
    'Tables' AS ObjectType, COUNT(*) AS Count
FROM sys.tables
UNION ALL
SELECT 
    'Views', COUNT(*) 
FROM sys.views
UNION ALL
SELECT 
    'Stored Procedures', COUNT(*) 
FROM sys.procedures
UNION ALL
SELECT 
    'Functions', COUNT(*) 
FROM sys.objects 
WHERE type IN ('FN', 'IF', 'TF');  -- Scalar, Inline, and Table-valued functions

-- Table storage sizes
SELECT 
    s.name AS SchemaName,
    t.name AS TableName,
    SUM(p.rows) AS [RowCount],
    CAST(SUM(a.total_pages) * 8 / 1024.0 AS DECIMAL(10,2)) AS TotalSpaceMB,
    CAST(SUM(a.used_pages) * 8 / 1024.0 AS DECIMAL(10,2)) AS UsedSpaceMB,
    CAST((SUM(a.total_pages) - SUM(a.used_pages)) * 8 / 1024.0 AS DECIMAL(10,2)) AS UnusedSpaceMB
FROM 
    sys.tables t
    JOIN sys.schemas s ON t.schema_id = s.schema_id
    JOIN sys.indexes i ON t.object_id = i.object_id
    JOIN sys.partitions p ON i.object_id = p.object_id AND i.index_id = p.index_id
    JOIN sys.allocation_units a ON p.partition_id = a.container_id
WHERE 
    i.index_id <= 1  -- clustered index or heap
GROUP BY 
    s.name, t.name
ORDER BY 
    TotalSpaceMB DESC;

×

Advanced DDL and DML Evaluation

To earn PASS status, system is about to evaluate you using multiple choice questions (MCQs) and True/False type questions.

  • CAREFULLY READ THE FOLLOWING INSTRUCTIONS!
  • Make sure you have learned this lecture along with its topics and tutorials.
  • On first evaluation you get 100% marks on correct answer, then on 2nd you get 95% marks and so on.
  • Answer the questions with a gap NOT MORE THAN A MINUTE, Otherwise it will re-start.

I have read above instrucitons and ready for evaluation.
Your's
Status
Not Registered
Teacher
Mukhtiar Zamin
TODO
Please ask your teacher to link related questions for this lecture.
Alert
Your performance monitoring will start when you register in a class of this course.

Questions on

No Linked topics!
Contact Us

support@subexpert.com
Write to Us View Help
Subject Expert Logo

Subject Expert

Learning Experience Platform

Follow Us
Facebook Switch Display Mode Enable Translation
© 2026 - Subject Expert)