Unit 1. RDBMS 12
Unit 1. RDBMS 12
Summary
File system suffers from Data Redundancy, Data Inconsistency, Data Isolation, Data
Database Management System (DBMS) is a software to create and manage databases. A database is a
collection of tables.
A database constraint is a restriction on the type of data that that can be inserted into the table.
Database schema and database constraints are stored in database Catalog. Whereas the snapshot of
the database at any given time is the database instance.
Relational DBMS (RDBMS) is used to store data in related tables. Rows and columns of a
table are called tuples and attributed respectively. A table is referred to as a relation.
Restrictions on data stored in a RDBMS is applied by use of keys such as Candidate Key,Primary Key,
Composite Primary Key, Foreign Key.
Each column in a table represents a feature (attribute) of a record. Table stores the information for an
entity whereas a row represents a record.
Each row in a table represents a record. A tuple is a collection of attribute values that makes a record
unique.
A tuple is a unique entity whereas attribute values can be duplicate in the table.
A. Multiple choice questions
collection of data or information that can be accessed, updated, and managed (d)
2. Which of the following is not a valid SQL type? (a) float (c) numeric (c) decimal (d) character
3. In DBMS, table is known as _________ and row is known as __________. (a) relation, tuple
4. In any table, the data types describe the kind of _________ that it can contain. (a) table (b)
5. The SQL statement used to select data items from the database is (a) SELECT (b) USE (c)
6. The database can be renamed using __________ SQL statement (a) CREATE DATABASE (b)
7. The syntax used to show all databases is (a) USE DATABASES (b) SELECT DATABASES (c)
8. In a database table the field which uniquely identifies each row in the table is known as
______ (a) primary key (b) unique key (c) composite key (d) foreign key
9. Foreign key is a _______ key in another table. (a) primary (b) unique (c) composite (d)
candidate key
10. The multiple columns that are used as primary key is known as (a) unique key (b)
11. Which of the following key is used to link between two tables (a) primary (b) foreign (c) composite
(d) unique
12. A primary key cannot be (a) Zero (b) foreign key (c) duplicate (d) NULL
known as __________ .
5. Data Definition language is the language which is used to defining the ______of relation.
5. To make a link between two tables, We can use foreign key constraints.
Note: These
systems, suchlimitations haveand
as databases ledcontent
to the development
managementofsystems.
alternative data storage and management
2. Why foreign
Answer: Foreignkeys
keysare
areallowed
allowedtotohave
haveNULL
NULLvalues?
values Explain
becausewith
theyanmight
example.
not always have a matching
value in the referenced table.
Example:
*Orders*
*Customers*
In this example,
"CustomerID" in the
the "CustomerID" fieldHowever,
Customers table. in the Orders
if an table
order isis aplaced
foreign
bykey that references
a customer the created
who hasn't
an account (a "guest" customer), there won't be a matching CustomerID in the Customers table. In this
case, the CustomerID field in the Orders table would be NULL, indicating that there is no associated
customer.
Allowing NULL
relationship values tables
between in foreign keys
might notprovides flexibility in handling such scenarios, where the
always exist.
3. What are the limitations of file system and how that are overcome by DBMS?
Answer: Limitations of File System:
1. *Data Redundancy
ensuring and Duplication*: DBMS stores data in a single place, reducing duplication and
data consistency.
2. *Data Inconsistency*: DBMS enforces data integrity constraints, ensuring data accuracy and
consistency.
3. *Data
access Search and Retrieval*: DBMS provides efficient search and retrieval mechanisms, making data
faster.
4. *DatatoSecurity
logging ensure and
dataIntegrity*: DBMS
integrity and offers robust security features, access control, and transaction
security.
5. *Data
scales Isolation and
horizontally, Scalability*:
ensuring DBMS allows
data availability andconcurrent access, supports large data volumes, and
performance.
- Data Normalization
- Query Language (e.g., SQL)
- Transaction Management
- Concurrency Control
- Backup and Recovery
By overcoming
data compared these limitations,
to traditional DBMS provides a more efficient, secure, and scalable way to manage
file systems.
1. Tables or relations: Define the structure of data storage, including columns (fields) and data types.
2. Relationships: Define how tables are connected, such as one-to-one, one-to-many, or many-to-many
relationships.
3. Indexes: Define how data is indexed for efficient retrieval.
4. Views: Define virtual tables based on queries.
5. Constraints: Define rules for data integrity, such as primary keys, foreign keys, and check constraints.
6. Stored procedures: Define reusable code blocks for performing specific tasks.
Having a well-designed database schema is crucial for:
Schemas
scripts. can be represented visually through entity-relationship diagrams (ERDs) or in code through SQL
5. What is data
Answer:Data redundancy
redundancy and to
refers its the
associated problems?
duplication of data values in a database or file system, where the
same data is stored in multiple places. This can occur due to various reasons like:
- Duplicate records
- Multiple copies of the same data in different tables or files
- Unnormalized data structures
1.
to *Data inconsistency*: Updates to one copy of the data may not be reflected in other copies, leading
inconsistencies.
2. *Data duplication*: Storage space is wasted by storing multiple copies of the same data.
3. *Data updating difficulties*: Updating data in multiple locations can be time-consuming and error-
prone.
4. *Data retrieval complexities*: Retrieving accurate data becomes challenging due to multiple versions.
5. *Data security risks*: Multiple copies of sensitive data increase the risk of unauthorized access.
6. *Data maintenance challenges*: Maintaining data integrity and consistency becomes more difficult.
7. *Performance issues*: Data redundancy can lead to slower query performance and data retrieval.
To avoiddata
ensure these problems,and
consistency data normalization techniques are used to eliminate data redundancy and
efficiency.
6. How data redundancy problem is solved in DBMS?
Answer:In DBMS, data redundancy is solved through:
1. *Data
into Normalization*:
smaller ones. Organizing data into tables and removing duplicates by splitting large tables
2. *First Normal Form (1NF)*: Ensuring each table cell contains a single value.
3. *Second Normal Form (2NF)*: Moving redundant data to a separate table.
4. *Third Normal Form (3NF)*: Removing data that depends on another field's value.
5. *Higher
Fourth Normal
Normal FormForms*:
(4NF), Further
and Fifthnormalization
Normal Formtechniques,
(5NF). like Boyce-Codd Normal Form (BCNF),
By applying
storage these
needs, andtechniques, DBMSretrieval
improving data minimizes data redundancy, ensuring data consistency, reducing
performance.
7. What is
Answer: MYSQL
MySQL is and its features?
a relational database management system (RDBMS) based on structured query
language (SQL) queries ¹ ² ³:
Each data type has its own specific characteristics and uses.
9. Differentiate
Degree between:
and cardinality of a(a)relation
Database state and database schema (b) Primary key and foreign key (c)
-set
Database state:
of values Refers
in the to the actual data stored in the database at a given point in time. It's the current
database.
-relationships,
Database schema: Refers to the
and constraints. It'sstructure or organization
the blueprint or design ofofthe
thedatabase.
database, including table definitions,
-It's
Primary key or
a column (PK):
setAofunique identifier
columns for a record
that uniquely in a table,
identifies ensuring data consistency and uniqueness.
each row.
-relationship
Foreign keybetween
(FK): A field in a table that references the primary key of another table, establishing a
tables.
Example:
In summary:
10.
KeyExplain the terms
(h) Foreign Key (a) Relation (b) Domain (c) Tuple (d) Attribute (e) Degree (f) Cardinality (g) Primary
Answer: Here are the explanations:
(a) Relation:
concept A relation
in relational is a table in a database that contains a set of related data. It's a fundamental
databases.
(b) Domain:
values A domain
for a specific is the set of possible values that an attribute can take. It defines the range of
attribute.
(c) Tuple:
single A tuple
entity is a single row or record in a relation (table). It's a collection of values that represent a
or instance.
(d) Attribute:
feature of theAn attribute is a column or field in a relation (table). It defines a specific characteristic or
data.
(e) Degree: The degree of a relation is the number of attributes (columns) it contains.
(f) Cardinality: The cardinality of a relation is the number of tuples (rows) it contains.
(g) Primary
attribute orKey
a set(PK): A primarythat
of attributes key uniquely
is a unique identifier
identifies fortuple.
each a tuple (row) in a relation. It's a single
(h) Foreign
relation. Key (FK): A aforeign
It establishes key is an
relationship attribute
between twoinrelations.
a relation that references the primary key of another
Example:
- Relation: Students
- Domain: The set of possible values for Age (e.g., 18-25)
- Tuple: A single row representing a student (e.g., John, 20, Computer Science)
- Attribute: Student_ID, Name, Age, Major
- Degree: 4 (four attributes)
- Cardinality: The number of students ( tuples) in the relation
- Primary Key: Student_ID
-relation,
Foreign it's
Key: If another
a Foreign relation "Courses" has an attribute "Student_ID" that references the Students
Key.
1. *Entity Integrity*: Ensures that each row in a table has a unique primary key value.
2. *Referential Integrity*: Ensures that a foreign key value matches a primary key value in another table.
3.
set*Domain Integrity*: Ensures that data values conform to the defined domain (e.g., format, range, or
of values).
4. *Unique Constraint*: Ensures that all values in a column or set of columns are unique.
5. *Check Constraint*: Ensures that data values meet specific conditions or rules (e.g., age > 18).
6. *Not Null Constraint*: Ensures that a column cannot contain null values.
7. *Default Constraint*: Provides a default value for a column when no value is specified.
8. *Primary Key Constraint*: Ensures that a primary key value is unique and not null.
These
reliableintegrity constraints help maintain data consistency, prevent errors, and ensure that data is
and trustworthy.
Chapter
SUMMARY 2. Structured Query Language (SQL)
Currently almost all RDBMS such as MySQL, Oracle, Informix, SQL server, MS Access,
SQL is a open source, interactive, portable, faster query processing, standardized and
SQL is divided into five types like DDL, DML, DQL, TCL and DCL.
DDL (Data Definition Language) includes SQL statements such as, Create table, Alter table
Create command is used to create database and its further objects like Table, View.
DML (Data Manipulation Language) includes SQL statements such as, insert, select,
A table is a collection of rows and columns, where each row is a record and columns
describe the feature of records.
DESCRIBE TABLE statement is used to view the structure of an already existing table
ALTER TABLE statement is used to make changes in the structure of a table like adding,
removing column and changing datatype of column(s). It is also used to apply/remove any
DROP statement is used to remove a database or a table permanently from the database
system.
TRUNCATE statement is used to delete all records from the table but table structure will
exist in database.
INSERT INTO statement is used to insert new records in any existing table
CREATE TABLE statement can also be used to create new table from existing tables/s.
RENAME statement is used to change the name of existing tables of other database
objects.
Views in any database is a special kind of virtual table that is created from one or more
WHERE clause in SQL query is used to enforce condition(s).
DISTINCT clause is used to eliminate repetition and display the values only once.
The BETWEEN operator defines the range of values inclusive of boundary values.
The IN operator selects values that match any value in the given list of values.
ORDER BY clause is used to display the result of a SQL query in ascending or descending
order with respect to specified attribute values. By default, the order is ascending.
LIKE operator is used for pattern matching. % and _ are two wild card characters. The per
cent (%) symbol is used to represent zero or more characters. The underscore (_) symbol is
1.
Which of the following is not a valid aggregate function? (a) COUNT (b) COMPUTE (c) SUM
(d) MAX
2.
DDL stands for (a) Data Describe Language (b) Definition Data Language (c) Data
3.
Which of the following SQL command is used to remove data from table (a) Collapse (b)
4.
The records and structure of a table may be removed or deleted from the database using
which command? (a) Remove (b) Delete (c) Drop (d) Truncate
5.
SQL ___ statement can be used to delete or drop existing databases in a SQL schema. (a)
Create Database (b) Rename Database (c) Drop Database (d) Select Database
6.
Using DROP TABLE command in SQL (a) Drop the table structure (b) Drop the Integrity
7.
Using DROP TABLE command in SQL (a) Drop the table structure (b) Drop the Integrity
8.
TRUNCATE TABLE requires (a) Where Clause (b) Having Clause (c) Both A And B (d) None
of the above
9.
Which of the following clause is used to add a Primary Key constraint after creating table
10. Which of the following clause is used to remove a primary key constraint (a) Delete (b)
11. Which of the following SQL statement is used to give result in sorted order (a) Sort By (b)
12. Commands under DCL are (a) GRANT (b) REVOKE (c) Both A. and B. (d) None of the above
13. The SQL command to retrieve table records is (a) RETRIEVE (b) SELECT (c) CREATE (d)
ALTER
14. Which of the following operator is used for pattern matching in SQL? (a) BETWEEN
operator (b) LIKE operator (c) EXISTS operator (d) None of these
15. Which operator is used to check the absence of data in any column (a) EXISTS operator (b)
5. The _______ command is used to remove all records only from a table.
11. To sort the result of a query in descending order, we can use clause ______
12. To extract unique values from a column, user can use __________ clause.
1.
2. INSERT clauseisisused
ALTER clause usedto
toadd
addaaPrimary
Foreignkey
keyconstraint
constraint.after table is created.
3. DROP command is used to delete the structure of a table from the database.
6. Aggregate functions are used to perform calculations on multiple values and returns a
single value.
8. DML is used to create a new database objects like table and view.
10. The name of any tables once its created and records are inserted cannot be change.
SQL is asupported
widely standard language
by variousfor interacting
database with relational
management databases,
systems and its
like MySQL, commandsMicrosoft
PostgreSQL, and syntax
SQLare
Server, Oracle, and many others.
SQL is andata
analyze essential tool for database administrators, developers, and data analysts to manage and
effectively.
2. SQL
Ans: Statements
SQL areare
statements classified in into
classified how several
many ways?
categories, including:
1. *DDLTRUNCATE.
DROP, (Data Definition Language)*: used to define and modify database structure, e.g., CREATE, ALTER,
2. *DML (Data Manipulation Language)*: used to manipulate data, e.g., INSERT, UPDATE, DELETE.
4. *TCL (Transaction Control Language)*: used to manage transactions, e.g., COMMIT, ROLLBACK,
SAVEPOINT.
5. *DCL (Data Control Language)*: used to control access and permissions, e.g., GRANT, REVOKE.
Note thatway
common sometosources
classify may group SQL statements slightly differently, but these five categories are a
SQL statements.
3. Differentiate
Ans:Here's between
a clear DDL andbetween
differentiation DML? DDL and DML:
In summary:
4. Differentiate
Ans:Here's between
a clear DCL and between
differentiation TCL? DCL and TCL:
In summary:
ALTER:
UPDATE:
In summary:
- ALTER changes the database object's structure ( schema ).
- UPDATE changes the data stored in the table (data manipulation).
Think of ALTER
(changing as renovating the house (changing the structure), and UPDATE as redecorating the house
the contents)!
6. Differentiate
Ans:The DELETEbetween DELETE
and DROP and DROP
commands command
in SQL serve different purposes:
DELETE:
DROP:
In summary:
Think of DELETE
including all filesas
andremoving specific
the folder itself!files from a folder, and DROP as deleting the entire folder,
7. What is
Ans:The createstatement
CREATE statement?is How
a SQLmany database
command usedobjects canabe
to create created
new usingobject,
database this? such as:
1. *Table*: Define a new table with its columns, data types, and constraints.
2. *Index*: Create an index on one or more columns of a table.
3. *View*: Define a virtual table based on a SELECT statement.
4. *Procedure*: Create a stored procedure for encapsulating a set of operations.
5. *Function*: Define a user-defined function for calculations or transformations.
6. *Trigger*: Create a trigger for automatic actions on specific table events.
7. *Database*: Create a new database (depending on the DBMS).
8. *Schema*: Define a new schema (a namespace for database objects).
9. *Sequence*: Create a sequence for generating unique numeric values.
10. *Synonym*: Define an alias for a database object (e.g., a shortcut for a long table name).
The
used,CREATE statement
but it generally variesadepending
follows on the
similar syntax andspecific database management system (DBMS) being
structure.
Note
beingthat the specific syntax may vary slightly depending on the database management system (DBMS)
used.
9. Modify isthe
Ans:Here theBook table
ALTER in previous
TABLE question
statement to addand
theadd
newone
fieldmore new field
Discount Discount
(Numeric) (Numeric).
to the existing Book
table:
```
ALTER TABLE Book
ADD COLUMN Discount NUMERIC;
```
This will add the new column Discount to the Book table, with a numeric data type.
If
canyou want the
modify to specify a default
statement value for the Discount column or add a constraint (e.g., NOT NULL), you
accordingly:
```
ALTER TABLE Book
ADD COLUMN Discount NUMERIC NOT NULL DEFAULT 0;
```
This will add
this field (NOTthe Discount column with a default value of 0 and ensure that a value must be provided for
NULL).
Note
beingthat the specific syntax may vary slightly depending on the database management system (DBMS)
used.
10. ShyamWhat
database. has created
commandoneshould
database name
Shyam beMycontacts
used beforebut he is not
creating theable to create new table in this
table?
Ans:Before creating a table in the Mycontacts database, Shyam needs to switch to that database using
the USE command. The syntax is:
USE Mycontacts;
This command
the current tells the
database fordatabase management
subsequent system to switch to the Mycontacts database, making it
commands.
After executing the USE command, Shyam can create a new table using the CREATE TABLE command.
Example:
```
USE Mycontacts;
CREATE TABLE contacts (
id INT PRIMARY KEY,
name VARCHAR(50),
email VARCHAR(100)
);
```
This will create a new table named "contacts" in the Mycontacts database.
11. Mr.while
Table2 Sachininserting
Agrawalnew
created
row two tablesTable2
in second with Course as Primary
Mr Agrawal is notKey
ableinto
Table1
insertand
newForeign
value inkey
thein
column City. What could be the possible reason for this?
Ans:The possible reason for this issue is that the Foreign Key constraint in Table2 is referencing the
Course column in Table1, and the value being inserted into the City column in Table2 does not have a
matching Course value in Table1.
Foreign
this case,Key constraints
Course ensure
in Table2) data consistency
matches byprimary
a value in the requiringkeythat the value
column in the
(Course foreign key
in Table1). column
If the value(in
doesn't exist in Table1, the insert operation in Table2 will fail.
Alternatively, if thethe
consider removing CityForeign
columnKey
in Table2 is not
constraint dependent
from the City on the Foreign
column Key constraint, he can
in Table2.
Chapter 3. Functions In SQL
SUMMARY
Single Row functions work on a single row of the table and return a single value.
Multiple Row functions work on a set of records as a whole and return a single value.
GROUP BY function is used to group rows of a table that contain the same values in a
specified column.
Join is an operation which is used to combine rows from two or more tables based on one
or more common fields between them.
1. Which of the following is not an example of single row function (a) MATH (b) STRING (c)
2. Which of the following is not an example of multiple row function (a) MAX ( ) (b) MIN ( ) (c)
3. What is the functionality of SQL COUNT? (a) It returns the no of record of table (b) It
returns the no of record of database (c) It returns the no of record of row (d) It returns the
no of record of column
4. Date and Time functions accept date and time value as input and return output as (a)
numeric (b) string (c) Date and Time (d) Any of the above
5. String Functions accept character value as input and return output as (a) either character
or numeric values (b) string values (c) numeric values (d) character values
6. Which of the following is aggregate function in SQL (a) LEFT (b) AVG (c) JOIN (d) LEN
7. The SQL statement Select Round (47.956,-1) from Dual; (a) is illegal in SQL (b) prints a
8. Which of the following SQL operation cannot be performed on relations (a) Union, (b)
9. Which of the following is used to join two tables on equality condition on the common
attribute (a) JOIN with ON clause (b) NATURAL JOIN in FROM clause (c) Any of a or b (d)
NATURAL JOIN
10. What will be the Cartesian product of the two relations having 4 rows and 3 columns for
first relation and 3 rows and 4 columns in second relation. (a) degree 7 cardinality 12 (b)
1. Single row functions are applied on a single ______ and return a single value.
4. MONTH (date) returns the month in ________ form from the date.
6. INSTR (string, substring) returns the position of the _________ of the substring in the given
string.)
7. MID (string, pos, n) returns a substring of size ___ starting from the specified position
8. LTRIM (string) returns the given string after removing ________ white space characters.
9. TRIM (string) returns the given string after removing both ________ and _________ white
space characters.
10. The _________ operation is used to get common tuples from two tables.
C. State True or False
4. INSTR (string, substring) returns 0, if the substring is not present in the string.
5. If n is not specified MID (string, pos, n), it returns the substring from the position 1 till end
of the string.
6. RTRIM (string) returns the given string after removing leading white space characters.
*Aggregate Functions:*
In summary:
- Single row functions process individual rows, returning a result for each row.
- Aggregate functions process groups of rows, returning a single result for the entire group.
Think of single
collections row functions as processing individual items, while aggregate functions process
of items!
2. List theare
Ans:Here single rowcommon
some functions withrow
single example.
functions with examples:
1. *Mathematical functions*
- ABS(-10) returns 10
- SQRT(16) returns 4
- ROUND(3.7) returns 4
- CEIL(3.2) returns 4
- FLOOR(3.8) returns 3
2. *String functions*
- UPPER('hello') returns 'HELLO'
- LOWER('WORLD') returns 'world'
- TRIM(' extra spaces ') returns 'extra spaces'
- LENGTH('hello') returns 5
- CONCAT('hello', 'world') returns 'helloworld'
3. *Date and Time functions*
- NOW() returns the current date and time
- DATE_FORMAT('2022-01-01', '%Y-%m-%d') returns '2022-01-01'
- DAYNAME('2022-01-01') returns 'Saturday'
- HOUR('12:30:00') returns 12
4. *Conversion functions*
- CAST('123' AS INTEGER) returns 123
- CONVERT('2022-01-01', DATE) returns '2022-01-01'
5. *Other functions*
- COALESCE(NULL, 'default') returns 'default'
- NULLIF('value', 'value') returns NULL
- TRIM(): Removes spaces from both the beginning (left) and end (right) of a string.
- Example: TRIM(' extra spaces ') returns 'extra spaces'
- LTRIM(): Removes spaces only from the beginning (left) of a string.
- Example: LTRIM(' extra spaces ') returns 'extra spaces '
- RTRIM(): Removes spaces only from the end (right) of a string.
- Example: RTRIM(' extra spaces ') returns ' extra spaces'
In summary:
1. _NOW()_
- Returns the current date and time.
- Example: NOW() returns '2024-07-28 14:30:00'
2. _CURDATE()_
- Returns the current date.
- Example: CURDATE() returns '2024-07-28'
3. _CURTIME()_
- Returns the current time.
- Example: CURTIME() returns '14:30:00'
4. _DATE()_
- Extracts the date from a datetime value.
- Example: DATE('2024-07-28 14:30:00') returns '2024-07-28'
5. _TIME()_
- Extracts the time from a datetime value.
- Example: TIME('2024-07-28 14:30:00') returns '14:30:00'
6. _DATE_FORMAT()_
- Formats a date in a specified way.
- Example: DATE_FORMAT('2024-07-28', '%Y-%m-%d') returns '2024-07-28'
7. _DAYNAME()_
- Returns the name of the day of the week.
- Example: DAYNAME('2024-07-28') returns 'Saturday'
8. _DAYOFWEEK()_
- Returns the day of the week (1-7).
- Example: DAYOFWEEK('2024-07-28') returns 7
9. _DAYOFMONTH()_
- Returns the day of the month (1-31).
- Example: DAYOFMONTH('2024-07-28') returns 28
10. _YEAR()_, _MONTH()_, _DAY()_
- Extract the year, month, or day from a date.
- Examples:
- YEAR('2024-07-28') returns 2024
- MONTH('2024-07-28') returns 7
- DAY('2024-07-28') returns 28
Note: These examples
management are for
system being illustrative purposes and may vary depending on the specific database
used.
6. What is
Ans:The the difference
NOW() between
and DATE() NOW(
functions both) and
dealDATE( ) function?
with dates, but they serve different purposes:
NOW():
- Returns the current date and time, including hours, minutes, and seconds.
- Example: NOW() returns '2024-07-28 14:30:00'
DATE():
- Returns the current date, without the time component (hours, minutes, and seconds).
- Example: DATE() returns '2024-07-28'
In other words:
Here's a summary:
SUM():
AVG():
| Salary |
| ------ |
| 1000 |
| 2000 |
| 3000 |
| 4000 |
| 5000 |
In this example:
So, SUM()
count adds up all the values, while AVG() calculates the average value by dividing the sum by the
of values.
8. A table
rows Student has
and columns will 4berows and
there 2 column
if we obtain and another table
the Cartesian has 3ofrows
product theseand
two4 tables?
columns. How many
Ans:If we obtain the Cartesian product (also known as the cross product or cross join) of the two tables,
the resulting table will have:
- Rows: 4 (from the first table) x 3 (from the second table) = 12 rows
- Columns: 2 (from the first table) + 4 (from the second table) = 6 columns
So, the resulting table will have 12 rows and 6 columns.
In
in aa new
Cartesian
table product,
with the each row ofcolumns
combined the firstand
table is paired
a larger with each
number row of the second table, resulting
of rows.
9. What will be the output of following SQL functions.
a)Select pow (3,2);
b) Select round (342.9234, 2);
c)Select
d) Selectlength (‘Vocational Education’);
year (‘1978/08/17’), month (‘1978/08/17’), day (‘1978/08/17’), monthname (‘1978/08/17’);
e)Select
Ans:Hereleft
are('Central', 3), of
the outputs right
the('Institute',
given SQL 4), mid ('Vocational', 3, 4), substr ('Education', 3);
functions:
a) Select pow(3,2);
Output: 9 (because 3^2 = 9)
Note
beingthat the exact output may vary slightly depending on the specific database management system
used.
10. Write the SQL functions to perform the following operations.
a)
b) To
To display
display the
the day like “Monday”,
specified number of“Tuesday”,
charactersfrom
fromthe date when
a particular India got
position independence.
of the given string.
c) To display the name of the month in which you were born.
d) To display
Ans:Here are your name
the SQL in capital
functions to letters.
perform the operations:
a) To display the day like "Monday", "Tuesday", from the date when India got independence (August 15,
1947):
```
SELECT DAYNAME('1947-08-15') AS Independence_Day;
```
b) To displayEducation",
"Vocational the specified number
starting of characters
from position 3, from a particular
display position of the given string (e.g.,
4 characters):
```
SELECT MID('Vocational Education', 3, 4) AS Substring;
```
c) To display the name of the month in which you were born (replace '1990-06-21' with your birthdate):
```
SELECT MONTHNAME('1990-06-21') AS Birth_Month;
```
d) To display your name in capital letters (replace 'Your_Name' with your actual name):
```
SELECT UPPER('Your_Name') AS Name_In_Capitals;
```
Note: These
database functions are
management basedbeing
system on MySQL
used. syntax. The exact syntax may vary depending on the
,******************. .*****************.