Professional Documents
Culture Documents
Dbms Question Bank Ans
Dbms Question Bank Ans
Database systems include complex data structures. In terms of retrieval of data, reduce complexity
in terms of usability of users and in order to make the system efficient, developers use levels of
abstraction that hide irrelevant details from the users. Levels of abstraction simplify database
design.
Mainly there are three levels of abstraction for DBMS, which are as follows –
It is the lowest level of abstraction for DBMS which defines how the data is actually stored, it defines
data-structures to store data and access methods used by the database. Actually, it is decided by
developers or database application programmers how to store the data in the database.So, overall,
the entire database is described in this level that is physical or internal level. It is a very complex
level to understand. For example, customer's information is stored in tables and data is stored in the
form of blocks of storage such as bytes, gigabytes etc.
Logical level is the intermediate level or next higher level. It describes what data is stored in the
database and what relationship exists among those data. It tries to describe the entire or whole data
because it describes what tables to be created and what are the links among those tables that are
created.It is less complex than the physical level. Logical level is used by developers or database
administrators (DBA). So, overall, the logical level contains tables (fields and attributes) and
relationships among table attributes.
It is the highest level. In view level, there are different levels of views and every view only defines a
part of the entire data. It also simplifies interaction with the user and it provides many views or
multiple views of the same database.View level can be used by all users (all levels' users). This level
is the least complex and easy to understand.For example, a user can interact with a system using
GUI that is view level and can enter details at GUI or screen and the user does not know how data is
stored and what data is stored, this detail is hidden from the user.
• The details of Library is store into the Library tablesrespective with all tables
• Each entity (Branch, Students, Managers, Books, Library) contains primary key and unique keys.
• The entity Students, Managers has binded with Library, Books entities with foreign key.There is
one-to-one and one-to-many relationships available between Managers, Issues, Branch, Library
• All the entities Library, Managers, Students, Branch are normalized and reduce duplicacy of
records
• We have implemented indexing on each tables of College Management System tables for fast
query execution.
Count()
Sum()
Avg()
Min()
Max()
COUNT() Function
Syntax:
COUNT(*)
Or
COUNT([ALLIDISTINCT] expression)
Example:
We will use the 'products' table from the sample database for our demonstration.
SELECT COUNT(product_id)
FROM Products;
Ans :-
SUM() Function
Example:
The following SQL statement finds the sum of the "unit price" fields in the "products" table:
SELECT SUM(unit_price)
FROM products;
AVG() Function
Syntax:
Example:
SELECT AVG(quantity_in_stock)
FROM Products;
Ans:-
MIN() Function
The MIN() aggregate function returns the lowest value (minimum) in a set of non-NULL values.
Syntax:
Example:
SELECT MIN(quantity_in_stock)
FROM products;
Ans:-
MAX() Function
The MAX() aggregate function returns the highest value (maximum) in a set of non-NULL values.
Syntax:
Example:
The code depicted below will give us the maximum quantity in stock in the products table.
SELECT MAX(quantity_in_stock)
FROM products;
Ans:- 6
CHAR()
This function returns the character based on the ASCII code. It takes a numeric value as an argument
and returns the character.
ASCII()
ASCII (American Standard Code for Information Interchange) is a code that uses numbers to
represent characters. This function returns the ASCII value for the specific character. To get the ASCII
code of a character, we can call the ASCII() function. It takes a character as an argument and returns
the ASCII code of the character.
LEFT()
This function is used to get a number of characters from a string starting from left. This function
takes two arguments. The first argument specifies the original string and the second argument
specifies the number of characters from the most-left.
For example: SELECT LEFT('Amit Mohanty’ , 4) AS [Name];
LEN()
This function returns the length of a string. This function takes one argument as the string to be
considered.
the database and its objects. The syntax of DDL commands is predefined for describing the data.
The commands of Data Definition Language deal with how the data should exist in the database.
1. CREATE Command :- CREATE is a DDL command used to create databases, tables, triggers
and other database objects. ( ex - Create Database Books;)
2. DROP Command :- DROP is a DDL command used to delete/remove the database objects
from the SQL database. We can easily remove the entire table, view, or index from the
database using this DDL command. (ex - DROP DATABASE Database_Name;)
3. . ALTER Command :- ALTER is a DDL command which changes or modifies the existing
structure of the database, and it also changes the schema of database objects.We can also
add and drop constraints of the table using the ALTER command. ( ex - ALTER
TABLE name_of_table ADD column_name column_definition;)
4. TRUNCATE Command :- TRUNCATE is another DDL command which deletes or removes all
the records from the table.This command also removes the space allocated for storing the
table records. ( ex - TRUNCATE TABLE Student;)
5. RENAME Command :- RENAME is a DDL command which is used to change the name of the
database table. ( ex - RENAME TABLE Old_Table_Name TO New_Table_Name;)
1. SELECT command :- SELECT is the most important data manipulation command in Structured
Query Language. The SELECT command shows the records of the specified table. It also
shows the particular record of a particular column by using the WHERE clause.
(For Ex:-
3. UPDATE Command :- UPDATE is another most important data manipulation command in
Structured Query Language,which allows users to update or modify the existing data in
database tables.
4. Delete command:- DELETE is a DML command which allows SQL users to remove single or
multiple existing records from the database tables.This command of Data Manipulation
Language does not delete the stored data permanently from the database. We use the
WHERE clause with the DELETE command to select specific rows from the table.
Syntax:- DELETE FROM Table_Name WHERE condition;