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

1) Implement Data Definition Language Statements.

Ans:

DDL Commands & Syntax

DDL-Commands:

In this section, we will cover the following DDL commands as follows.

1. Create

2. Alter

3. drop

1. Create

2. Alter Command
3. Drop table

2) Implement Data Manipulation Statements.


1. Update

2. Select

3. Delete

4. Insert

1. Update Command
2.Select Command

3. Delete Command

4. Insert Command
3) Implement SELECT command with different clauses.
Ans:

The select statement is used to get the required data from the database according to

the conditions, if any. This data is returned in the form of a table.

The basic syntax of the select statement is −

Select column 1, column 2 ... column N

From table name

An example of the select statement is −

<Student>

Query −

Select Student_Name

From Student

This query yields the following result −


Clauses in Select statement

The example of select statement given above is quite simple and not that useful in

practice. So, there are many other clauses associated with select statement that make

it more meaningful. Some of these are −

Where

The where clause is used to filter out data i.e. it returns information that satisfies a

certain condition. For example −

Select Student_Name

From Student

Where Student_Marks >50

This query will return the following result:


Group by

This is mostly used with aggregate functions to group the result set according to the

value of a column. For example −

Select Count (Student_Number), Student_MajorSubject

From Student

Group by Student_MajorSubject

This query will return the following result −

Having

This is used along with Group By clause because Where clause could not be used by

aggregate functions. For Example −

Select Count (Student number), Student_MajorSubject

From Student

Group by Student_MajorSubject

Having Count (Student_Number) > 2

This query will return the following result −


Order by

The order by keyword is used to sort the results in ascending or descending order. By

default, the order is assumed to be ascending. For Example −

Select Student_Name

From Student

Where Student_Marks>50

Order by Student_Marks

This query will return the following result −


4)Implement various type of Integrity Constraints on database.
Ans:

Integrity Constraints

• Integrity constraints are a set of rules. It is used to maintain the quality of information.

• Integrity constraints ensure that the data insertion, updating, and other processes have

• To be performed in such a way that data integrity is not affected.

• Thus, integrity constraint is used to guard against accidental damage to the database.

Types of Integrity Constraint

1. Domain constraints

• Domain constraints can be defined as the definition of a valid set of values for an

• attribute.

• The data type of domain includes string, character, integer, time, date, currency, etc.

• The value of the attribute must be available in the corresponding domain.

2. Entity integrity constraints

• The entity integrity constraint states that primary key value can't be null.

• This is because the primary key value is used to identify individual rows in relation and if the primary
key has a null value, then we can't identify those rows.

• A table can contain a null value other than the primary key field.

3. Referential Integrity Constraints

• A referential integrity constraint is specified between two tables.

• In the Referential integrity constraints, if a foreign key in Table 1 refers to the Primary

• Key of Table 2, then every value of the Foreign Key in Table 1 must be null or be

• available in Table 2.

4. Key constraints
• Keys are the entity set that is used to identify an entity within its entity set uniquely.

• An entity set can have multiple keys, but out of which one key will be the primary key.

• A primary key can contain a unique and null value in the relational table.
5)Implement SINGLE ROW functions (Character, Numeric,

Date functions) and GROUP functions (avg, count, max, min,

sum).
Ans:

SQL Aggregate Functions

o SQL aggregation function is used to perform the calculations on multiple rows of a

single column of a table. It returns a single value.

o It is also used to summarize the data.

Types of SQL Aggregation Function

. COUNT FUNCTION

o COUNT function is used to Count the number of rows in a database table. It can work

on both numeric and non-numeric data types.

o COUNT function uses the COUNT (*) that returns the count of all the rows in a

specified table. COUNT (*) considers duplicate and Null.

Syntax

1. COUNT (*)

2. or

3. COUNT([ALL|DISTINCT] expression)

Sample table:

PRODUCT_MAST

PRODUCT COMPANY QTY RATE COST

Item1 Com1 2 10 20

Item2 Com2 3 25 75

Item3 Com1 2 30 60
following records.

ID NAME AGE ADDRESS SALARY

1 John 20 US 2000.00

2 Stephan 26 Dubai 1500.00

3 David 27 Bangkok 2000.00

4 Alina 29 UK 1625.00

5 Kathrin 34 Bangalore 2125.00

6 Harry 42 China 1125.00

7 Jackson 25 Mizoram 10000.00

4. Subqueries with the DELETE Statement

The subquery of SQL can be used in conjunction with the Delete statement just like

any other statements mentioned above.

Syntax

1. DELETE FROM TABLE_NAME

2. WHERE VALUE OPERATOR

3. (SELECT COLUMN_NAME

4. FROM TABLE_NAME

5. WHERE condition);

Example

Let's assume we have an EMPLOYEE_BKP table available which is backup of

EMPLOYEE table. The given example deletes the records from the EMPLOYEE table

for all EMPLOYEE whose AGE is greater than or equal to 29.

1. DELETE FROM EMPLOYEE

2. WHERE AGE IN (SELECT AGE FROM EMPLOYEE_BKP

3. WHERE AGE >= 29);

You might also like