Вы находитесь на странице: 1из 11

1

1. Explain the uses of data models.


A data model refers to the logical inter-relationships and data flow between different data elements
involved in the information world. It also documents the way data is stored and retrieved. It has the
following main components:
Data types
Data items
Data sources
Event sources
Links

Data models can be represented by an accompanying database diagram. Data models are
represented by the data modeling notation, which is often presented in the graphical format. Their main focus
is to support and aid information systems by showing the format and definition of the different data involved.
They also help prevent data redundancy. Information stored in data models is of great significance for
businesses because it dictates the relationships between database tables, foreign keys and the events involved.

The three basic styles of data model are:

Conceptual data models- High-level, static business structures and concepts. The business key,
attributes and definitions of business data objects. Also shows the relationship between business
data objects. Broader scope than LDM and may cover a subject area (also known as subject area
model).

Physical data models- Entity types, data attributes and relationships between entities. Technical design
e.g. tables, columns, keys, foreign keys and other constraints to be implemented in the data base
or XSD. May be generated from a logical data model. This model is within the scope of a defined
project.

Logical data models- The internal schema database design. Documents the business key, attributes
and definitions of business data objects. It also shows the relationship between business data
objects. Frequently is within the scope of a defined project.

Data models are used for many purposes, from high-level conceptual models to physical data models. Data
modeling explores data-oriented structures and identifies entity types. The purpose of a Data model is to
design a relational database system An ER Model is used to specify design and document
Database design A Data model is a pictorial representation of the structure of a relational
database system it is a description of the objects represented by a computer system
together with their properties and relationships ER Modelling is a Database design method

2. Describe the concurrency management strategies.

Concurrency control is a database management systems (DBMS) concept that is used to address conflicts
with the simultaneous accessing or altering of data that can occur with a multi-user system. concurrency
control, when applied to a DBMS, is meant to coordinate simultaneous transactions while preserving data
integrity. The Concurrency is about to control the multi-user access of Database.
2

Concurrency Management Strategies are as follows:

Pessimistic Locking: This concurrency control strategy involves keeping an entity in a database locked the
entire time it exists in the database's memory. This limits or prevents users from altering the data entity
that is locked. There are two types of locks that fall under the category of pessimistic locking: write lock
and read lock.

With write lock, everyone but the holder of the lock is prevented from reading, updating, or deleting the
entity. With read lock, other users can read the entity, but no one except for the lock holder can update or
delete it.

Optimistic Locking: This strategy can be used when instances of simultaneous transactions, or collisions,
are expected to be infrequent. In contrast with pessimistic locking, optimistic locking doesn't try to
prevent the collisions from occurring. Instead, it aims to detect these collisions and resolve them on the
chance occasions when they occur.

Pessimistic locking provides a guarantee that database changes are made safely. However, it becomes less
viable as the number of simultaneous users or the number of entities involved in a transaction increase
because the potential for having to wait for a lock to release will increase.

Optimistic locking can alleviate the problem of waiting for locks to release, but then users have the
potential to experience collisions when attempting to update the database.

4. Explain different types of database softwares.

A database software is system software for creating and managing databases. The DBMS provides users and
programmers with a systematic way to create, retrieve, update and manage data.

The types of Database software are following:


3

Relational database management system (RDMS) - adaptable to most use cases, but RDBMS Tier-1 products
can be quite expensive.

NoSQL DBMS - well-suited for loosely defined data structures that may evolve over time.

In-memory database management system (IMDBMS) - provides faster response times and better performance.

Columnar database management system (CDBMS) - well-suited for data warehouses that have a large number
of similar data items.

Cloud-based data management system - the cloud service provider is responsible for providing and
maintaining the DBMS.

Some examples of database software are Oracle, FileMaker Pro, Microsoft Access, Microsoft SQL Server,
SAP and MySQL. Database software, also called a database management system or DBMS, is used to store,
retrieve, add, delete and modify data.

7. Describe DDL.

Data Definition 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.

DDL statements are used to build and modify the structure of your tables and other objects in
the database. When you execute a DDL statement, it takes effect immediately.
The create table statement does exactly that:
CREATE TABLE <table name> (
<attribute name 1> <data type 1>,
...
<attribute name n> <data type n>);
The data types that you will use most frequently are character strings, which might be
called VARCHAR or CHAR for variable or fixed length strings; numeric types such as
NUMBER or INTEGER, which will usually specify a precision; and DATE or related types.
Data type syntax is variable from system to system; the only way to be sure is to consult
the documentation for your own software.
The alter table statement may be used as you have seen to specify primary and foreign key
constraints, as well as to make other modifications to the table structure. Key constraints may
also be specified in the CREATE TABLE statement.
ALTER TABLE <table name>
ADD CONSTRAINT <constraint name> PRIMARY KEY (<attribute list>);
You get to specify the constraint name. Get used to following a convention of
tablename_pk (for example, Customers_pk), so you can remember what you did later. The
attribute list contains the one or more attributes that form this PK; if more than one, the
names are separated by commas.
The foreign key constraint is a bit more complicated, since we have to specify both the FK
attributes in this (child) table, and the PK attributes that they link to in the parent table.
ALTER TABLE <table name>
ADD CONSTRAINT <constraint name> FOREIGN KEY (<attribute list>)
4

REFERENCES <parent table name> (<attribute list>);


Name the constraint in the form childtable_parenttable_fk (for example,
Orders_Customers_fk). If there is more than one attribute in the FK, all of them must be
included (with commas between) in both the FK attribute list and the REFERENCES
(parent table) attribute list.
You need a separate foreign key definition for each relationship in which this table is the
child.
If you totally mess things up and want to start over, you can always get rid of any object youve
created with a drop statement. The syntax is different for tables and constraints.
DROP TABLE <table name>;

ALTER TABLE <table name>


DROP CONSTRAINT <constraint name>;
This is where consistent constraint naming comes in handy, so you can just remember the
PK or FK name rather than remembering the syntax for looking up the names in another
table. The DROP TABLE statement gets rid of its own PK constraint, but wont work until
you separately drop any FK constraints (or child tables) that refer to this one. It also gets
rid of all data that was contained in the tableand it doesn't even ask you if you really
want to do this!
All of the information about objects in your schema is contained, not surprisingly, in a set of
tables that is called the data dictionary. There are hundreds of these tables most database
systems, but all of them will allow you to see information about your own tables, in many cases
with a graphical interface. How you do this is entirely system-dependent.

8. Explain the aspects to consider for database security.

Database security concerns the use of a broad range of information security controls to protect
databases (potentially including the data, the database applications or stored functions, the
database systems, the database servers and the associated network links) against compromises of
their confidentiality, integrity and availability. It involves various types or categories of controls,
such as technical, procedural/administrative and physical.

Many aspects to consider for database security include the following:

Legal issues

Physical security

OS/Network security

Security policies and protocols

Encryption and passwords

Database security can be defined as a system or process by which the "Confidentiality, Integrity, and
Availability," or CIA, of the database can be protected. Unauthorized entry or access to a database server
signifies a loss of confidentiality; unauthorized alteration to the available data signifies loss of integrity;
5

and lack of access to database services signifies loss of availability. Loss of one or more of these basic
facets will have a significant impact on the security of the database.

Databases have been largely secured against hackers through network security measures such as firewalls, and
network-based intrusion detection systems. While network security controls remain valuable in this regard,
securing the database systems themselves, and the programs/functions and data within them, has arguably
become more critical as networks are increasingly opened to wider access, in particular access from the
Internet. Furthermore, system, program, function and data access controls, along with the associated user
identification, authentication and rights management functions, have always been important to limit and in
some cases log the activities of authorized users and administrators.

9. Explain Hierarchical model in detail.


The hierarchical data model organizes data in a tree structure. There is a hierarchy of parent and child data
segments. This structure implies that a record can have repeating information, generally in the child data
segments. Data in a series of records, which have a set of field values attached to it. It collects all the
instances of a specific record together as a record type. These record types are the equivalent of tables in
the relational model, and with the individual records being the equivalent of rows.
To create links between these record types, the hierarchical model uses Parent Child Relationships. These
are a 1:N mapping between record types. This is done by using trees, like set theory used in the relational
model, "borrowed" from maths. For example, an organization might store information about an employee,
such as name, employee number, department, salary.
The organization might also store information about an employee's children, such as name and date of
birth. The employee and children data forms a hierarchy, where the employee data represents the parent
segment and the children data represents the child segment. If an employee has three children, then there
would be three child segments associated with one employee segment. In a hierarchical database the
parent-child relationship is one to many. This restricts a child segment to having only one parent segment.

In this data model, the entities are represented in a hierarchical fashion. Here we identify a parent entity,
and its child entity. Again we drill down to identify next level of child entity and so on. This model can be
imagined as folders inside a folder!
6

In our example above, it is diagrammatically represented as below:

It can also be imagined as


root like structure. This model will have only one main root. It then branches into sub-roots, each of
which will branch again. This type of relationship is best defined for 1:N type of relationships. E.g.; One
company has multiple departments (1:N), one company has multiple suppliers (1:N),one department has
multiple employees (1:N), each department has multiple projects(1:N) . If we have M:N relationships,
then we have to duplicate the entities and show it in the diagram. For example, if a project in the company
involves multiple departments, then our hierarchical representation changes as below:

13. Explain database integrity constraint with example


Integrity constraints are used to ensure accuracy and consistency of data in a relational database. Data integrity is handled
in a relational database through the concept of referential integrity. Many types of integrity constraints play a role in
referential integrity (RI).

Primary Key Constraints- Primary key is the term used to identify one or more columns
in a table that make a row of data unique. Although the primary key typically consists of one
column in a table, more than one column can comprise the primary key. The primary key is
assigned at table creation. The following example identifies the EMP_ID column as the PRIMARY
KEY for the EMPLOYEES table:

CREATE TABLE EMPLOYEE_TBL

(EMP_ID CHAR(9) NOT NULL PRIMARY KEY,

EMP_NAME VARCHAR (40) NOT NULL,

EMP_ST_ADDR VARCHAR (20) NOT NULL,


7

EMP_CITY VARCHAR (15) NOT NULL,

EMP_PAGER INTEGER(10) NULL);

Unique Constraints - A unique column constraint in a table is similar to a primary key in that the value
in that column for every row of data in the table must have a unique value. Although a primary key
constraint is placed on one column, you can place a unique constraint on another column even though it is
not actually for use as the primary key.
Study the following example:
CREATE TABLE EMPLOYEE_TBL
(EMP_ID CHAR(9) NOT NULL PRIMARY KEY,
EMP_NAME VARCHAR (40) NOT NULL,
EMP_ST_ADDR VARCHAR (20) NOT NULL,
EMP_CITY VARCHAR (15) NOT NULL,
EMP_PHONE INTEGER(10) NULL UNIQUE,
EMP_PAGER INTEGER(10) NULL);
Foreign Key Constraints - A foreign key is a column in a child table that references a primary key in the
parent table. A foreign key constraint is the main mechanism used to enforce referential integrity between
tables in a relational database. A column defined as a foreign key is used to reference a column defined as
a primary key in another table.

Study the creation of the foreign key in the following example:

CREATE TABLE EMPLOYEE_PAY_TBL


(EMP_ID CHAR(9) NOT NULL,
POSITION VARCHAR2(15) NOT NULL,
DATE_HIRE DATE NULL,
PAY_RATE NUMBER(4,2) NOT NULL,
DATE_LAST_RAISE DATE NULL,
CONSTRAINT EMP_ID_FK FOREIGN KEY (EMP_ID) REFERENCES EMPLOYEE_TBL
(EMP_ID));
NOT NULL Constraints
Previous examples use the keywords NULL and NOT NULL listed on the same line as each column and
after the data type. NOT NULL is a constraint that you can place on a table's column. This constraint
disallows the entrance of NULL values into a column; in other words, data is required in a NOT NULL
column for each row of data in the table. NULL is generally the default for a column if NOT NULL is not
specified, allowing NULL values in a column.

Check Constraints - Check (CHK) constraints can be utilized to check the validity of data entered into
particular table columns. Check constraints are used to provide back-end database edits, although edits
are commonly found in the front-end application as well. General edits restrict values that can be entered
into columns or objects, whether within the database itself or on a front-end application. The check
constraint is a way of providing another protective layer for the data.

The following example illustrates the use of a check constraint:

CREATE TABLE EMPLOYEE_TBL


(EMP_ID CHAR(9) NOT NULL,
EMP_NAME VARCHAR2(40) NOT NULL,
8

EMP_ST_ADDR VARCHAR2(20) NOT NULL,


EMP_CITY VARCHAR2(15) NOT NULL,
EMP_PAGER NUMBER(10) NULL),
PRIMARY KEY (EMP_ID),
CONSTRAINT CHK_EMP_ZIP CHECK ( EMP_ZIP = '46234');
Dropping Constraints - Any constraint that you have defined can be dropped using the ALTER TABLE
command with the DROP CONSTRAINT option. For example, to drop the primary key constraint in the
EMPLOYEES table, you can use the following command:

ALTER TABLE EMPLOYEES DROP CONSTRAINT EMPLOYEES_PK;

Table altered.

14. Describe in detail about interactive SQL DML.

DML statements affect records in a table. These are basic operations we perform on
data such as selecting a few records from a table, inserting new records, deleting
unnecessary records, and updating/modifying existing records.

DML statements include the following:

SELECT select records from a table


INSERT insert new records
UPDATE update/Modify existing records
DELETE delete existing records

SELECT Command - Once the data has been inserted into a table,the next most logical
operation would be to view what has been inserted. The SELECT SQL verb is used to
achieve this.The SELECT command is used to retrieve rows selected from one or more
tables.

All Rows And All Columns In order to view global data the syntax is:

SELECT <Columnname 1>To <Columnname N> FROM TableName;

Or

Select * FROM <TableName>;

For example:
9

SELECT S-id, Name, Age FROM Student;

S_id S_Name age

101 sushil 39

1) INSERT command - Insert command is used to insert data into a table. Following is its
general syntax,

INSERT into table-name values(data1,data2,..)

For example, Consider a table Student with following fields.

S_id S_Name age

We need to issue the insert statement:

INSERT into Student values(101,'Sushil',35);

UPDATE command - Update command is used to update a row of a table. Following is


its general syntax,

UPDATE table-name set column-name = value where condition;

Lets see an example,

update Student set age=39 where s_id=101;

S_id S_Name age

101 sushil 39

Delete command- Delete command is used to delete data from a table. Delete command
can also be used with condition to delete a particular row. Following is its general syntax,

DELETE from table-name;


Example to Delete all Records from a Table

DELETE from Student;


10

The above command will delete all the records from Student table.

Example to Delete a particular Record from a Table-


DELETE from Student where s_id=101;
The above command will delete the record where s_id is 101 from Student table.

17:
Every book has a title, isbn, year and price. The store also keeps the author and
publisher for any book.

For authors, the database keeps the name, address and the url of their homepage.

For publishers, the database keeps the name, address, phone number and the url of
their website.

The store has several warehouses, each of which has a code, address and phone
number.

The warehouse stocks several books. A book may be stocked at multiple

warehouses. (In previous sentence, we are not referring to a particular copy of the
book. Consider for example the complete book for our course. This book may be
stocked at multiple warehouses.)

The database records the number of copies of a book stocked at various

warehouses.

The bookstore keeps the name, address, email-id, and phone number of its

customers.

A customer owns several shopping basket. A shopping basket is identified by a


basketID and contains several books. Some shopping baskets may contain more
than one copy of same book. The database records the number of copies of each
book in any shopping basket.

Design an ER diagram for such a bookstore. You are NOT required to identify keys
or constraints for this problem.
11

Answer
STEP 1
Identify all the entities
-AUTHOR
-PUBLISHER
-BOOK
-CUSTOMER
-SHOPPING_BASKET
-WAREHOUSE
STEP 2
find the relations
1.Each book is written by a author
2.Each book has a publisher
3. Some shopping baskets may contain more than one copy of same book
4. The warehouse stocks several books
5. A customer owns several shopping basket
STEP 3
Identify the key attribute
*AUTHOR- name
*PUBLISHER- name
*BOOK- ISBN
*CUSTOMER- email
*SHOPPING_BASKET- basket_ID
*WAREHOUSE- code
STEP 4
Identify other relevant attributes
*AUTHOR- name,address,URL
*PUBLISHER- name,address,URL,phone
*BOOK- ISBN,year,title,price
*CUSTOMER- email, name,address,phone
*SHOPPING_BASKET- basket_ID
*WAREHOUSE- code, address,phone

Вам также может понравиться