Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 15

Ch.

Devilal State Institute of Engineering and


Technology, Panniwala Mota(Sirsa).

PRACTICAL FILE
DATABASE MANAGEMENT SYSTEM

Submitted by:
Ankit Jaiswal (182003)
CSE 4th sem

Submitted to:
Ms. Seema Yodha
Prof. Of CSE
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: ther
e 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.

You might also like