Ism Lab File-Compressed

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 59

PRACTICAL FILE

INFORMATION SYSTEMS MANAGEMENT LAB

(Paper Code: BBA-307)

BBA-5th Sem Sec-C 2021-24

GURU GOBIND SINGH INDRAPRASTHA UNIVERSITY

MAHARAJA SURAJMAL INSTITUTE


C-4, Janakpuri, New Delhi-110058

SUBMITTED BY: SUBMITTED TO:


Putul Kumari Dr Itti Hooda
11421201721 Assistant Professor
BBA(V) Sec-C (EVE) BBA Dept.
Index

Date S.No. Title Sign


1 What do you mean by ‘Data’, ‘Information’,’DBMS, RDBMS AND
Database’?
2 Introduction to SQL
3 Performing table operations using SQL (DDL &DML): Creation,
Insertion, Deletion, and Selection
4 To implement various Clauses using SQL Queries
5 Write steps to open MS Access. Write steps to create database. What
are the various elements/objects of a database? What are the various
ways to create tables in a database?
6 What are the steps to create a table in design view and datasheet
view?
7 To implement Arithmetic and Logical Functions
8 To implement Range Selection and Pattern Matching Operations
9 To implement various String Functions
10 Create a table named as STUDENT_MARKS with the following field
as
1. S.No.
2. Name
3. Marks
Execute the following Queries after entering 10 records in the table
1. Display the S.No. of those students whose names start with L
and ends with A or marks less than 70
2. Display the name and S.No. of those students who have scored
marks=95
3. Display the name and marks of all those students who have
scored marks b/w 75&90
4. Arrange the marks of the students in decending order
5. Delete any 2 records from the table
6. Update any new record in the table using update command
11 Create a table student with following fields
Enrollment No., S NAME, Course id, Batch, Semester
Execute the following Queries after entering 10 records in the table
1. Display the list of students in batch “2017-2020”
2. Display the enrollment no. of 4th sem students
3. Dispklay the list of students of batch “2017-2020” and course
is 17
4. Display the no of students in course id 44
12 Create the following table CUSTOMER having the columns , data
types
Customer id, customer name, designation, city, country, salary and
phone no.
Insert the data into table customer and apply the queries
1. Display customer detail having designation sales
representative
2. Retrive customer who is living in Canada
3. Show details of the customer whose name is Victoria
4. Show details of the customer who lives in Sweden
5. Show details of the customer who is owner
6. Display the records of the customer who is living in Canada
and designation is HR
7. Display customer who are either living in Canada or Sweden
8. Sort the salary in ascending order
13 To implement Aggregate Functions:
1. Write an SQL query to calculate the total purchase amount of all
orders. (Return total
purchase amount)
2. Write an SQL query to calculate the average purchase amount of all
orders. (Return
average purchase amount.)
3. From the following table, write an SQL query to compute the sum
of the allotment amount
of all departments. (Return the sum of the allotment amount.)
4. Write an SQL query to count the number of customers. (Return
number of customers.)
5. Write a SQL query to determine the highest purchase amount made
by each salesperson on
'2012-08-17'. (Return salesperson ID, purchase amount.)
6. Write an SQL query to find the highest order (purchase) amount by
each customer on a
particular order date. Filter the result by the highest order (purchase)
amount above
2000.00. (Return customer ID, order date, and maximum purchase
amount.)

14 Create a table employee with the following fields:


Emp_id, Emp_name, Dept_name, Salary, Address, Dob
1. Find the employee ids of the employees having same salary.
2. Find the details of the employee working in the same dept.
Find employee id, emp-name of the employee having same dob.
QUERY1: Find the employee ids of the employees having same
salary.
QUERY2: Find the details of the employee working in the same dept.
QUERY3:Find employee id, emp-name of the employee having same
dob.
15 Create a company database with the following table EMP_DETAILS
with the fields as:
EMP_I
EMP_NAME
EMP_DESIGNATION
And make EMP_ID as the primary key.
Create another table as DEPT_DETAILS with the fields as:
DEPT_ID
DEPT_NAME
DEPT_LOCATION
Also create a table as PROJECTS with fields as:
P_ID
P_NAME
Designate primary key in both the fields.
Establish a relationship between the table EMP-DETAILS AND
DEPT_DETAILS AS 1:1, 1: M and M: 1. Also enforce referential
integrity constraint on it and write down the steps for the same.
16 Create two tables EMPLOYEE and DEPARTMENT with the
following
Fields:
1. EMPLOYEE
• F_NAME
• L_NAME
• E_ID
• DOB
• ADDRESS
• SALARY
2. DEPARTMENT
• D_NO
• D_NAME
• MGR_NO
• MGR-DOJ
Create the forms for the employee as well as the dept table in tabular
form and write the steps to create the forms. Also provide the suitable
title toboth the forms and insert the page no’s to it.
17 Create a table named STUDENT_DETAILS with the following
fields:
• R_no
• Name
• Course name
• Attendance
• Dob
• Add
Course will have values either economics or dbms. Enter 5 records.
Create a form for the above table in the design view. Add text box and
the following buttons to it:
Go to first record
Go to last record
Go to previous record
Go to next record
Add a label student form to it.
18 To implement various data integrity constraints in SQL

Assignment- 1

What do you mean by ‘Data’, ‘Information’,’DBMS, RDBMS AND Database’?

1. Data is any sort of information which is stored in computer memory. This information can
later be used for a website, an application or any other client to store for future purpose. The
most common information is User information in the form of user personal, address and
banking information.

2. Database (DB) are organized, they have a structure, and all the data they store it fits into
that structure. More specifically, a database is an electronic system that allows data to be
stored, easily accessed, manipulated and updated.

3. Information is stimuli that have meaning in some context for its receiver. When
information is entered into and stored in a computer, it is generally referred to as data. After
processing (such as formatting and printing), output data can again be perceived as
information.

4. Database Management System (DBMS) is the software that interacts with end users,
applications, and the database itself to capture and analyze the data. The DBMS software
additionally encompasses the core facilities provided to administer the database. The sum
total of the database, the DBMS and the associated applications can be referred to as a
"database system".

6. Relational Database Management System (RDBMS). RDBMS is the basis for SQL, and
for all modern database systems like MS SQL Server, IBM DB2, Oracle, MySQL, and
Microsoft Access.

A Relational database management system (RDBMS) is a database management system


(DBMS) that is based on the relational model as introduced by E. F. Codd.

Assignment- 2

Introduction to SQL

SQL-(Structured Query Language) is a special-purpose programming language designed for


managing data in relational database management systems (RDBMS).Originally based upon
relational algebra and tuple relational calculus, its scope includes data insert, query, update and
delete, schema creation and modification, and data access control.
What does SQL do?

• SQL can execute queries against a database.


• SQL can retrieve data from a database.
• SQL can insert records in a database.
• SQL can update records in a database.
• SQL can delete records from a database.
• SQL can create new databases.
• SQL can create new tables in a database.
• SQL can create stored procedures in a database.
• SQL can create views in a database.
• SQL can set permissions on tables, procedures, and views.

SQL FEATURES

· Multiple views of data

· Complete database language

· Dynamic data definition

· Client/server architecture

· High-level, English-like structure

SQL LANGUAGE

SQL was one of the first commercial languages for Edgar F. Codd's relational model, as
described in his influential 1970 paper, "A Relational Model of Data for Large Shared Data
Banks. Despite not adhering to the relational model as described by Codd’s it became the most
widely used database language.

Assignment- 3

Performing table operations using SQL (DDL &DML): Creation, Insertion,


Deletion, and Selection

Data Definition Language (DDL)

A data definition language or data description language (DDL) is syntax similar to a


computer programming language for defining data structures, especially database schemas.
Used to create and modify database objects. Create Drop and Alter.

CREATE statement

A CREATE statement in SQL creates an object inside of a relational database management


system (RDBMS). The types of objects that can be created depends on which RDBMS is
being used, but most support the creation of tables, indexes, users, synonyms and databases.
For example, the command to create a table named employees with a few sample columns
would be:

CREATE TABLE employees (

Id INTEGER PRIMARY KEY,

first_name VARCHAR(50) NULL,

last_name VARCHAR(75) NOT NULL,

dateofbirth DATE NULL

);

DROP statements

A DROP statement in SQL removes an object from a relational database management system
(RDBMS). The types of objects that can be dropped depends on which RDBMS is being
used, but most support the dropping of tables, users, and databases. Some systems (such as
Postgre SQL) allow DROP and other DDL commands to occur inside of a transaction and
thus be rolled back.

For example, the command to drop a table named employees would be:

DROP TABLE employees;

ALTER statements

An ALTER statement in SQL changes the properties of an object inside of a relational


database management system (RDBMS). The types of objects that can be altered depends on
which RDBMS is being used.

Data Manipulation Language (DML)

A data manipulation language (DML) is a family of syntax elements similar to a computer


programming language used for inserting, deleting and updating data in a database.
Performing read-only queries of data is sometimes also considered a component of
DML.Data manipulation languages have their functional capability organized by the initial
word in a statement, which is almost always a verb.

SELECT statement

A SELECT statement retrieves zero or more rows from one or more database tables or
database views. In most applications, SELECT is the most commonly used Data
Manipulation Language (DML) command.
INSERT statement

An SQL INSERT statement adds one or more records to any single table in a relational
database.

The number of columns and values must be the same. If a column is not specified, the default
value for the column is used.

Insert statements have the following form:

INSERT INTO table (column1 [, column2, column3 ... ]) VALUES (value1 [, value2, value3
... ])

UPDATE statement

An SQL UPDATE statement changes the data of one or more records in a table. Either all the
rows can be updated, or a subset may be chosen using a condition.

The UPDATE statement has the following form:

UPDATE table_name SET column_name = value [, column_name = value ...] [WHERE


condition]

DELETE statement

In the database structured query language (SQL), the DELETE statement removes one or
more records from a table. A subset may be defined for deletion using a condition, otherwise
all records are removed.

The DELETE statement follows the syntax: DELETE FROM table_name [WHERE
condition];

Assignment- 4

To implement various Clauses using SQL Queries

SQL GROUP BY Statement

The GROUP BY statement is used in conjunction with the aggregate functions to group the
result-set by one or more columns.

Or

The SQL GROUP BY clause can be used in an SQL SELECT statement to collect data across
multiple records and group the results by one or more columns.

SQL GROUP BY Syntax---


SELECT Column_name1, Column_name2 FROM table_name GROUP BY Column_name;

SQL GROUP BY Example

Let us we have to GROUP BY students according to their branch in student table.

SQL HAVING Clause

Having Clause is used in SQL with the GROUP BY statement because the WHERE keyword
could not be used with aggregate functions.

SQL HAVING Syntax

Select Column_name1, …… , Column_name_n from table_name

GROUP BY Column_name HAVING Predicate;

SQL HAVING Example

Let us we have to Group By the students according to Brach from table student having total
marks greater than 150.

Assignment- 5

Write steps to open MS Access. Write steps to create database. What are the various
elements/objects of a database? What are the various ways to create tables in a database?
Steps to open MS- Access:

STEP-1: Click on ‘Windows’.

STEP-2:Click on ‘All Programes’. In ‘All programmes’ click on ‘Microsoft Office’.

STEP-3:Click on ‘MS Access’

STEPS TO CREATE DATABASE

STEP-1: Open MS Access


STEP-2: Select blank database

STEP-3: Enter file name and then click create.

ELEMENTS AND OBJECTS OF DATABASE

i. Table

A table is the primary unit of physical storage for data in a database. When a user accesses
the database, a table is usually referenced for the desired data. Multiple tables might comprise
a database, therefore a relationship might exist between tables. Because tables store data, a
table requires physical storage on the host computer for the database.

Types of table:

• Data tables store most of the data found in a database.

• Join tables are tables used to create a relationship between two tables that would
otherwise be unrelated.

• Subset tables contain a subset of data from a data table.

• Validation tables, often referred to as code tables, are used to validate data entered
into other database tables.
Tables are used to store the data that the user needs to access. Tables might also have
constraints attached to them, which control the data allowed to be entered into the table. An
entity from the business model is eventually converted into a database table.

ii. Columns

A column, or field, is a specific category of information that exists in a table. A column is to


a table what an attribute is to an entity. In other words, when a business model is converted
into a database model, entities become tables and attributes become columns. A column
represents one related part of a table and is the smallest logical structure of storage in a
database. Each column in a table is assigned a data type. The assigned data type determines
what type of values that can populate a column. When visualizing a table, a column is a
vertical structure in the table that contains values for every row of data associated with a
particular column.

iii. Rows

A row of data is the collection of all the columns in a table associated with a single
occurrence. Simply speaking, a row of data is a single record in a table. For example, if there
are 25,000 book titles with which a bookstore deals, there will be 25,000 records, or rows of
data, in the book titles table once the table is populated. The number of rows within the table
will obviously change as books' titles are added and removed. See Figure 3 for an illustration
of a row of data in a table.

iv. Data Types

A data type determines the type of data that can be stored in a database column.

Although many data types are available, three of the most commonly used data types are

• Text

• Alphanumeric/MEMO

• Numeric

• Date and time

Alphanumeric data types are used to store characters, numbers, special characters, or nearly
any combination. If a numeric value is stored in an alphanumeric field, the value is treated as
a character, not a number. In other words, you should not attempt to perform arithmetic
functions on numeric values stored in alphanumeric fields. Design techniques such as this
will be discussed in more detail throughout the book. Numeric data types are used to store
only numeric values. Date and time data types are used to store date and time values, which
widely vary depending on the relational database management system (RDBMS) being used.

VARIOUS WAYS TO CREATE TABLE

There are two ways to create :

(I) Design view


(II) Datasheet view

I. DESIGN VIEW

II. DATASHEET VIEW

Assignment- 6

What are the steps to create a table in design view and datasheet view?

Steps to create database

• Open ms- access

• Select blank database

• Provide 'file name' and then click on create.

DESIGN VIEW

Step 1: Click on ‘View’

Step 2: Select ‘Design View’. The datasheet will open.


Step 3: Enter ‘Field Name’ and ‘Data Type’, as per the data.

DATASHEET VIEW

Step 1: Click on ‘View’

Step 2: Select ‘Datasheet View’. The datasheet will open.

Step 3: Create table on the basis of given data


Assignment- 7

To implement Arithmetic and Logical Functions

SQL Functions.

1. Arithmetic & Logical Function.

Arithmetic & Logical Function include Sum, Multiplication, Division, Round, AND, OR &
NOT. ->Sum: - The SUM () function returns the total sum of a numeric column. SYNTAX--
SELECT SUM(column_name) FROM table_name WHERE condition;

Example---Select SUM(Salary) FROM EMP; Where---EMP is the table name -


>Multiplication: - The Multiplication () function returns the total multiplication of a numeric
column. ->Division: - The Division () function returns the total division of a numeric column.
->Round: - The ROUND () function is used to round a numeric field to the number of
decimals specified. LOGICAL OPERATORS- Returns values in either TRUE or FALSE(0 or
1)

AND :-The AND operator displays result if both the first condition and the second condition
are true.

SELECT column_1, column_2, … column_n

FROM table

WHERE condition_1 AND condition_2 AND condition_n When multiple conditions are
combined using the AND operator, all rows which meet all of the given conditions will be
returned. Now it’s time to apply the AND operator to our gym scenario. Say we wanted to
find all members that are under the age of 50 and live in Los Angeles

SELECT *

FROM members

WHERE Age < 50 AND Location = 'Los Angeles';

Example- SELECT & FROM EMP WHERE Salary = 20,000 AND Empname = ‘AJAY’

OR: - The OR operator displays result if either the first condition or the second condition is
true.

SELECT column_1, column_2, … column_n


FROM table

WHERE condition_1 OR condition_2 OR condition_n When multiple conditions are


combined using the OR operator, all rows which meet any of the given conditions will be
returned.

SELECT *

FROM members

WHERE Location = 'Los Angeles' OR LastName = 'Hanks'

NOT: - The NOT operator displays result when given predicate is not satisfied.

SELECT column_1, column_2, … column_n

FROM table

WHERE NOT condition When multiple conditions are combined using the NOT operator, all
rows which do not meet the given conditions will be returned.

We can use this operator with our gym example in a number of useful ways. What if we
wanted to find all of our members that were outside of Los Angeles? Using the NOT
operator, we can simply write:

SELECT *

FROM members

WHERE NOT Location = 'Los Angeles'

Query Example=

Select round(((Mark1+Mark2)/Mark3)*2) from student;

Or

Select * from student where Mark2>50 AND Mark3>40;

Example- 2

we want to fetch the data for members that fit very specific criteria. We want members who
are:

Over the age of 50.

Located in Los Angeles or Manhattan.

We can accomplish this by writing the following SQL query:

SELECT * FROM members

WHERE AGE > 50 AND (Location='Los Angeles' OR Location='Manhattan')


Assignment- 8

To implement Range Selection and Pattern Matching Operations

Range Searching & Pattern Matching

1. BETWEEN: - The BETWEEN operator selects a range of data between two values. The
BETWEEN operator selects values within a given range. The values can be numbers, text, or
dates. The BETWEEN operator is inclusive: begin and end values are included. BETWEEN
Syntax SELECT column_name(s) FROM table_name WHERE column_name BETWEEN
value1 AND value2; EXAMPLE-- SELECT * FROM Products WHERE Price BETWEEN
10 AND 20;

1. NOT BETWEEN:- The NOT BETWEEN operator selects a range of data not between two
values. 2. SELECT * FROM Products WHERE Price NOT BETWEEN 10 AND 20;

3. LIKE:- The LIKE operator is used to search for a specified pattern in a column.

SELECT & FROM EMP WHERE Ename LIKE ‘A*’;

It will return the name of employee whose name starts with letter A from EMP table

IN:- The IN operator allows you to specify multiple values in a WHERE clause. The IN
operator allows you to specify multiple values in a WHERE clause. The IN operator is a
shorthand for multiple OR conditions. IN Syntax SELECT column_name(s) FROM
table_name WHERE column_name IN (value1, value2, ...); or: SELECT column_name(s)
FROM table_name WHERE column_name IN (SELECT STATEMENT);

4. NOT IN:- It used to search opposite to the WHERE clause value. SELECT * FROM
Customers WHERE Country NOT IN ('Germany', 'France', 'UK');

Query Example

Select * from student where Mark1 BETWEEN 70 AND 80;

Or

Select * from student where Name LIKE ‘R%’;

Or

Select * from student where Name LIKE ‘___am’;

Or

Select * from student where City IN (‘Delhi’, ‘Mumbai’);

Assignment- 9

To implement various String Functions


Introduction:

SQL (Structured Query Language) provides a variety of string functions that allow
manipulation and processing of character data. These functions enable users to perform tasks
such as string concatenation, substring extraction, case conversion, and more.

Objectives:

Implement string concatenation using the CONCAT function.

Use the SUBSTRING function to extract a substring from a given string.

Convert string case using the UPPER and LOWER functions.

Find the length of a string with the LEN function.

Trim leading and trailing spaces using the LTRIM and RTRIM functions.

SQL String Functions:

1. CONCAT Function:

The CONCAT function is used to concatenate two or more strings

SELECT CONTACT(first_name, ‘ ‘, last_name) AS full_name FROM employees;

2. SUBSTRING Function:

The SUBSTRING function extracts a substring from a string.

SELECT SUBSTRING(title, 1, 3) AS short_title FROM books;

3. UPPER and LOWER Functions:

The UPPER function converts a string to uppercase, while the LOWER function converts it
to lowercase.

SELECT UPPER(city) AS capital_city FROM countries;

SELECT LOWER(product_name) AS lowercase_name FROM products;

4. LEN Function:

The LEN function returns the length of a string.

SELECT LEN(description) AS description_length FROM products;

5. LTRIM and RTRIM Functions:

The LTRIM function removes leading spaces, and RTRIM removes trailing spaces from a
string.
SELECT LTRIM(employee_code) AS trimmed_code FROM employees;

SELECT RTRIM(address) AS trimmed_address FROM customers;

Conclusion:

String functions in SQL provide powerful tools for manipulating character data in databases.
Understanding and using these functions efficiently can enhance the capabilities of SQL
queries and make data processing more flexible.

Assignment- 10

Create a table named as STUDENT_MARKS with the following field as


1. S.No.
2. Name
3. Marks

Execute the following Queries after entering 10 records in the table


1. Display the S.No. of those students whose names start with L and ends with A or
marks less than 70
2. Display the name and S.No. of those students who have scored marks=95
3. Display the name and marks of all those students who have scored marks b/w
75&90
4. Arrange the marks of the students in descending order
5. Delete any 2 records from the table
6. Update any new record in the table using update command
Step1: Create table field name and data type

Step2: Create table


Queries:
Display the name and S.No. of those students who have scored marks=95
Syntax:
SELECT s_no FROM student WHERE marks='95';
Output:

Display the name and marks of all those students who have scored marks b/w 75&90
Syntax:
SELECT name,marks FROM student WHERE marks>'75' AND marks<'90';
Output:
Arrange the marks of the students in descending order
Syntax:
SELECT name, marks FROM student ORDER BY marks;
Output:

Delete any 2 records from the table


Syntax:
Delete from student where marks<60
Output:
Update any new record in the table using update command

Syntax:

update student set marks =90 where name= 'olivia';

Output:

Assignment- 11

Create a table student with following fields

Enrollment No., S NAME, Course id, Batch, Semester


Execute the following Queries after entering 10 records in the table
1. Display the list of students in batch “2017-2020”
2. Display the enrollment no. of 4th sem students
3. Dispklay the list of students of batch “2017-2020” and course is 17
4. Display the no of students in course id 44
Step1: Create field name and data types

Step2: Create table

Step3: Go to qury wizard, select ‘Simple query wizard’ and click next.

Step4: Click next and then finish to modify the table.


Queries:
To Display the list of students in batch “2017-2020”
Syntax:
SELECT *FROM Student where batch='2017-20';
Output:
To Display the enrollment no. of 4th sem students
Syntax:
SELECT Enrollment_no FROM Student where semester='4';
Output:

To Display the list of students of batch “2017-2020” and course is 17


Syntax:
SELECT *FROM Student where batch='2017-20' and course_id='17'
Output:
To Display the no of students in course id 44
Syntax:
SELECT count (s_name) FROM Student where course_id='44'
Output:

Assignment- 12

Create the following table CUSTOMER having the columns , data types

Customer id, customer name, designation, city, country, salary and phone no.
Insert the data into table customer and apply the queries
1. Display customer detail having designation sales representative
2. Retrive customer who is living in Canada
3. Show details of the customer whose name is Victoria
4. Show details of the customer who lives in Sweden
5. Show details of the customer who is owner
6. Display the records of the customer who is living in Canada and designation is
HR
7. Display customer who are either living in Canada or Sweden
8. Sort the salary in ascending order
Step1: Create customer table.

Step2: Create query wizard


Queries:
Display customer detail having designation sales representative
Syntax:

Output:

Retrive customer who is living in Canada


Syntax:
Output:
Show details of the customer whose name is Victoria
Syntax:

Oytput:

Show details of the customer who lives in Sweden


Syntax:
Output:

Show details of the customer who is owner


Syntax:
Output:

Display the records of the customer who is living in Canada and designation is HR
Syntax:
Output:

Display customer who are either living in Canada or Sweden


Syntax:
Output:

Sort the salary in ascending order


Syntax:

Output:

Assignment- 13

To implement Aggregate Functions:

1. Write an SQL query to calculate the total purchase amount of all orders. (Return
total

purchase amount)

2. Write an SQL query to calculate the average purchase amount of all orders. (Return
average purchase amount.)

3. From the following table, write an SQL query to compute the sum of the allotment
amount

of all departments. (Return the sum of the allotment amount.)

4. Write an SQL query to count the number of customers. (Return number of


customers.)

5. Write a SQL query to determine the highest purchase amount made by each
salesperson on

&#39;2012-08-17&#39;. (Return salesperson ID, purchase amount.)

6. Write an SQL query to find the highest order (purchase) amount by each customer
on a

particular order date. Filter the result by the highest order (purchase) amount above

2000.00. (Return customer ID, order date, and maximum purchase amount.)

-- 1. Calculate the total purchase amount of all orders.

SELECT SUM(purchase_amount) AS total_purchase_amount

FROM orders;

-- 2. Calculate the average purchase amount of all orders.

SELECT AVG(purchase_amount) AS average_purchase_amount

FROM orders;

-- 3. Compute the sum of the allotment amount of all departments.

SELECT SUM(allotment_amount) AS total_allotment_amount

FROM department;

-- 4. Count the number of customers.

SELECT COUNT(customer_id) AS number_of_customers

FROM customers;
-- 5. Determine the highest purchase amount made by each salesperson on '2012-08-17'.

SELECT salesperson_id, MAX(purchase_amount) AS highest_purchase_amount

FROM orders

WHERE order_date = '2012-08-17'

GROUP BY salesperson_id;

-- 6. Find the highest order (purchase) amount by each customer on a particular order date.

-- Filter the result by the highest order (purchase) amount above 2000.00.

SELECT customer_id, order_date, MAX(purchase_amount) AS max_purchase_amount

FROM orders

GROUP BY customer_id, order_date

HAVING MAX(purchase_amount) > 2000.00;

Assignment- 14

Create a table employee with the following fields:

Emp_id, Emp_name, Dept_name, Salary, Address, Dob

1. Find the employee ids of the employees having the same salary.

2. Find the details of the employee working in the same dept.

Find employee id, emp-name of the employee having same dob.

QUERY1: Find the employee ids of the employees having same salary.

QUERY2: Find the details of the employee working in the same dept.

QUERY3:Find employee id, emp-name of the employee having same dob.


STEP 1: CREATE THE REQUIRED DATABASE.
QUERY1: Find the employee ids of the employees having same salary.
Syntax:

Output:

QUERY2: Find the details of the employee working in the same dept.
Syntax:

Output:
QUERY3: Find employee id, emp-name of the employee having same dob.
Syntax:

Output:

Assignment- 15

Create a company database with the following table EMP_DETAILS with the fields as:

EMP_ID

EMP_NAME

EMP_DESIGNATION

And make EMP_ID as the primary key.

Create another table as DEPT_DETAILS with the fields as:

DEPT_ID

DEPT_NAME

DEPT_LOCATION

Also create a table as PROJECTS with fields as:

P_ID

P_NAME

Designate primary key in both the fields.


Establish a relationship between the table EMP-DETAILS AND DEPT_DETAILS AS
1:1, 1: M and M: 1. Also enforce referential integrity constraint on it and write down
the steps for the same.
➢ EMP_DETAILS

OUTPUT

➢ DEPT_DETAILS

OUTPUT
➢ PROJECTS

OUTPUT

Establishing a relationship between the table EMP-DETAILS AND DEPT_DETAILS


AS 1:1, 1: M and M: 1.
Step 1: Click on ‘Relationship’, in ‘Database Tools’. A new ‘Relationship Tool’ area will
open.
Step 2: Click on ‘Show Table’ in ‘Design’. A dialogue box will open.

Step 3: Select the tables between which the relation has to be shown. Select the table and
click ‘Add’.
Step 4: Click on ‘Edit Relationship’ in ‘Design’. A dialogue box will open. Click on ‘Create
New..’. Another dialogue box will open.

Step 5: Enter ‘Left Table Name’ and ‘Right Table Name’.

Step 6:Select ‘Left Column Name’ and ‘Right Column Name’ and click ‘OK’. The changes
will be made in ‘Edit Relationship’ dialogue box.

Step 7: (For, 1:1 Relation) Click ‘Create’ in Edit Relationship.

Output (1:1 Relation)


(For 1:M Relation): In 1:M case, enter the same Attribute in “DEPT_DETAIL” i.e.,
DEPT_ID. On the other side, enter more than one Attribute in “EMP_DETAIL”. Click on
‘OK’.

OUTPUT (1:M Relation)

(M:1 Relation): Enter the same Attribute in “EMP_DETAIL” i.e., EMP_ID. On the other
side, enter more than one Attribute in “DEP_DETAIL”. Click on ‘OK’
OUTPUT (M:1 Relation)

Assignment- 16

Create two tables EMPLOYEE and DEPARTMENT with the following

Fields:

1. EMPLOYEE

• F_NAME

• L_NAME

• E_ID

• DOB

• ADDRESS

• SALARY

2. DEPARTMENT

• D_NO
• D_NAME

• MGR_NO

• MGR-DOJ

Create the forms for the employee as well as the dept table in tabular form and write
the steps to create the forms. Also provide the suitable title toboth the forms and insert
the page no’s to it.
EMPLOYEE VIEW

DEPARTMENT VIEW

STEPS TO CREATE
FORM ARE-
STEP 1-
STEP 2-
STEP 3-

STEP 4-

STEP 5-
STEP 6-

Assignment- 17

Create a table named

STUDENT_DETAILS with the following fields:

• R_no

• Name

• Course name

• Attendance

• Dob
• Add

Course will have values either economics or dbms. Enter 5 records. Create a form for
the above table in design view. Add text box and the following buttons to it:

Go to first record

Go to last record

Go to previous record

Go to next record

Add a label student form to it.


Step 1: Fill The Required Data In MS ACCESS

Step 2:Now In Create Tab Click On “More Forms” Then “Form Wizard”

Step 3:After That In Form Wizard Select All The Available Fields And Click On Next

Step 4: In The Next Step We Will Select The Layout Of The Form As Tabular
Step 5:After That We Are Required To Select Style Of Our Form

Step 6:Next We Are Required To Give A Title To Our Form In This Case We Will
Give It The Title “STUDENT_DETAILS1”

Step 7: Now We Will Click On “Finish” To Get The Form


Step 8: Then We Will Go To Design View

Step 9:To Add Text BOX We Will Select The Option TextBox And Add The Text Box
Where it Is Required By Clicking On The Location

Step 10: To Add Buttons We Have To Select The Option Buttons And Specify The
Location Where We Want The Button To Be Located by Clicking On The Location
after that a Command Button Wizard Will Appear From Where We Will Select What
Actions We Want The Button To Perform, What Type Of Picutre We Want On The
Button and Lastly We Can Name The Button If We Want To And Then We Will Click
On Finish To Insert Our Button

Step 11:To Add Label Click On The Option “Label “ Then Click Where You Want To
ADD The Label And The ADD The Label

Step 12: Finally Click ON Design View To See Final Output


Assignment-- 18

To implement various data constraints in SQL.


Data Constraints are the rules enforced on data columns on table. These 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
database. Data Constraints could be column level or table level. Column level constraints are
applied only to one column where as table level constraints are applied to the whole table.
Column level constraints: Column level constraints are just imposing on a single column. The
constraints are applied while table creation or modification. Column level constraints cannot
be applied if a constraint spans more than one column in a table.
Table level constraints: Table level constraints applied on more than one column on a table.
These constraints are applied after all the columns of a table defined. These types of constraints
are required when you need to impose constraint on more than one column.
Types of Data Constraints
• PRIMARY KEY
• UNIQUE
• NOT NULL
• CHECK
PRIMARY KEY
The PRIMARY KEY constraint uniquely identifies each record in a database table. Primary
keys must contain unique values. A primary key column cannot contain NULL values. Each
table should have a primary key, and each table can have only one primary key. When primary
key is applied on a single attribute it is called Simple Key and when it is applied on two or
more than two attributes then it is called as Composite Key.
Syntax: At table Level
CREATE TABLE table_name
(column_name1 data_type PRIMARY KEY,
column_name2 data_type ,
column_name3 data_type,
....
);
E.g. If the values of primary key is duplicated or null error will be shown as shown in example
below of table “College”.

Ø UNIQUE
A UNIQUE key integrity constraint requires that every value in a column or set of columns
(key) be unique-that is, no two rows of a table have duplicate values in a specified column or
set of columns.Unique Key constraint is same as primary key i.e. it does not accept duplicate
values, except the following differences. There can be only one Primary key per table.
Whereas, you can have as many Unique Keys per table as you want. Primary key does not
accept NULL values whereas; unique key columns can be left blank.

Syntax: At table Level

CREATE TABLE table_name


(column_name1 data_type,
column_name2 data_type UNIQUE,
column_name3 data_type,
....
);

Ø Not Null Integrity Constraint

By default all columns in a table can contain null values. If you want to ensure that a column
must always have a value, i.e. it should not be left blank, then define a NOT NULL constraint
on it.
The NOT NULL constraint enforces a field to always contain a value. This means that you
cannot insert a new record, or update a record without adding a value to this field.

Syntax: At table Level

CREATE TABLE table_name


(column_name1 data_type,
column_name2 data_type NOT NULL,
column_name3 data_type,
....
);

E.g. The column to that we apply NOT NULL constraints the value cannot be null if the
value entered is null the error will shown as shown in example below of Table “College”.
Ø Check Constraint
Check constraint is used to validate values entered into a column. CHECK constraints enforce
domain integrity by limiting the values that are accepted by a column.
CHECK constraints determine the valid values from a logical expression that is not based on
data in another column. For example, it is possible to limit the range of values for a salary
column by creating a CHECK constraint that allows only data that ranges from 15,000 through
500, 00. This prevents salaries from being entered beyond the normal salary range.
You can create a CHECK constraint with any logical (Boolean) expression that returns TRUE
or FALSE based on the logical operators.

Syntax: At table Level


CREATE TABLE table_name
(column_name1 data_type,
column_name2 data_type CHECK (Predicate),
column_name3 data_type,
....
);

E.g. If the CHECK Predicate is not satisfies the error will be shown as shown in example of
table “College”.

You might also like