You are on page 1of 8

Databases: DML & DDL Statements and Relationships

1. Define the term Foreign key.

Foreign key is a field in one table that is also the primary key in another
table. The purpose of the foreign key is to ensure referential integrity of the
data. In other words, only those values that are supposed to appear in the
database are permitted.

2. Define the term SQL.

Structured Query Language (SQL) commands are used to manage and


manipulate data in a database.

3. Differentiate between DDL and DML language.

A data definition language or data description language (DDL) is a


standard for commands that define the different structures in a database.
DDL statements create, modify, and remove database objects such as tables,
indexes, and users. Common DDL statements are CREATE, ALTER, and
DROP.

A data manipulation language (DML) is a language that enables users to


access and manipulate data in a database. The goal is to provide efficient
human interaction with the system. Select, Insert, Delete and Update
statements are used in DML.

1
Data manipulation involves:
• Retrieval of information from the database- SELECT statement
• Insertion of new information (records) into the database - INSERT
statement
• Deletion of information (records) in the database - DELETE statement
• Modification of information in the database - UPDATE statement

There are two types of DML:

● Procedural: The user specifies what data is needed and how to get it
● Nonprocedural: The user only specifies what data is needed. This is
easier for the user but may not generate code as efficient as that
produced by procedural languages. (SQL- the code is not written)

4. Define the term query.

Query is a database object which is used to retrieve and view information


from one or more tables that meet a specific condition or criteria.

A popular data manipulation language is Structured Query Language


(SQL)

5. What is the purpose of the CREATE statement?

Create statements are used to create tables in a database.


Example: Create table Student
(Admn_no numeric (4) Primary Key,
Stud_Name varchar(20),
Stud_Class varchar(3),
Stud_Addressvarchar(30) ) ;

6. In the given table: store, identify the data types for the various fields and
write an SQL statement to create the table.
item_no item qty rate lastbuy

101 Sharpener 75 10.00 2018-12-15

102 Ball Pen 100 25.00 2019-04-17


0.25

103 Eraser small 60 7.00 2019-03-19

2
104 Eraser Big 50 15.00 2018-12-14

105 Ball Pen 0.5 75 50 2019-05-20

Create table store (


item_no numeric (4) primary key,
item varchar (50),
qty numeric(5),
rate decimal(7,2),
lastbuy date );

7. Write the SQL command to create a table Movie with the following
structure:

Field Data type

Movie_no Integer (5)

Movie_Name Varchar (250)

Date_of_Release Date

Ticket_Rate Decimal

Director Varchar (100)

8. Siddharth is designing a database on products sold in his father’s store,


where he has to design tables to record the details. Suggest ways to :

a) reduce the duplication of records - Primary Key


b) to store the picture of products - Long varbinary datatype
c) to create tables for his store - Create command
d) to retrieve daily sale records of a particular day - Queries
e) to store values 0 or 1 : Boolean datatype

9. What do you mean by sorting data?

Sorting means to arrange the data in either ascending order or descending


order.

3
10. Define the term ‘Referential Integrity’.

Referential integrity is used to maintain accuracy and consistency of data


in a relationship. In Base, data can be linked between two or more tables
with the help of primary key and foreign key constraints.It requires that if a
value of one attribute (column) of a relation (table) references a value of
another attribute (either in the same or a different relation), then the
referenced value must exist

Referential integrity helps to avoid:

● Adding records to a related table if there is no associated record


available in the primary key table.
● Changing values in a primary if any dependent records are present in
the associated table.
● Deleting records from a primary key table if there are any matching
related records available in associated table(s).
The rule states that the DEPT_ID in the Employee table has a matching
valid DEPT_ID in the Department table.
To allow join, the referential integrity rule states that the Primary Key and
Foreign Key have the same data types.

11. What do you mean by relationship? Why do we need to create a


relationship between tables?
A relationship refers to an association or connection between two or more
tables. When you relate two tables, you don't need to enter the same data in
separate tables.
Relationships between tables helps to:
● Save time as there is no need to enter the same data in separate tables.
● Reduce data-entry errors.
● Summarize data from related tables.
You can create a relationship between any two tables by selecting the
Relationships option from the Tools menu.

12. Mention the various ways of creating relationships.

There are three types of relationships which can be created in tables:

● one to one (in this relationship, both the tables must have

4
primary key columns. )

● one to many or many to one (one of the tables must have a


primary key column). It signifies that one column of the primary
key table is associated with all the columns of the associated
table

● many to many (In this relationship, no table has the primary


key column.It signifies that all the columns of the primary key
table are associated with all the columns of the associated table.)

5
Remove the Relationships:The relationships applied on the tables can be
removed also with the help of the Delete option. Right Click on the
relationship thread and select the Delete option.

13. What is data redundancy? How can you avoid redundancy in the tables?
Data redundancy is “duplication of data” in the database. It can be avoided
by designing the tables properly. Each row of table has to be uniquely
identified by the primary key.

14. Mention some advantages and disadvantages of databases.


Advantages:
❖ Controlling Data redundancy
❖ Data can be shared
❖ Data security
❖ Support multi users access
❖ Better organised data helps in decision making.
Disadvantages:
● Increased costs in maintaining the hardware and software.
● Cost of upgrading the files or conversion of files.
● Extremely complex software.
● Frequent upgrades.

6
● Cost of staff training.

Fill in the blanks:

1 The CREATE DDL command is used to create a table.

2 Common DDL statements are: create, alter and drop.

3 The types of languages used for creating and manipulating the data in the
database are DML and DDL.

4 A DDL is a standard for commands that define the different structures in


a database.

5 A DML is a language that enables users to access and manipulate data in a


database.

6 A Select statement is a part of DML involving information retrieval only.

7 A popular data manipulation language is SQL

8 There are three types of Relationships in a table.

9 To create a form you need to select FORM option available under


Database section.

10
One to one relationship Primary key is needed in both
tables.

One to many relationship Primary key is a must in one table.

Many to many relationship No table has Primary key column

7
11 Create the following table for transport details.

t_id transport_ mode transport_ fees

t001 bus 2000.00

t002 supervision 0.00

t003 bus 3000.00

a) Create table transport details


( t_id char (5) primary key,
transport_mode char(25),
transport_fees Decimal (8,2) ) ;

You might also like