0% found this document useful (0 votes)
16 views5 pages

Lab Manual Week03 DBS

The document outlines the learning objectives and tasks for a Database Management System lab focused on Data Definition Language (DDL) commands. It provides instructions on creating, altering, dropping, truncating, and renaming databases and tables using SQL commands. Additionally, it includes specific lab tasks for students to practice these commands in a practical setting.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
16 views5 pages

Lab Manual Week03 DBS

The document outlines the learning objectives and tasks for a Database Management System lab focused on Data Definition Language (DDL) commands. It provides instructions on creating, altering, dropping, truncating, and renaming databases and tables using SQL commands. Additionally, it includes specific lab tasks for students to practice these commands in a practical setting.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

Database Management System Lab (Week3_Spring 2025)

Department of Computer Science

Learning Objectives:
• Learning Data Definition Language
• Implementing DDL commands on our database

DDL commands:

The queries to manage the database, tables and views come under the umbrella of Data Definition Language.

1- Create:

Write the following in query editor.

CREATE DATABASE TestDB_2021_SE_X -- Creates a database with your registration number

Run the query by pressing F5 key or using Execute button:

Remember…!! SQL is not case sensitive.

Are you able to see the database created…???

If no, then right click on Databases and Refresh the services again

We just created our first database. If we expand the database, we


can see multiple options like, Database Diagrams, Tables, Views,
etc.

By expanding the Tables, you can see there is currently no table in our database, so we have to create one in
order to put our data into it.
For this task, write the following into the Query editor.
Remember: Once a query is executed, you should remove or hide it to avoid re-execution.
To comment the previous queries, use the button and to uncomment use this
CREATE table TableName -- Creates a database with your registration number
(
ID int,
FirstName varchar(255),
LastName varchar(255),
Age int,
Gender varchar(255),
)

By executing the above query, you can now see a table in your database with the given table name. Right click
on the table name and click “Select Top 1000 Rows”.

It will show the columns of your table.


Before moving further, let us look into Data Types of SQL server.

2- Drop:
This query is used to remove a table from the database.
Syntax:

DROP TABLE tableName -- Deletes the table from database

This query is also used to delete an entire database


Syntax:

DROP DATABASE databaseName -- Deletes the database

3- Alter:
For any change in the tables, we use Alter command.
Description Query Syntax Example
Add a column in table ALTER Table tableName ADD ALTER Table Student ADD GPA
columnName datatype varchar(255)

Change datatype of column ALTER Table tableName ALTER ALTER Table Students ALTER
column columnName datatype column GPA int

Remove column(s) from the ALTER Table tableName DROP ALTER Table Students DROP
table column columnName column GPA

4- Truncate:
To remove the data from the tables we use Truncate command.
Syntax:

TRUNCATE Table tableName --All the entries from your table will be removed

5- Rename
To change the name of a table we use sp_rename command, which is a Stored Procedure. Stored procedures
are the functions of SQL server. And to execute the stored procedures we use exec before the command.
Syntax:

exec sp_rename tableName, new_tableName --Table will be renamed to the new name
2. Lab Tasks
1. Create database of a company having following tables.

2. Add a Column DependentName into Dependent table.


3. Change the datatype of Supervisor from int to varchar in the employee table.
4. Add a Table Stakeholders (Name, Id, ContractType) in the database.
5. Modify the location length in project table as 70.
6. Rename the table employee as emp.
7. Delete entries from the table Stakeholders and then delete the whole table.

You might also like