0% found this document useful (0 votes)
41 views

DBMS File Practical Shail

The document contains details about a database management system session for the year 2019-2020. It includes a table with 6 programs/topics to be covered during the session, including using Oracle software, creating tables with different fields and data types, adding constraints to tables, inserting, deleting and modifying records, modifying tables using the ALTER command, and using SELECT statements with various clauses. The document was submitted by a student to the CSE department for the session.

Uploaded by

NK
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
41 views

DBMS File Practical Shail

The document contains details about a database management system session for the year 2019-2020. It includes a table with 6 programs/topics to be covered during the session, including using Oracle software, creating tables with different fields and data types, adding constraints to tables, inserting, deleting and modifying records, modifying tables using the ALTER command, and using SELECT statements with various clauses. The document was submitted by a student to the CSE department for the session.

Uploaded by

NK
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 21

Data Base Management System

Session: 2019-2020

Submitted by: Submitted to:


Sarvan Barnawal Seema Yodha
182014 CSE Department
CSE 4th Sem
SR.NO. PROGRAMS/TOPICS DATE SIGNATURE

1. Use oracle software and


login with valid user ID and
password. Explore its GUI
and practice some basic
commands
of it.
2. WAP to create a table
having different fields and
datatypes.

3. WAP to create a table


with different types of
constraints.

4. WAP to insert, delete


and modify record
from the table.

5. WAP to modify the table


using Alter command.

6. WAP to explore Select


statement using various
clauses like where ,order
by, group by, having and
aggregate
functions.
PROGRAM:-1
Aim:-Use oracle software and login with valid user id and
password. Explore its GUI and practice some basic commands of
it.

❖ Steps to install MySQL:-


● If you are connecting to the internet while installing MySQL, you can choose the
online installation version mysql-installer-web-community-<version>.exe .

● In case you want to install MySQL offline, you can download the mysql-installer-
community-<version>.exe file.

Install MySQL via MySQL Installer:-

To install MySQL using the MySQL installer, double-click on the MySQL installer file
and follow the steps below:

Step 1: Windows configures MySQL Installer.


Step 2 – Welcome Screen: A welcome screen provides several options. Choose the first
option: Install MySQL Products.

Step 3 – Download the latest MySQL products: MySQL installer checks and
downloads the latest MySQL products including MySQL server, MySQL Workbench,
etc.
Step 4: Click the Next button to continue.

Step 5 – Choosing a Setup Type: there are several setup types available. Choose the
Full option to install all MySQL products and features.
Step 6 : Checking Requirements.

Step 7 – Installation Progress: MySQL Installer downloads all selected products. It will
take a while, depending on which products you selected and the speed of your internet
connection.
Step 7.1 – Installation Progress: Complete Downloading. Click the Next button to continue…

Step 8: Configuration Overview. Click the Next button to configure MySQL


Database Server.
Step 9 – MySQL Server Configuration: choose Config Type and MySQL port (3006 by
default) and click Next button to continue.

Step 9.1: MySQL Server Configuration: choose Windows service details including
Windows Service Name and account type, then click Next button to continue.
Step 10: Configuration Overview: MySQL Installer installs sample databases and
sample models.

Installation Completed: The installation completes. Click the Finish button to close the
installation wizard and launch the MySQL Workbench.
PROGRAM:
-2
AIM:- WAP to create a table having different fields
and datatypes.
CREATE DATABASE

A Database is defined as a structured set of data. So, in SQL the very first step to store
the data in a well-structured manner is to create a database. The CREATE
DATABASE statement is used to create a new database in SQL.

Syntax:

CREATE DATABASE database_name;

database_name: name of the database.

Example Query:
This query will create a new database in SQL and name the database as sin;

CREATE DATABASE sin;

CREATE TABLE
We have learned above about creating databases. Now to store the data we need a table
to do that. The CREATE TABLE statement is used to create a table in SQL. We know
that a table comprises of rows and columns. So while creating tables we have to provide
all the information to SQL about the names of the columns, type of data to be stored in
columns, size of the data etc. Let us now dive into details on how to use CREATE
TABLE statement to create tables in SQL.

Syntax:

CREATE TABLE
table_name
( column1
data_type(size),
column2
data_type(size),
column3
data_type(size),
....
);
table_name: name of the table.
column1 name of the first column.
data_type: Type of data we want to store in the particular column. For example, int for
integer data.
size: Size of the data we can store in a particular column. For example if for a column
we specify the data_type as int
and size as 10 then this column can store an integer number of maximum 10 digits.
Example Query:
PROGRAM:
3
AIM:-WAP to create a table with different types of constraints.

CONSTRAINTS:-

Constraints can be specified when the table is created with the CREATE TABLE
statement, or after the table is created with the ALTER TABLE statement.

Syntax
CREATETABLEtable_
name ( column1
datatypeconstraint,
column2
datatypeconstraint,
column3
datatypeconstraint,
....
);

SQL Constraints

SQL constraints are used to specify rules for the data in a table.
Constraints are used to limit the type of data that can go into a table. This
ensures the accuracy and reliability of the data in the table. If there is any
violation between the constraint and the data action, the action is aborted.
Constraints can be column level or table level. Column level constraints
apply to a column, and table level constraints apply to the whole table.

The following constraints are commonly used in SQL:

NOT NULL - Ensures that a column cannot have a NULL value


UNIQUE - Ensures that all values in a column are different
PRIMARY KEY - A combination of a NOT NULL and UNIQUE. Uniquely
identifies each row in a table
FOREIGN KEY - Uniquely identifies a row/record in another table
CHECK - Ensures that all values in a column satisfies a specific condition
DEFAULT - Sets a default value for a column when no value is specified
INDEX - Used to create and retrieve data from the database very quickly

SQL NOT NULL Constraint

By default, a column can hold NULL values.

The NOT NULL constraint enforces a column to NOT accept NULL values.

This enforces a field to always contain a value, which means that you cannot insert
a new record, or update a record without adding a value to this field.
SQL NOT NULL on CREATE TABLE

The following SQL ensures that the "ID", "LastName", and "FirstName" columns will
NOT accept NULL values when the "Persons" table is created:

Example

SQL NOT NULL on ALTER TABLE

To create a NOT NULL constraint on the "Age" column when the "Persons" table is
already created, use the following SQL:

SQL UNIQUE Constraint

The UNIQUE constraint ensures that all values in a column are different.

Both the UNIQUE and PRIMARY KEY constraints provide a guarantee for
uniqueness for a column or set of columns.

However, you can have many UNIQUE constraints per table, but only one PRIMARY
KEY constraint per table.
SQL PRIMARY KEY Constraint

The PRIMARY KEY constraint uniquely identifies each record in a


table. Primary keys must contain UNIQUE values, and cannot contain
NULL values.
A table can have only ONE primary key; and in the table, this primary key can
consist of single or multiple columns (fields).

SQL FOREIGN KEY Constraint


A FOREIGN KEY is a key used to link two tables together.
A FOREIGN KEY is a field (or collection of fields) in one table that refers to the
PRIMARY KEY in another table.
The table containing the foreign key is called the child table, and the table
containing the candidate key is called the referenced or parent table.
SQL FOREIGN KEY on CREATE TABLE

The following SQL creates a FOREIGN KEY on the "ID" column when the "Orders" table is
created:

SQL CHECK Constraint


The CHECK constraint is used to limit the value range that can be placed in a column.
If you define a CHECK constraint on a single column it allows only certain values
for this column.
If you define a CHECK constraint on a table it can limit the values in certain columns
based on values in other columns in the row.

SQL DEFAULT Constraint


The DEFAULT constraint is used to provide a default value for a column.
The default value will be added to all new records IF no other value is specified.

SQL CREATE INDEX Statement


The CREATE INDEX statement is used to create indexes in tables.
Indexes are used to retrieve data from the database more quickly than otherwise. The
users cannot see the indexes, they are just used to speed up searches/queries.
P
ROGRAM: 4
AIM:- WAP to insert, delete and modify record from the table.
INSERT INTO:-

This statement is used to insert new records into the table.

Syntax
INSERT INTO TableName (Column1, Column2, Column3,
...,ColumnN) VALUES (value1, value2, value3, ...);
--If you don't want to mention the column names then use the below

syntax INSERT INTO TableName

VALUES (Value1, Value2, Value3, ...);

UPDATE

This statement is used to modify the records already present in the table.

Syntax
UPDATE TableName
SET Column1 = Value1, Column2 =
Value2, ... WHERE Condition;

DELETE

This statement is used to delete the existing records in a table.


Syntax
DELETE FROM TableName WHERE Condition;

Example Query:
PROGRAM:
5
AIM:- WAP to modify the table using Alter command.
ALTER:-

This command is used to delete, modify or add constraints or columns in an existing table.

The ‘ALTER TABLE’ Statement

This statement is used to add, delete, modify columns in an existing table.

The ‘ALTER TABLE’ Statement with ADD/DROP COLUMN

You can use the ALTER TABLE statement with ADD/DROP Column command
according to your need. If you wish to add a column, then you will use the ADD
command, and if you wish to delete a column, then you will use the DROP COLUMN
command.

Syntax
ALTER TABLE
TableName ADD
ColumnName Datatype;

ALTER TABLE
TableName DROP
COLUMN ColumnName;

Example Query:

The ‘ALTER TABLE’ Statement with ALTER/MODIFY COLUMN

This statement is used to change the datatype of an existing column in a table.


Syntax
ALTER TABLE TableName
ALTER COLUMN ColumnName Datatype;

Example Query:
P
ROGRAM: 6
AIM:- WAP to explore Select statement using various
clauses like where ,order by, group by, having and aggregate
functions.

What is SQL SELECT?

The SELECT statement is used to select a specific set of data from the database. The
data returned by the SELECT statement is stored in a result table called as result set.

SQL SELECT Syntax:


--To select few columns
SELECTColumnName1, ColumnName2, ColumnName(N) FROMTableName;

-- To select complete data from the


table SELECT* FROMTableName;

--To select the top N records from the


table SELECTTOPN * FROMTableName;

Use SELECT with ORDER BY

As we all know that the ORDER BY statementis used to sort the results either in
ascending or descending order. We can use the ORDER BY statement with the
SELECT statement to retrieve specific data in ascending or descending order.

Syntax
SELECTColumnName1, ColumnName2,
ColumnName(N) FROMTableName
ORDERBYColumnName1, ColumnName2, ... ASC|DESC;
Use SELECT with GROUP BY

The GROUP BY statement is used with the SELECT statement to group the result-set
by one or more columns.

Syntax:
SELECTColumnName1, ColumnName2,...,
ColumnName(N) FROMTableName
WHERECondition
GROUPBYColumnNam
e(N)
ORDERBYColumnNam
e(N);

Use SELECT with HAVING clause

The HAVING clause can be used with the SELECT statement to retrieve data based on some
conditions.

Syntax:
SELECTColumnName1, ColumnName2, ColumnName(N)

FROMTableName
WHERECondition
GROUPBYColumnNam
e(N)
HAVINGCondition
ORDERBYColumnNam
e(N);

You might also like