You are on page 1of 12

A

LAB FILE
ON
DBMS (BCST-402)
Submitted
For

Bachelor of Technology (CSE)


At

DBGI Dehradun
(Department of Computer Science)
Dev Bhoomi Institute of Technology, Dehradun
Prepared BY Submitted To
Name: Kajal Mr. Rahul Bhatt
Univ Roll No: 190080101059 Assistant Professor
Year:2nd DBIMS Dehradun
Semester:4th
INDEX
S.NO Practical Name Assigned Submission Remarks Signature
Date Date
How to create the 09/06/2021 16/06/2021
1 database, restore the
database and attach
the database.
How to create the 09/06/2021 16/06/2021
2 table in database.
How to insert the 09/06/2021 16/06/2021
3 data in table.
DELETE ,DROP 11/06/2021 16/06/2021
4 &TRUNCATE

Update operation in the 11/06/2021 16/06/2021


5 database using the where
clause.

10
LAB NO: 01
01

02 Program NO: 01

03 Assigned Date 09/06/2021

04 Submission Date 16/06/2021

Objective: How to create the database , restore the database and attach the
database.
Description:
Here to create database we use syntax CREATE DATABASE database_name.
To restore database from the .bak file,we use the command RESTORE
DATABASE FROM DISK = ‘\’ GO make sure to replace database name with
the name of database you wish to restore. Also replace ‘backupfilepath’ with the
path of your database backup file and ‘BackupFileName’ with the name of your
.bak file. For restoring a specific file from the .bak file, use a command that
resembles the following: RESTORE DATABASE FILE = FROM DISK =’\’ GO,
Replace ‘FileName’ with the name of the file you wwant to restore.
To attach the database first of all create the new database like I created database
named as [Teacher] then come to the object explorer right click on the database
which you have created,select task and click DETACH then after few step the
created database will be detached. Now change the location of detached file from
their original location along with its log file to another drive.
Now to attach the database we use the syntax CREATE
DATABASE[database_name] ON
(FILENAME = ‘location of primary data file’),
(FILENAME = ‘location of secondary data file’),
FOR ATTACH
GO
Code: CREATE DATABASE Student;
RESTORE DATABASE [Student2] FROM DISK = N
‘D:\sql\Student.bak’ WITH FILE = 2, MOVE N ‘Student’ TO N
‘C:\Program Files\Microsoft SQL
Server\MSSQL.MSSQLSERVER\MSSQL\DATA\Student2.mdf’, MOVE
N ‘Student’ TO N ‘C:\Program Files\Microsoft SQL
Server\MSSQL.MSSQLSERVER\MSSQL\DATA\Student2_log,ldf’,
NOUNLOAD, STATS = 5
GO
USE [master]
GO
CREATE DATABASE [Teacher] ON
(FILENAME = N ‘D:\sql\Teacher.mdf’ ),
(FILENAME = N ‘D:\sql\Teacher_log.ldf’ ),
FOR ATTACH
GO

Output:
Create database Restore Attach

STATUS REMARKS SIGNATURE

RUN
LAB NO: 01
01

02 Program NO: 02

03 Assigned Date 09/06/2021

04 Submission Date 16/06/2021

Objective: How to create the table in database.


Description:
To create table in database we use CREATE TABLE table_name
statement .if you want to create table ,you should name the table and
define its column and each columns data type.

Code: CREATE TABLE Student


(
Stud_Id varchar(10),
First_Name varchar(10),
Last_Name varchar(10),
Course varchar(10),
Roll_No varchar(10)
);

Output:
STATUS REMARKS SIGNATURE

RUN
LAB NO: 01
01

02 Program NO: 02

03 Assigned Date 11/06/2021

04 Submission Date 16/06/2021

Objective: How to insert the data in table.


Description:
To insert data in table we use syntax INSERT INTO table_name
VALUES( value1, value2, value3,……valueN); But make sure the
order of the values is in same order as the columns in the table.

Code: INSERT into Student Values( ‘1’,’Kajal’,‘singh1’,‘DBMS’,‘101’);


INSERT into Student Values( ‘2’,’Kajal’, ‘singh2’, ‘DBMS’, ‘102’);
INSERT into Student Values( ‘3’,’Kajal’, ‘singh3’, ‘DBMS’, ‘103’);
INSERT into Student Values( ‘4’,’Kajal’, ‘singh4’, ‘DBMS’, ‘104’);
SELECT*FROM Students;

Output:
STATUS REMARKS SIGNATURE

RUN
LAB NO: 02
01

02 Program NO: 01

03 Assigned Date 11/06/2021

04 Submission Date 16/06/2021

Objective: DELETE ,DROP &TRUNCATE


Description:
For delete selected rows from table we use command DELETE FROM
table_name WHERE condition;
For delete the whole table structure along with data use command DROP
TABLE table_name; so here after drop the table ,the dbo.person will be
disappeared from the table of person database.
For delete entire data from the table use command TRUNCATE TABLE
table_name;
.
Code: INSERT into Person Values( ‘1’,’Kajal’,‘singh1’, ‘Hajipur’);
INSERT into Person Values( ‘2’,’Kajal’, ‘singh2’, ‘Hajipur’);
INSERT into Person Values( ‘3’,’Kajal’, ‘singh3’, ‘Hajipur’);
SELECT*FROM Person;
DELETE FROM Person WHERE Doctor_Id = ‘3’;
DELETE FROM Person WHERE Doctor_Id = ‘2’;
SELECT*FROM Person;
TRUNCATE TABLE person;
SELECT*FROM Person;
DROP TABLE Person;
SELECT*FROM Person;
OUTPUT:
Delete Drop Truncate

STATUS REMARKS SIGNATURE

RUN
LAB NO: 02
01

02 Program NO: 02

03 Assigned Date 11/06/2021

04 Submission Date 16/06/2021

Objective: Update operation in the database using the where clause.

Description: First of all create database then create table in database


then insert the data in table which you have created.
Now for update in existing table we use syntax : UPDATE table_name
SET column1=value1,coulmn2= value2,……WHERE Condition;

Code: INSERT INTO COLLEGE VALUES(‘1’, ‘KAJAL’, ‘SINGH’, ‘20’);


INSERT INTO COLLEGE VALUES(‘2’, ‘KAJAL’, ‘SINGH2’, ‘20’);
INSERT INTO COLLEGE VALUES(‘3’, ‘KAJAL’, ‘SINGH2’, ‘20’);
SELECT*FROM COLLEGE;
UPDATE COLLEGE SET First_Name= ‘AYUSHI’ WHERE
STUD_ID=2;
SELECT*FROM COLLEGE;
Output:
STATUS REMARKS SIGNATURE

RUN

You might also like