0% found this document useful (0 votes)
48 views15 pages

Kathmandu University Department of Computer Science and Engineering

The document is a lab report submitted by Nabin Ghimire for the course COMP 232. It contains summaries of SQL (Structured Query Language) including the different types of SQL languages like DDL, DML, DQL. It also describes basic data types in SQL like string, numeric, and date/time data types. The lab work solutions section demonstrates creating databases and tables for a vehicle insurance and school database, inserting values, and writing queries using SQL statements. Screenshots from VS Code are included showing the SQL code and outputs.

Uploaded by

Nabin Ghimire
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)
48 views15 pages

Kathmandu University Department of Computer Science and Engineering

The document is a lab report submitted by Nabin Ghimire for the course COMP 232. It contains summaries of SQL (Structured Query Language) including the different types of SQL languages like DDL, DML, DQL. It also describes basic data types in SQL like string, numeric, and date/time data types. The lab work solutions section demonstrates creating databases and tables for a vehicle insurance and school database, inserting values, and writing queries using SQL statements. Screenshots from VS Code are included showing the SQL code and outputs.

Uploaded by

Nabin Ghimire
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/ 15

Kathmandu University

Department of Computer Science and Engineering


Dhulikhel, Kavre

A Lab Report
on
“Lab 1 and 2”
[Code No: COMP 232]

Submitted by

Nabin Ghimire(17)

Submitted to
Mr. Santosh Khanal
Department of Computer Science and Engineering

Submission Date: 14th Oct 2020


SQL (Structured Query Language)
Introduction:
SQL stands for Structured Query Language which is a medium to
communicate with the Database. SQL statements are used to perform tasks
such as update data on a database, or retrieve data from a database. SQL
can be further classified as:

 Data Defining Language(DDL)

DDL is language used to define data structures and modify the data.

Examples of the DDL are:

CREATE – is used to create the database or its objects (like table,


index, function, views, store procedure and triggers).

DROP – is used to delete objects from the database.

ALTER-is used to alter the structure of the database.

TRUNCATE–is used to remove all records from a table, including


all spaces allocated for the records are removed.

COMMENTS –is used to add comments to the data dictionary.

RENAME–is used to rename an object existing in the database.

 Data Manipulation Language(DML)

The SQL commands that deals with the manipulation of data present
in the database belong to DML or Data Manipulation Language and this
includes most of the SQL statements.

Some Examples of DML:

INSERT – is used to insert data into a table.


UPDATE– is used to update existing data within a table.

DELETE – is used to delete records from a database table.

 Data Query Language(DQL) :


The purpose of DQL Command is to get some schema relation based
on the query passed to it.

Example of DQL:

SELECT – is used to retrieve data from the database.

We also have the other Query languages which can be listed as Figure:

BASIC DATA TYPES:


The data type of a column defines what value the column can hold: integer,
character, money, date and time, binary, and so on.

Various Types of datatypes are:

1. STRING DATATYPES:

Few of the string Datatypes are:

A FIXED length string (can contain letters,


numbers, and special characters). The size
CHAR(SIZE) parameter specifies the column length in
characters - can be from 0 to 255. Default is
1.
A VARIABLE length string (can contain
VARCHAR(SIZE) letters, numbers, and special characters).The
size parameter specifies the maximum
column length in characters - can be from 0
to 65535
Equal to CHAR(), but stores binary byte
BINARY(SIZE) strings. The size parameter specifies the
column length in bytes. Default is 1

2. NUMERIC DATATYPES:

Few of the Numeric Data Types are:

A medium integer. Signed range is from -2147483648 to


INT(size) 2147483647. Unsigned range is from 0 to 4294967295. The
size parameter specifies the maximum display width (which
is 255)

A floating point number. MySQL uses the p value to


determine whether to use FLOAT or DOUBLE for the
FLOAT(p) resulting data type. If p is from 0 to 24, the data type
becomes FLOAT(). If p is from 25 to 53, the data type
becomes DOUBLE()
A normal-size floating point number. The total number of
DOUBLE(size, d) digits is specified in size. The number of digits after the
decimal point is specified in the d parameter
BOOL Zero is considered as false, non-zero values are considered
true.

3. DATE AND TIME DATA TYPES:

Few date and time data types are:

DATE A date. Format: YYYY-MM-DD. The supported range is


from '1000-01-01' to '9999-12-31'
A date and time combination. Format: YYYY-MM-DD
DATETIME(fsp) hh:mm:ss. The supported range is from '1000-01-01 00:00:00'
to '9999-12-31 23:59:59'. Adding DEFAULT and ON
UPDATE in the column definition to get automatic
initialization and updating to the current date and time

SCHEMA IN SQL
A database schema is the skeleton structure that represents the logical view of
the entire database. It defines how the data is organized and how the relations
among them are associated. It formulates all the constraints that are to be applied
on the data.
A database schema defines its entities and the relationship among them. It
contains a descriptive detail of the database, which can be depicted by means of
schema diagrams. It’s the database designers who design the schema to help
programmers understand the database and make it useful.

CREATING THE DATABASE/SCHEMA:

SYNTAX:

CREATE DATABASE/SCHEMA <DATABASE NAME / SCHEMA NAME>

ALTERING THE DATABASE:

SYNTAX:

ALTER DATABASE/SCHEMA DATABASE_NAME/SCHEMA NAME [RENAME TO


NEW DATABASE NAME].
DROP SCHEMA (DATABASE):

SYNTEAX:

DROP SCHEMA <SCHEMA_NAME>

Basic Structure of SQL Query


SQL is based on set and relational operations with certain modification and
enhancement. A typical SQL has the form:

Select/Create/Alter/Drop A1, A2,...An

From r1, r2,...rm

Where,

Ai represents an attribute which a user require,

ri represents a relation or the table

Also, select clause list the attributes desired in the result of query. The From clause
lists the relation involved in a query.

LAB WORKS SOLUTIONS:


We were asked to implement the query of the school and the vehicle database.
We have used the various datatypes and various data languages to create and
maintain a beautiful Database. So I will be posting the important datatypes and
queries taking the screenshot from VS_CODE.

Firstly,

NABIN_VEHICLEINSURANCE:
CREATING THE DATABASE:

CREATE DATABASE nabin_vehicleinsurance;

CREATING THE TABLE:

CREATE TABLE nabin_person(


driver_id VARCHAR(30), -- Here we used the varchar datatype--
name VARCHAR(30),
address VARCHAR(30),
PRIMARY KEY(driver_id) -- It should never be null and unique--
);

DROPPING AND AGAIN INSERTING VALUES:

-- Deleting the table if there is any--

DROP TABLE IF EXISTS nabin_participated;


DROP TABLE IF EXISTS nabin_owns;
DROP TABLE IF EXISTS nabin_car;
DROP TABLE IF EXISTS nabin_person;
DROP TABLE IF EXISTS nabin_accident;

-- Doing same , again craeting the table --


CREATE TABLE nabin_person(
driver_id VARCHAR(30),
name VARCHAR(30),
address VARCHAR(30),
PRIMARY KEY(driver_id)
);

DESCRIBING THE DATABASE:

DESC nabin_person; -- It will show all things inside our database --

INSERTING INTO THE TABLE:

-- inserting the value into my table--


INSERT INTO nabin_person ( driver_id, name, address) VALUES ('51064', 'Alex
andros Tallant', '761 Gulseth Alley');
INSERT INTO nabin_person ( driver_id, name, address) VALUES ('35389', 'Jessal
yn Tripony', '50 Heath Alley');
INSERT INTO nabin_person ( driver_id, name, address) VALUES ('81347', 'Alidi
a Frogley', '924 Rigney Junction');
INSERT INTO nabin_person ( driver_id, name, address) VALUES ('28821', 'Gretn
a Wastie', '937 Veith Terrace');
INSERT INTO nabin_person ( driver_id, name, address) VALUES ('29420', 'Tull
Warrender', '878 Schlimgen Drive');

Other Important Queries:


Fig – 1

Fig - 2
NABIN_SCHOOL:

FIG – SQL QUERY


FIG – SQL QUERY
Fig – SQL QUERY
Fig – SQL QUERY
FIG – SQL QUERY
FIG – SQL QUERY

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy