37
CS101 Introduction of computing www.Virtualins .pk Prepared by Imran Baloch www.virtualians.pk Prepared by: Persian Prince CS403 Database Management Systems Lecture Wise Questions and Answers For Final Term Exam Preparation By Virtualians Social Network Lec 22: Physical Data Base Design includes the following : 1 Data volume and usage 2 Designing fields 3 Choosing data types 4 Coding techs 5 Data integrity Data volume and usage simply means to evaluate the quantity of the data to be inserted into a system and also the usage of that data. Designing field/choosing data type means that while designing a physical data base, it should be kept in view that each data type is appropriate for use with certain types of data. Data type can be defined as a set of values along with the operations that can be performed on them. Objectives of using appropriate data types include: Minimized usage of storage space Representation of all possible values Improved data integrity Supporting all data manipulation Coding is basically used to save the space. But it should be done only over the values/components/objects having a small domain. i.e. for various hobbies into a particular system like Reading, Gardening, Movies, we can assign, R, G and M. Data integrity can be achieved by putting into a system : Default value constraint Rang control

CS101 Introduction of computingapi.ning.com/files/PHKC1AOWfhzq4Ke6NcoQ3xSUT85V8MeX23...Reserved words are always written as they are i.e. in capital. Reserve words are the words which

  • Upload
    others

  • View
    1

  • Download
    0

Embed Size (px)

Citation preview

Page 1: CS101 Introduction of computingapi.ning.com/files/PHKC1AOWfhzq4Ke6NcoQ3xSUT85V8MeX23...Reserved words are always written as they are i.e. in capital. Reserve words are the words which

CS101 Introduction of computing

www.Virtualins .pk Prepared by Imran Baloch

www.virtualians.pk Prepared by: Persian Prince

CS403 Database Management Systems Lecture Wise Questions and Answers

For Final Term Exam Preparation By Virtualians Social Network

Lec 22:

Physical Data Base Design includes the following :

1 Data volume and usage

2 Designing fields

3 Choosing data types

4 Coding techs

5 Data integrity

Data volume and usage simply means to evaluate the quantity of the data to be inserted into a

system and also the usage of that data.

Designing field/choosing data type means that while designing a physical data base, it should

be kept in view that each data type is appropriate for use with certain types of data. Data type can

be defined as a set of values along with the operations that can be performed on them. Objectives

of using appropriate data types include:

Minimized usage of storage space

Representation of all possible values

Improved data integrity

Supporting all data manipulation

Coding is basically used to save the space. But it should be done only over the

values/components/objects having a small domain. i.e. for various hobbies into a particular

system like Reading, Gardening, Movies, we can assign, R, G and M.

Data integrity can be achieved by putting into a system :

Default value constraint

Rang control

Page 2: CS101 Introduction of computingapi.ning.com/files/PHKC1AOWfhzq4Ke6NcoQ3xSUT85V8MeX23...Reserved words are always written as they are i.e. in capital. Reserve words are the words which

CS101 Introduction of computing

www.Virtualins .pk Prepared by Imran Baloch

www.virtualians.pk Prepared by: Persian Prince

Null value control

Referential integrity

Lec 23:

De-normalization:

It is a technique to move from higher to lower normal forms of database modeling in order to

speed up the database access. In other words, it is a process of transforming normalized relations

into un-normalized physical record specifications.

De-normalization Situations:

1 Merge two entity types into one with one to one relationship.

2 Many to many binary relationships mapped to three relations. Joining of various relations

might get expensive in terms of time.

3 One to many situation when the ET on side does not participate in any other relationship,

then many side ET is appended with reference data rather than the foreign key.

Partitioning : De-normalization leads to merging different relations, whereas partitioning splits

same relation into two. Has two types:

Horizontal Partitioning and Vertical Partitioning.

Horizontal Partitioning Table is split on the basis of rows, which means a larger table is

split into smaller tables.

Types of Horizontal Partitioning:

Range Partitioning In this type of partitioning range is imposed on any particular attribute.

Hash Partitioning It is a type of horizontal partitioning. In this type particular algorithm is

applied and DBMS knows that algorithm.

List Partitioning In this type of partitioning the values are specified for every partition. So

there is a specified list for all the partitions.

Q. what is the actual difference between Normalization and De-normalization.

Page 3: CS101 Introduction of computingapi.ning.com/files/PHKC1AOWfhzq4Ke6NcoQ3xSUT85V8MeX23...Reserved words are always written as they are i.e. in capital. Reserve words are the words which

CS101 Introduction of computing

www.Virtualins .pk Prepared by Imran Baloch

www.virtualians.pk Prepared by: Persian Prince

Ans

We actually need to adopt de-normalization in order to attain efficiency ( access speed). It

might produce some negatives such as the violation of some normalized forms. But its

benefits are more then its drawbacks.

Q. The difference between Horizontal and Vertical Partitioning

Horizontal partitioning:

It is partitioning the table into no.of smaller tables on the basis of rows.

Like

In an employee table, employees with salary less than $10,000 will be partitioned into

different table.

Vertical Partitioning:

It is dividing the table based on the different columns.

Like

In the same employee table, retrieving oly the name and contact number of all the

employees into a different table.

Q. point out about the exact difference between DBMS and RDBMS?

DBMS is a software or tool to manage any type of Database like Relational, Object

Oriented or Hierarchical DBMS.Relational Database Management System (RDBMS) is a

type of DBMS which is specifically used to manage Relational Database.

Lec 24:

Vertical Partitioning It is done on the basis of columns.

In case of vertical partitioning , we specifically give the attribute names which are to be

partitioned, whereas, in horizontal partitioning, we apply an condition on the value of attributes

to be partitioned.

Clustering It is basically related to the adjacent physical placement of records. i.e. in case of

and Employ and department‟s example, now on the basis of the PK of the department‟s table,

this is the part that particular cluster. After creating employ table (1 to many relationship), we‟ll

Page 4: CS101 Introduction of computingapi.ning.com/files/PHKC1AOWfhzq4Ke6NcoQ3xSUT85V8MeX23...Reserved words are always written as they are i.e. in capital. Reserve words are the words which

CS101 Introduction of computing

www.Virtualins .pk Prepared by Imran Baloch

www.virtualians.pk Prepared by: Persian Prince

include department ID as foreign key (FK). Now we‟ll make the part of this cluster on the basis

of FK.

In other words Define cluster, key of the cluster, include the tables into the cluster while

creating and associating the key with it.

SQL Structured Query Language used to access and manipulate the database through DBMS.

i.e. accessing, inserting, deleting etc.

SQL benefits Application portability, Application longevity/durability, Reduced dependence

on a single vendor, Cross-system communication.

Q. What is meant by ad hoc queries?

We have seen types of partitioning? is there any further classification of denormalization in

types?

Ad Hoc queries are that queries which the user can create on their own outside the scope of

the delivered software. These are not included in the typical set of queries and reports

provided in the software. For example in SQL Server, there are many built-in Stored

Procedures, functions, views etc.

Q. what is the difference between Logical and Physical data model????

In “Logical Database Design” we design our database by keeping in view the particular

DBMS and in “Physical Database Design” we practically/physically implement the logical

design in Particular DBMS

Lec 25:

SQL Rules :

1. Reserved words are always written as they are i.e. in capital. Reserve words are the words

which a system has set itself for certain purposes. i.e. SELECT, INSERT , etc.

2. Identifiers must be valid.

Page 5: CS101 Introduction of computingapi.ning.com/files/PHKC1AOWfhzq4Ke6NcoQ3xSUT85V8MeX23...Reserved words are always written as they are i.e. in capital. Reserve words are the words which

CS101 Introduction of computing

www.Virtualins .pk Prepared by Imran Baloch

www.virtualians.pk Prepared by: Persian Prince

3. Optional things are represented by [] while required things are represented by {}, Choices

are represented by | and [….n] means n times separated by comma.

Data types in SS.

Integers : Bigint, int, smallint, tinyint.

Bit, Decimal and numeric, text, money, floating point and date.

Note that in a ternary relationship, at least one entity‟s cardinality should be 1 to make

possible the primary of all 3 relations to become the primary key of the relation being

created against this ternary relationship.

Q. As we are studying about denormalization, could you please tell me how and when it is

decided that denormalization is required. I mean what would those cricumstances be?

Ans

We will need demoralization when we are using only “Select statement” because then we

will not need normalization at all as there would be no anomalies like insert. , delete etc

Q. we update recodes in application, if yes, how?

records can be updated using SQL. You will study Update commands in SQL later in this

course.

Q. Clustering ?

is basically related to the adjacent physical placement of records. i.e. in case of and

Employ and department‟s example, now on the basis of the PK of the department‟s table,

this is the part that particular cluster. After creating employ table (1 to many relationship),

we‟ll include department ID as foreign key (FK). Now we‟ll make the part of this cluster on

the basis of FK.

Lec 26: SQL commands : DDL,DML,DCL.

Data definition language ( DDL):

DDL relates to the basic structure, creation or more precisely , the making of database.

It further has :

Create command : relates to the creation of data base, i.e. tables, populating the tables etc.

Points to remember while creating/initializing the SQL commands.

Be sure of the sign | as it allows you to pick one of the given two or more choices as appropriate.

CASCADE command allows a particular to be applied to subsequent levels . i.e. to all the data

Page 6: CS101 Introduction of computingapi.ning.com/files/PHKC1AOWfhzq4Ke6NcoQ3xSUT85V8MeX23...Reserved words are always written as they are i.e. in capital. Reserve words are the words which

CS101 Introduction of computing

www.Virtualins .pk Prepared by Imran Baloch

www.virtualians.pk Prepared by: Persian Prince

base. Whereas

NO ACTION command means that if there is a single record that is refereeing to the primary key

of the record being deleted, such operation of Deletion will not be allowed.

Best Regards from pp !

Q. denormalization & normalization difference ?

Answer: Normalization is actually the process of dividing larger tables into smaller ones

reducing the redundant data, while denormalization is the process of adding redundant

data to optimize performance. Both processes are completely oposite. Normalization is

carried out to prevent databases anomalies whereas Denormalization is usually carried out

to improve the read performance of the database.

2) Partitioning is important for following purposes:

1. Reduce workload (e.g. data access, communication costs, search space)

2. Balance workload

3. Speed up the rate of useful work (e.g. frequently accessed objects in main memory)

Q.. When i store data 01-03-2012 in a field defined as datetime type, in table very long

value appears how can i change datetime format as i feeded

Ans

If you are using later version like MS SQL Server 2005, you can try to use DATE data

type instead of DATETIME.

Q. What is the difference in datetime, date, and interval type

Ans

In datetime data type, date and time would be shown in the table. Whereas in date

datatype only date would be shown.

Q. I could not find command to see the current structure of table in query analyzer before

putting alter table command ?

Ans

You can use desc <table_name> command for this purpose.

Lec 27:

Alter command :

Used to make changes in the definition of a table already created through create statement.

Page 7: CS101 Introduction of computingapi.ning.com/files/PHKC1AOWfhzq4Ke6NcoQ3xSUT85V8MeX23...Reserved words are always written as they are i.e. in capital. Reserve words are the words which

CS101 Introduction of computing

www.Virtualins .pk Prepared by Imran Baloch

www.virtualians.pk Prepared by: Persian Prince

The TRUNCATE is used to delete all the rows of any table but rows would exist whereas

DELETE is used to delete one or many records. Note that to remove all records, we must

use TRUNCATE.

As we know, there are two types of DML (Data Manipulation languages). First one is

procedural which relates to „what‟ and „how‟ whereas the second one is non procedural

which relates only to „what‟.

Next we have is the Insert command which is used simply to insert / to add records to an

existing data.

INSERT [INTO] table {[ ( column_list ) ] { VALUES ( { DEFAULT | NULL | expression } [

,...n] ) } } | DEFAULT VALUES

Regards from Persian !

Q. What is constrain? And what is difference between constrain and attribute?

Answer: Constraints are actually used to limit the type of data that can be inserted into a

table. There are two basic types of constraints:

1.Column Level

2.Table Level

The difference between these two is that column level constraints are apply only to one

column where as table level constraints are apply to whole table. Constraints are defined at

the time of table creation using CREATE TABLE command.

For example, look into this simple query create table employee ( employee_id number not

null); Here in this query Not null is a constraint, means employee_id column can not be

null.

For attributes, you can consider them the properties of any entity. For example, employeeis

an entity. Then Employee_id, Name, Address, Salary would be its attributes. These

attributes are maped into columns of the table when you make relations from ER diagram

Q. What are reserved words ?

Ans

Reserved words are always written as they are i.e. in capital. Reserve words are the words which

a system has set itself for certain purposes. i.e. SELECT, INSERT , etc.

Page 8: CS101 Introduction of computingapi.ning.com/files/PHKC1AOWfhzq4Ke6NcoQ3xSUT85V8MeX23...Reserved words are always written as they are i.e. in capital. Reserve words are the words which

CS101 Introduction of computing

www.Virtualins .pk Prepared by Imran Baloch

www.virtualians.pk Prepared by: Persian Prince

Q. how to right optional things ?

Ans

Optional things are represented by [] while required things are represented by {}, Choices

are represented by | and [….n] means n times separated by comma.

Data types in SS.

Lec 28:

INSERT INTO is simply an INSERT command where INTO is optional.

SELECT statement/command is used not only to select rows but also the columns. It has 3

clauses : SELECT , FROM and WHERE.

In case of * , all the attributes of a given table would be available/selected.

The DISTINCT keyword is used to return only different / distinct values.

WHERE is used to limit rows or to select certain rows of certain length , credits etc.

Regards from Persian !

Q. CREATE TABLE student(

stld char(5) primary key constraint ST_CK check(stld like 's[0-

9][0-9][0-9][0-9]'),

stname char(25) not null,

stfname char(25),

staddres text,

stphone char(10),

prname char(4),

cursem smallint default 1,

gpa real)

I write this data on sql but table is not show on the screen. on message screen it is

successfully completed but table is not created please help.

Answer :

Your table has been successfully created. Now you have to use „select‟ statement to see your

created table.

For example, SELECT * FROM STUDENT;

Or

Page 9: CS101 Introduction of computingapi.ning.com/files/PHKC1AOWfhzq4Ke6NcoQ3xSUT85V8MeX23...Reserved words are always written as they are i.e. in capital. Reserve words are the words which

CS101 Introduction of computing

www.Virtualins .pk Prepared by Imran Baloch

www.virtualians.pk Prepared by: Persian Prince

You can search in your Database there will be your student table.

I hope this will help.

Q. I made Student table using SQL query, I defined its attributes and constraints, then I

execute the query and table was generated. Now if I want to change some attribute name

or add additional attribute to the table, the SQL server Management studio gives error

that similar table already exist, how we edit a table to add more attributes?

Answer :

please note down some SQL ALTER TABLE SYNTAX:

If you want to add a new column into an existing table.The following query syntax will do

the task:

ALTER TABLE table_name ADD column_name datatype

Example: Suppose you want to add a new column named 'Login', you will need to write as

ALTER TABLE student ADD Login CHAR(8);

Q. CREATE TABLE student(

stld char(5) constraint ST-PK primary key constraint ST-CK check(stld like 's[0-9][0-9][0-

9][0-9]'),

stname char(25) notnull.

stfname char(25),

staddres text,

stphone char(10),

prname char(4),

cursem smallint default 1,

gpa real)

Sir I write this in sql and then execute. After execution this message was print in message

screen” server: msg170 level 15, state1, line2

Page 10: CS101 Introduction of computingapi.ning.com/files/PHKC1AOWfhzq4Ke6NcoQ3xSUT85V8MeX23...Reserved words are always written as they are i.e. in capital. Reserve words are the words which

CS101 Introduction of computing

www.Virtualins .pk Prepared by Imran Baloch

www.virtualians.pk Prepared by: Persian Prince

Line 2: incorrect syntax near ’-‘.”

Now help me that how we correct it and how we make a table

Answer: Here in this query I have made very few changes and the query completed

successfully.

Please copy and try the following query with slight changes.

CREATE TABLE student(

stld char(5) primary key constraint ST_CK check(stld like 's[0-

9][0-9][0-9][0-9]'),

stname char(25) not null,

stfname char(25),

staddres text,

stphone char(10),

prname char(4),

cursem smallint default 1,

gpa real)

Lec 29:

If “WHERE” is given In square brackets, it means that it is optional.

The BETWEEN condition allows you to retrieve values within a specific range.

The IN function helps reduce the need to use multiple OR conditions. It is sued to check in a

list of values.

The LIKE operator allows you to use wildcards in the where clause of an SQL statement.

This allows you to perform pattern matching.

The ORDER BY clause allows you to sort the records in your result set. The ORDER BY

clause can only be used in SELECT statements.

Regards from Persian !

Q. If I have a table in Microsoft XL worksheet and there are 1000 records; Now I want to

put all these records into MS SQL; obviously I cannot write insert statement 1000 times;

can I do copy paste in this case if the attributes of both tables in MS XL and MS SQL are

same?

Answer: you can use this task by using SQL Server Import services.

Page 11: CS101 Introduction of computingapi.ning.com/files/PHKC1AOWfhzq4Ke6NcoQ3xSUT85V8MeX23...Reserved words are always written as they are i.e. in capital. Reserve words are the words which

CS101 Introduction of computing

www.Virtualins .pk Prepared by Imran Baloch

www.virtualians.pk Prepared by: Persian Prince

Q. If we say the DDL is used to declare or define the columns, would it be wrong?

Answer: It will not be wrong. It is true that DDL is used to define and declare columns.

Q. When we install SQL on our machine, an object of sql server is created. which holds

other objects e.g database, tables, views, etc. now table object could have object rows,

object columns.

Sir, if we want to define a Hierarchy of objects that on the top is SQL, than Database, than

tables than rows or columns, and than name, ids, addresses, etc. So can we define it this

way. If yes please guide me what could be the hierarchy of objects, after installing SQL

server on the PC.

Answer:

SQL system tables hierarchy is created by default. If you want to change column hierarchy,

you have to change sequence of attributes in your CREATE table SQL query.

Lec 30:

Functions in SQL :

There are normally two types of functions. First is Built in, which are provided by any

specific tool or language. Second is user defined, which are defined by the user.

Categories of Functions:

• Mathematical (ABS, ROUND, SIN, SQRT) • String (LOWER, UPPER, SUBSTRING,

LEN) • Date (DATEDIFF, DATEPART, GETDATE ()) • System (USER, DATALENGTH,

HOST_NAME) • Conversion (CAST, CONVERT)

Aggregate Functions These functions operate on a set of rows and return a single value.

The GROUP BY clause can be used in a SELECT statement to collect data across multiple

records and group the results by one or more columns.

The HAVING clause is used in combination with the GROUP BY clause. It can be used in a

SELECT statement to filter the records that a GROUP BY returns.

Page 12: CS101 Introduction of computingapi.ning.com/files/PHKC1AOWfhzq4Ke6NcoQ3xSUT85V8MeX23...Reserved words are always written as they are i.e. in capital. Reserve words are the words which

CS101 Introduction of computing

www.Virtualins .pk Prepared by Imran Baloch

www.virtualians.pk Prepared by: Persian Prince

A Cartesian join gives a Cartesian product. A Cartesian join is when you join every row of

one table to every row of another table.

Q. sir sql are install in window 7 any other window sql cannot install please sir in my pc

RAM are 5 12 processor are 2.4 please sir we already download on net but sir pc in

processing please sir solve my problems.

Answer: our PC specifications are good. SQL Server can be installed easily on your PC.

But your query is not clear. Please email your error details so that your problem can be

resolved.

Q. According to your guideline and provided links for installation of SQL Server for

windows 7 we tried a lot but it was not fruitful. SQL Server 2000 installed but unable to

create tables in database. Still many of student has same issue and they are also unable to

use SQL Server even installation. I was frequently following the links provided by you but

not installed and show errors. It is a humble request to you please add practical of SQL in

lecture as well.

Answer : SQL server 2000 is not compatible with windows 7. Many students have

successfully installed SQL Server and submitted their assignments. If you are facing any

difficulty, please provide details of your error in the form of screenshot through email.

Your request has been noted and it will be taken in consideration.

Lec 31:

Inner Join :

Only those rows from two tables are joined that have same value in the common attribute.

SELECT * FROM course INNER JOIN program ON course.prName = program.prName

Outer Join :

In an outer join, COURSE rows without a matching PROGRAM row appear exactly once in

the result, with the result columns inherited from PROGRAM assigned null values.

Select * from COURSE c LEFT OUTER JOIN

Page 13: CS101 Introduction of computingapi.ning.com/files/PHKC1AOWfhzq4Ke6NcoQ3xSUT85V8MeX23...Reserved words are always written as they are i.e. in capital. Reserve words are the words which

CS101 Introduction of computing

www.Virtualins .pk Prepared by Imran Baloch

www.virtualians.pk Prepared by: Persian Prince

Semi Join :

First inner join is performed on the participating tables and then resulting table is projected

on the attributes of one table.

SELECT distinct p.prName, totsem, prCredits FROM program p inner JOIN course c ON

p.prName = c.prName

Self Join:

In self join a table is joined with itself. This operation is used when a table contains the

reference of itself through PK, that is, the PK and the FK are both contained in the same table

supported by the referential integrity constraint.

Subquery :

A nested query is a query that has another query embedded within it; the embedded query is

called a subquery.

SELECT * from student where cgpa > (select max(cgpa) from student where prName =

'BCS„)

the outer query displays the attributes with the condition on cgpa whereas the subquery finds

the maximum cgpa

The GRANT command gives users privileges to base tables and views. The syntax of this

command is as follows: GRANT privileges ON object TO users [ WITH GRANT OPTION ]

There is a complementary command to GRANT that allows the withdrawal of privileges. The

syntax of the REVOKE command is as follows: REVOKE [GRANT OPTION FOR]

privileges ON object FROM users {RESTRICT | CASCADE}

Q. how to add column in query analyzer ?

Answer:

You have to write ALTER Table query in Query analyzer same as you have written other

create table quries.

ALTER command is used to add a column in a table

Page 14: CS101 Introduction of computingapi.ning.com/files/PHKC1AOWfhzq4Ke6NcoQ3xSUT85V8MeX23...Reserved words are always written as they are i.e. in capital. Reserve words are the words which

CS101 Introduction of computing

www.Virtualins .pk Prepared by Imran Baloch

www.virtualians.pk Prepared by: Persian Prince

Syntax of adding a column is as follows

ALTER TABLE table_name

ADD column_name datatype

Q. kindly tell me that when we used [],{} and ().. i can't understand it... [] these bracket are

used when something is optional ??

Answer:

[ ] are used for the user choice,

{ } are used for the readabiliy and ( ) are mandatory.

Q. Where year <>‟2010‟; sir it is from select operation statement please tell the symbol <>

what mean… with 2010.

Answer : '< >' operator is used for "not equal to".

Lec 32:

Application Programs :

Programs written to perform different requirement posed by the users/organization are the

application programs.

General Activities in Application Programs : • Data input programmes • Editing • Display•

Processing related to activities • Reports

User Interface :

Following are the two types of user interfaces:

• Text based • Graphical User Interface (GUI) most commonly called as Forms

Forms :

Browser Based These are web-based forms. They are developed in HTML, scripting

language or Front Page. Non-Browser/Simple

Page 15: CS101 Introduction of computingapi.ning.com/files/PHKC1AOWfhzq4Ke6NcoQ3xSUT85V8MeX23...Reserved words are always written as they are i.e. in capital. Reserve words are the words which

CS101 Introduction of computing

www.Virtualins .pk Prepared by Imran Baloch

www.virtualians.pk Prepared by: Persian Prince

Graphical User Interface :

Following are the different kinds of users:

Beginners :

Beginners need to know what your system does before they start to learn how to use it. The

best way to present this information is outside the main system itself.

Intermediate :

Intermediate users know what the system does, but they often forget the details of how. This

is the group you must support directly in the user interface.

Experts :

Expert users know what to do and how to do it. They're primarily interested in doing things

quickly.

Q. i want rename column name in sql server. sir i want to know that what is command to

do this.Regards

Answer : "sp_rename" is used to rename any object in SQL Server. Suppose you have a

table named "STUDENT" having column names St_id and Address.

Now you can rename your "St_id" column by this command.

sp_rename 'student.St_id' , 'Stu_id';

Q. I want to know that web servers now a day they used the data base what kind of data

base they are trying to used.

Answer: there is no specific database for web servers. Any database can be used along

them

Lec : 33

Following things must be ensured for input forms:

Page 16: CS101 Introduction of computingapi.ning.com/files/PHKC1AOWfhzq4Ke6NcoQ3xSUT85V8MeX23...Reserved words are always written as they are i.e. in capital. Reserve words are the words which

CS101 Introduction of computing

www.Virtualins .pk Prepared by Imran Baloch

www.virtualians.pk Prepared by: Persian Prince

• Forms should be user friendly • Data integrity must be ensured, which means that database

must represent the true picture of real system. • Checks can be applied within the tables

definition or through input forms

Forms are used as an alternative way to enter data into a database table. It can be made more

perfect with lots of practice and designing number of forms.

Q. What is intermediate and Experts. thanks with-regards

Answer: Actually intermediate users know what the system does, but they often don't

know the details of how the system do all the task. When you are going to make any user

interface, for this group of users you must support directly in the user interface.

On the other hand expert users are actually those users who know what to do and how to

do it using that software system.

Q. i want to that is there any site from where i can get help regarding all comands and all

sql stuff.regards

Answer

: http://www.sqlcourse.com/index.html and http://www.w3schools.com/sql/default.asp are very

good websites to learn SQL online.

Lec: 34

Classification of Physical Storage MediaStorage media are classified according to following

characteristics:

Speed of access, Cost per unit of data, Reliability

We can also differentiate storage as either Volatile storage Non-volatile storage

Computer storage that is lost when the power is turned off is called as volatile storage.

Computer storage that is not lost when the power is turned off is called as non – volatile

storage.

Page 17: CS101 Introduction of computingapi.ning.com/files/PHKC1AOWfhzq4Ke6NcoQ3xSUT85V8MeX23...Reserved words are always written as they are i.e. in capital. Reserve words are the words which

CS101 Introduction of computing

www.Virtualins .pk Prepared by Imran Baloch

www.virtualians.pk Prepared by: Persian Prince

Some memory caches are built into the architecture of microprocessors. Such internal caches

are often called Level 1 (L1) caches. Most modern PCs also come with external cache

memory, called Level 2 (L2) caches. These caches sit between the CPU and the DRAM.

Disk caching works under the same principle as memory caching, but instead of using high-

speed SRAM, a disk cache uses conventional main memory.

RAID (Redundant Array of Independent (or Inexpensive) Disks) :

a category of disk drives that employ two or more drives in combination for fault tolerance

and performance. RAID disk drives are used frequently on servers but aren't generally

necessary for personal computers.

RAID-0 : RAID Level 0 is not redundant, hence does not truly fit the "RAID" acronym.

Since no redundant information is stored, performance is very good, but the failure of any

disk in the array results in data loss. This level is commonly referred to as striping.

RAID-1 : provides redundancy by writing all data to two or more drives.

RAID Level 2, which uses Hamming error correction codes, is intended for use with drives

which do not have built-in error detection.

RAID Level 3 stripes data at a byte level across several drives, with parity stored on one

drive.

RAID Level 4 stripes data at a block level across several drives, with parity stored on one

drive.

RAID Level 5 is similar to level 4, but distributes parity among the drives. RAID-5 is the

best choices in multi-user environments which are not write performance sensitive. However,

at least three and more typically five drives are required for RAID-5 arrays.

Q. what is mean of Constraints kindly explain this term with examples. Regard's

Answer : constraints are basically rules which are used to limit the kind of data that can be

stored in a table. Very interesting information can be found on this useful

page:http://www.sql.org/sql-database/postgresql/manual/ddl-constraints.html

Page 18: CS101 Introduction of computingapi.ning.com/files/PHKC1AOWfhzq4Ke6NcoQ3xSUT85V8MeX23...Reserved words are always written as they are i.e. in capital. Reserve words are the words which

CS101 Introduction of computing

www.Virtualins .pk Prepared by Imran Baloch

www.virtualians.pk Prepared by: Persian Prince

Q. What is user friendly interface and Beginners ?

Answer : user friendly interface means that interface which is easy to use and operate for

beginner. Interface is the front end screen for any software system. Q. Different kinds of users ?

Ans

Beginners, intermediaries and experts

Lec 35 :

File Organizations :

In this scheme, all the records have the same size and the same field format, with the fields

having fixed size as well. The records are sorted in the file according to the content of a field

of a scalar type, called ``key''.

Sequential files provide access only in a particular sequence. That does not suit many

applications since it involves too much time. Some mechanism for direct access is required

Direct Access File Organization:

when multiple users have access to files, it may be desirable to control by whom and in what

ways files may be accessed. This control is known as file protection. Following are the two

types:

• Indexed Sequential • Direct File Organization

Indexed sequential file: The simplest indexing structure is the single-level one: a file whose

records are pair‟s key-pointer, where the pointer is the position in the data file of the record

with the given key. Only a subset of data records, evenly spaced along the data file, are

indexed, so to mark intervals of data records.

Defining Keys: An indexed sequential file must have at least one key. The first (primary) key

is always numbered 0. An indexed sequential file can have up to 255 keys; however, for file-

processing efficiency it is recommended that you define no more than 7 or 8 keys.

Page 19: CS101 Introduction of computingapi.ning.com/files/PHKC1AOWfhzq4Ke6NcoQ3xSUT85V8MeX23...Reserved words are always written as they are i.e. in capital. Reserve words are the words which

CS101 Introduction of computing

www.Virtualins .pk Prepared by Imran Baloch

www.virtualians.pk Prepared by: Persian Prince

When you design an indexed sequential file, you must define each key in the following

terms:

• Position and size • Data type • Index number • Options selected

Q. I am still confuse between char and varchar. As you mentioned that both have

maximum limit 8000 characters and also we are mentioning number of characters in both

cases then where is actual difference ? Let say I write char(10) and varchar(10) so what is

difference between these two declaration and how it effect on data ? Kindly Explain...

Ans:

Actually, the main difference between CHAR and VARCHAR data types is that a CHAR

data type is fixed-length while a VARCHAR is variable-length.

If the number of characters entered in a CHAR data type column is less than the declared

column length, spaces are appended to it to fill up the whole length.

For example, you want to store cell numbers of the employees, you will make a column like

"Emp_Contact char (15)", here you are using CHAR data type because you know the

digits of the fone / cell numbers would almost be the same for all the emopoyees.

And if you want to store the address of the employees, you will make your column like

"Emp_Address VARCHAR(30)". The use of VARCHAR is due to the variable length of

the addresses of different employees.

Another difference is in the storage size wherein the storage size for CHAR is n bytes while

for VARCHAR is the actual length in bytes of the data entered (and not n bytes). You

should use CHAR data type when the data values in a column are expected to be

consistently close to the same size. On the other hand, you should use VARCHAR when the

data values in a column are expected to vary considerably in size.

Hopefully, it would be more easy now to understand with the help of examples.

Q.What is difference among text, char and varchar (datatypes). Kindly explain with

examples...

Ans

1.TEXT data type is used to store variable-length non-Unicode data. It can be used to store

2GB of character data.

2. Char data type stores fixed-length data. Values shorter than the set length are padded

with spaces. Maximum specified length is 8,000 characters.

3. Varchar: This data type is used to store a variable amount of non-Unicode data between

Page 20: CS101 Introduction of computingapi.ning.com/files/PHKC1AOWfhzq4Ke6NcoQ3xSUT85V8MeX23...Reserved words are always written as they are i.e. in capital. Reserve words are the words which

CS101 Introduction of computing

www.Virtualins .pk Prepared by Imran Baloch

www.virtualians.pk Prepared by: Persian Prince

1 and 8,000 characters, and is expressed as varchar {n}, where n is the maximum number

of characters to store. Each character requires 1 byte of storage space.

Q. i could not understand semi joins.....please tell me about it.

Ans

Semi join actually involves two operations. First inner join is performed on the

participating tables and then resulting table is projected on the attributes of one table.

Lec 36:

Hashing

A hash function is computed on some attribute of each record. The result of the function

specifies in which block of the file the record should be placed .Hashing

provides rapid, non-sequential, direct access to records. A key record field is used to

calculate the record address by subjecting it to some calculation; a process called hashing.

For numeric ascending order a sequential key record fields this might involve simply using

relative address indexes from a base storage address to access records. Most of the time,

key field does not have the values in sequence that can directly be used as relative record

number.

Hash Functions A good hash function gives an average-case lookup that is a small constant,

independent of the number of search keys. We hope records are distributed uniformly

among the buckets. The worst hash function maps all keys to the same bucket. The best

hash function maps all keys to distinct addresses. Ideally, distribution of keys to addresses

is uniform and random.

Hashed Access Characteristics Following are the major characteristics:

• No indexes to search or maintain

• Very fast direct access • Inefficient sequential access • Use when direct access is needed,

but sequential access is not.

Q. sir i installed the sql server 2005 but how can use i cannot uderstand what is the method

to use ( sql configration manger)server surface area these are tool which ican use

1. Open Management Studio.

2. Click the New Query button at the top left of the toolbar to open a query editor window.

3. Type any SQL statement statements in the editor window. (For this step you can copy

andy past any create table query from the SQL Queries Tutorial available under

downloads section)

4. Then Click the ! Execute button just to the right of the toolbar drop-down list box.

Page 21: CS101 Introduction of computingapi.ning.com/files/PHKC1AOWfhzq4Ke6NcoQ3xSUT85V8MeX23...Reserved words are always written as they are i.e. in capital. Reserve words are the words which

CS101 Introduction of computing

www.Virtualins .pk Prepared by Imran Baloch

www.virtualians.pk Prepared by: Persian Prince

Q. sir you have provided me these links for my operating system window 8 64 bits but

when i did instlled this in my laptop ,massage comes not compatible for your system.

Dear student, please follow the following links:

1. http://download.microsoft.com/download/8/E/5/8E53FAA8-1129-4621-903...

The above link will help you to download SQL Server 2008 Express Edition for 64-bit OS.

2. http://download.microsoft.com/download/6/7/4/674A281B-84BF-4B49-848...

And now this link will able you to dowload the specific management studio.

Hope this helps...

Ok... try the setup on this link please.

http://download.microsoft.com/download/7/C/8/7C8F6A23-5876-4C55-91A...

You can read all important instructions at this link from

Microsoft. http://www.microsoft.com/en-us/download/details.aspx?displaylang=en...

Q. I want to know that what is the main difference between Conceptual Data Model and

Logical Data Model?

actually a logical data model describes the data in as much detail as possible, without

regard to how they will be physical implemented in the database. Features of a logical data

model include:

1. Includes all entities and relationships among them.

2. All attributes for each entity are specified.

3. The primary key for each entity is specified.

4. Foreign keys (keys identifying the relationship between different entities) are specified

5. Normalization occurs at this level.

On the other hand, in conceptual data model we identify the highest-level relationships

between the different entities. Features of conceptual data model include:

1. Includes the important entities and the relationships among them.

2. No attribute is specified.

3. No primary key is specified.

Lec 37: Index

In a book, the index is an alphabetical listing of topics, along with the page number where

the topic appears. The idea of an INDEX in a Database is similar. We will consider two

popular types of indexes, and see how they work, and why they are useful. Any subset of

the fields of a relation can be the search key for an index on the relation. Search key is not

the same as key (e.g. doesn‟t have to be unique ID). An

index contains a collection of data entries, and supports efficient retrieval of all records

with a given search key value k.

Page 22: CS101 Introduction of computingapi.ning.com/files/PHKC1AOWfhzq4Ke6NcoQ3xSUT85V8MeX23...Reserved words are always written as they are i.e. in capital. Reserve words are the words which

CS101 Introduction of computing

www.Virtualins .pk Prepared by Imran Baloch

www.virtualians.pk Prepared by: Persian Prince

Index Classification Indexes are classified as under: • Clustered vs. Un-clustered Indexes

• Single Key vs. Composite Indexes • Tree-based, inverted files, pointers

Primary Indexes: Consider a table, with a Primary Key Attribute being used to store it as

an ordered array (that is, the records of the table are stored in order of increasing value of

the Primary Key attribute.)As we know, each BLOCK of memory will store a few records

of this table. Since all search operations require transfers of complete blocks, to

search for a particular record, we must first need to know which block it is stored in.

Secondary Indexes: Users often need to access data on the basis of non-key or non-unique

attribute; secondary key. Like student name, program name, students enrolled in a

particular program

Properties of Indexes: Following are the major properties of indexes: • Indexes can be

defined even when there is no data in the table

• Existing values are checked on execution of this command

• It support selections of form as under: field <operator> constant

• It support equality selections as under: Either “tree” or “hash” indexes help here. • It

support Range selections (operator is one among <, >, <=, >=, BETWEEN)

Q. I would like to confirm if I can use the SQL 2008 R2 or SQL 2012. I know that there is

big differences between these version but the basic are same at the level of our work.

Ans

It would be better for you to use SQL Server 2008, because your main purpose is to learn

SQL. After that you can migrate to latest versions.

Q.21st century NoSQL databases

Ans

In the 21st century a new trend of NoSQL databases was started. Those non-relational

databases are significantly different from the classic relational databases. They often do not

require fixed table schemas, avoid join operations by storing denormalized data, and are

designed to scale horizontally. Most of them can be classified as either key-value

stores or document-oriented databases.

In recent years there was a high demand for massively distributed databases with high

partition tolerance but according to the CAP theorem it is impossible for a distributed

system to simultaneously provide consistency, availability and partition tolerance guarantees.

A distributed system can satisfy any two of these guarantees at the same time, but not all

Page 23: CS101 Introduction of computingapi.ning.com/files/PHKC1AOWfhzq4Ke6NcoQ3xSUT85V8MeX23...Reserved words are always written as they are i.e. in capital. Reserve words are the words which

CS101 Introduction of computing

www.Virtualins .pk Prepared by Imran Baloch

www.virtualians.pk Prepared by: Persian Prince

three. For that reason many NoSQL databases are using what is called eventual

consistency to provide both availability and partition tolerance guarantees with a maximum

level of data consistency.

The most popular software in that category

include: MongoDB, memcached, Redis, CouchDB, Hazelcast, Apache Cassandra and HBase,

that all are open-source software products.

Q. Database indexing

Ans

Indexing is a technique for improving database performance. The many types of indexes

share the common property that they reduce the need to examine every entry when

running a query. In large databases, this can reduce query time/cost by orders of

magnitude. The simplest form of index is a sorted list of values that can be searched using

a binary search with an adjacent reference to the location of the entry, analogous to the

index in the back of a book. The same data can have multiple indexes (an employee

database could be indexed by last name and hire date.)

Indexes affect performance, but not results. Database designers can add or remove indexes

without changing application logic, reducing maintenance costs as the database grows and

database usage evolves.

Given a particular query, the DBMS' query optimizer is responsible for devising the most

efficient strategy for finding matching data.

Indexes can speed up data access, but they consume space in the database, and must be

updated each time the data is altered. Indexes therefore can speed data access but slow

data maintenance. These two properties determine whether a given index is worth the cost.

Lec 38: Ordered Indices In order to allow fast random access, an index structure may be

used. A file may have several indices on different search keys. If the file containing the

records is sequentially ordered, the index whose search key specifies the sequential order of

the file is the primary index, or clustering index.

Note: The search key of a primary index is usually the primary key, but it is not necessarily

so. Indices whose search key specifies an order different from the sequential order of the

file are called the secondary indices, or nonclustering indices.

Dense and Sparse Indices There are Two types of ordered indices: Dense Index: An index

record appears for every search key value in file. This record contains search key value and

Page 24: CS101 Introduction of computingapi.ning.com/files/PHKC1AOWfhzq4Ke6NcoQ3xSUT85V8MeX23...Reserved words are always written as they are i.e. in capital. Reserve words are the words which

CS101 Introduction of computing

www.Virtualins .pk Prepared by Imran Baloch

www.virtualians.pk Prepared by: Persian Prince

a pointer to the actual record. Sparse Index: Index records are created only for some of the

records. To locate a record, we find the index record with the largest search key value less

than

or equal to the search key value we are looking for. We start at that record pointed to by

the index record, and proceed along the pointers in the file (that is, sequentially) until we

find the desired record. Dense indices are faster in general, but sparse indices require less

space and impose less maintenance for insertions and deletions. We can have a good

compromise by having a sparse index with one entry per block. It has several advantages.

Q. Guidelines for Managing Indexes

Ans

Create Indexes After Inserting Table Data

Data is often inserted or loaded into a table using either the SQL*Loader or an import

utility. It is more efficient to create an index for a table after inserting or loading the data.

If you create one or more indexes before loading data, the database then must update every

index as each row is inserted.

Creating an index on a table that already has data requires sort space. Some sort space

comes from memory allocated for the index creator. The amount for each user is

determined by the initialization parameter SORT_AREA_SIZE. The database also swaps

sort information to and from temporary segments that are only allocated during the index

creation in the user's temporary tablespace.

Under certain conditions, data can be loaded into a table with SQL*Loader direct-path

load and an index can be created as data is loaded.

Q. Index the Correct Tables and Columns

Ans

Use the following guidelines for determining when to create an index:

Create an index if you frequently want to retrieve less than 15% of the rows in a

large table. The percentage varies greatly according to the relative speed of a table

scan and how the distribution of the row data in relation to the index key. The faster

the table scan, the lower the percentage; the more clustered the row data, the higher

the percentage.

To improve performance on joins of multiple tables, index columns used for joins.

Page 25: CS101 Introduction of computingapi.ning.com/files/PHKC1AOWfhzq4Ke6NcoQ3xSUT85V8MeX23...Reserved words are always written as they are i.e. in capital. Reserve words are the words which

CS101 Introduction of computing

www.Virtualins .pk Prepared by Imran Baloch

www.virtualians.pk Prepared by: Persian Prince

Note:

Primary and unique keys automatically have indexes, but you might want to create

an index on a foreign key.

Lec 39: Views Views are generally used to focus, simplify, and customize the perception

each user has of the database. Views can be used as security mechanisms by allowing users

to access data through the view, without granting the users

permissions to directly access the underlying base tables of the view.

You can customize all aspects of a view, including: • The name of the view • The fields that

appear in the view • The column title for each field in the view • The order of the fields in

the view • The width of columns in the view, as well as the overall width of the view • The

set of records that appear in the view (Filtering) • The order in which records are displayed

in the view (Sorting & Grouping) • Column totals for numeric and currency fields

(Totaling & Subtotaling)

Q. Columns That Are Suitable for Indexing

Ans

Some columns are strong candidates for indexing. Columns with one or more of the

following characteristics are candidates for indexing:

Values are relatively unique in the column.

There is a wide range of values (good for regular indexes).

There is a small range of values (good for bitmap indexes).

The column contains many nulls, but queries often select all rows having a value. In

this case, use the following phrase:

WHERE COL_X > -9.99 * power(10,125)

Using the preceding phrase is preferable to:

WHERE COL_X IS NOT NULL

This is because the first uses an index on COL_X (assuming that COL_X is a

numeric column)

Q. Columns That Are Not Suitable for Indexing

Ans

Page 26: CS101 Introduction of computingapi.ning.com/files/PHKC1AOWfhzq4Ke6NcoQ3xSUT85V8MeX23...Reserved words are always written as they are i.e. in capital. Reserve words are the words which

CS101 Introduction of computing

www.Virtualins .pk Prepared by Imran Baloch

www.virtualians.pk Prepared by: Persian Prince

Columns with the following characteristics are less suitable for indexing:

There are many nulls in the column and you do not search on the not null values.

LONG and LONG RAW columns cannot be indexed.

Virtual Columns

You can create unique or non-unique indexes on virtual columns.

Q. Order Index Columns for Performance

Ans

The order of columns in the CREATE INDEX statement can affect query performance. In

general, specify the most frequently used columns first.

If you create a single index across columns to speed up queries that access, for

example, col1, col2, and col3; then queries that access just col1, or that access

just col1 and col2, are also speeded up. But a query that accessed just col2, just col3, or

just col2 and col3 does not use the index.

Q. Limit the Number of Indexes for Each Table

Ans

A table can have any number of indexes. However, the more indexes there are, the more

overhead is incurred as the table is modified. Specifically, when rows are inserted or

deleted, all indexes on the table must be updated as well. Also, when a column is updated,

all indexes that contain the column must be updated.

Thus, there is a trade-off between the speed of retrieving data from a table and the speed of

updating the table. For example, if a table is primarily read-only, having more indexes can

be useful; but if a table is heavily updated, having fewer indexes could be preferable.

Lec 40: Characteristics /Types of Views: We have a number of views type of which some of

the important views types are listed below: • Materialized View • Simple Views • Complex

View • Dynamic Views.

A materialized view is a replica of a target master from a single point in time. The master

can be either a master table at a master site or a master materialized view at a materialized

view site.

Page 27: CS101 Introduction of computingapi.ning.com/files/PHKC1AOWfhzq4Ke6NcoQ3xSUT85V8MeX23...Reserved words are always written as they are i.e. in capital. Reserve words are the words which

CS101 Introduction of computing

www.Virtualins .pk Prepared by Imran Baloch

www.virtualians.pk Prepared by: Persian Prince

simple views are created from tables and are used for creating secure manipulation over

the tables or structures of the database.

Complex views are by definition views of type which may comprise of many of elements,

such as tables, views sequences and other similar objects of the database.

Dynamic views are those types of views for which data is not stored and the expressions

used to build the view are used to collect the data dynamically.

Q. what is meant by Drop Indexes That Are No Longer Required ?

Ans

Consider dropping an index if:

It does not speed up queries. The table could be very small, or there could be many

rows in the table but very few index entries.

The queries in your applications do not use the index.

The index must be dropped before being rebuilt.

Q. ndexes and Deferred Segment Creation ? Ans

Index segment creation is deferred when the associated table defers segment creation. This

is because index segment creation reflects the behavior of the table it is associated with.

Q. Estimate Index Size and Set Storage Parameters

Ans

Estimating the size of an index before creating one can facilitate better disk space planning

and management. You can use the combined estimated size of indexes, along with estimates

for tables, the undo tablespace, and redo log files, to determine the amount of disk space

that is required to hold an intended database. From these estimates, you can make correct

hardware purchases and other decisions.

Use the estimated size of an individual index to better manage the disk space that the index

uses. When an index is created, you can set appropriate storage parameters and improve

I/O performance of applications that use the index. For example, assume that you estimate

the maximum size of an index before creating it. If you then set the storage parameters

when you create the index, fewer extents are allocated for the table data segment, and all of

Page 28: CS101 Introduction of computingapi.ning.com/files/PHKC1AOWfhzq4Ke6NcoQ3xSUT85V8MeX23...Reserved words are always written as they are i.e. in capital. Reserve words are the words which

CS101 Introduction of computing

www.Virtualins .pk Prepared by Imran Baloch

www.virtualians.pk Prepared by: Persian Prince

the index data is stored in a relatively contiguous section of disk space. This decreases the

time necessary for disk I/O operations involving this index.

The maximum size of a single index entry is approximately one-half the data block size.

Storage parameters of an index segment created for the index used to enforce a primary

key or unique key constraint can be set in either of the following ways:

In the ENABLE ... USING INDEX clause of

the CREATE TABLE or ALTER TABLE statement

In the STORAGE clause of the ALTER INDEX statement

Lec 41: Updating Multiple Tables We can do this updation of multiple views by doing it

one at a time. It means that while inserting values in different tables, it can only be done

one at a time. We will now see an example of this as under: CREATE VIEW st_pr_view1

(a1, a2, a3, a4) AS (select stId, stName, program.prName, prcredits from student, program

WHERE student.prName = program.prName) In this example this is a join statement We

will now enter data in the table insert into st_pr_view1 (a3, a4) values ('MSE', 110) We will

now see the program table after writing this SQL statement as the data

has been stored in the table. Select * from program

Materialized Views A pre-computed table comprising aggregated or joined data from fact

and possibly dimensions tables. Also known as summary or aggregate table.Views are

virtual tables. In which query is executed every time .For complex queries involving large

number of join rows and aggregate functions, so it is problematic.

Transaction Management A transaction can be defined as an indivisible unit of work

comprised of several operations, all or none of which must be performed in order to

preserve data integrity. For example, a transfer of Rs 1000 from your checking account to

your savings account would consist of two steps: debiting your checking account by Rs1000

and

crediting your savings account with Rs1000. To protect data integrity and consistency and

the interests of the bank and the customer these two operations must be applied together or

not at all. Thus, they constitute a transaction.

Q. Specify the Tablespace for Each Index

Page 29: CS101 Introduction of computingapi.ning.com/files/PHKC1AOWfhzq4Ke6NcoQ3xSUT85V8MeX23...Reserved words are always written as they are i.e. in capital. Reserve words are the words which

CS101 Introduction of computing

www.Virtualins .pk Prepared by Imran Baloch

www.virtualians.pk Prepared by: Persian Prince

Ans

Indexes can be created in any tablespace. An index can be created in the same or different

tablespace as the table it indexes. If you use the same tablespace for a table and its index, it

can be more convenient to perform database maintenance (such as tablespace or file

backup) or to ensure application availability. All the related data is always online together.

Using different tablespaces (on different disks) for a table and its index produces better

performance than storing the table and index in the same tablespace. Disk contention is

reduced. But, if you use different tablespaces for a table and its index and one tablespace is

offline (containing either data or index), then the statements referencing that table are not

guaranteed to work.

Q. Consider Parallelizing Index Creation

Ans

You can parallelize index creation, much the same as you can parallelize table creation.

Because multiple processes work together to create the index, the database can create the

index more quickly than if a single server process created the index sequentially.

When creating an index in parallel, storage parameters are used separately by each query

server process. Therefore, an index created with an INITIAL value of 5M and a parallel

degree of 12 consumes at least 60M of storage during index creation.

Q. Consider Creating Indexes with NOLOGGING

Ans

You can create an index and generate minimal redo log records by

specifying NOLOGGING in the CREATE INDEX statement.

Note:

Because indexes created using NOLOGGING are not archived, perform a backup after

you create the index.

Lec 42:

The Concept of a Transaction A user writes data access/update programs in terms of the

high-level query and up- date language supported by the DBMS. To understand how the

DBMS handles such

requests, with respect to concurrency control and recovery, it is convenient to regard an

Page 30: CS101 Introduction of computingapi.ning.com/files/PHKC1AOWfhzq4Ke6NcoQ3xSUT85V8MeX23...Reserved words are always written as they are i.e. in capital. Reserve words are the words which

CS101 Introduction of computing

www.Virtualins .pk Prepared by Imran Baloch

www.virtualians.pk Prepared by: Persian Prince

execution of a user program, or transaction, as a series of reads and writes of database

objects:

• To read a database object, it is first brought into main memory (specifically, some frame

in the buffer pool) from disk, and then its value is copied into a program variable. • To

write a database object, an in-memory copy of the object is first modified and then written

to disk.

There are four important properties of transactions that a DBMS must ensure to maintain

data in the face of concurrent access and system failures:

• Users should be able to regard the execution of each transaction as atomic: either all

actions are carried out or none are. Users should not have to worry about the effect of

incomplete transactions (say, when a system crash occurs).

• Each transaction, run by itself with no concurrent execution of other transactions, must

preserve the consistency of the database. This property is called consistency, and the

DBMS assumes that it holds for each transaction. Ensuring this property of a transaction is

the responsibility of the user.

• Users should be able to understand a transaction without considering the effect of other

concurrently executing transactions, even if the DBMS interleaves the actions of several

transactions for performance reasons. This property is sometimes referred to as isolation:

Transactions are isolated, or protected, from the effects of concurrently scheduling other

transactions.

• Once the DBMS informs the user that a transaction has been successfully completed, its

effects should persist even if the system crashes before all its changes are reflected on disk.

This property is called durability.

Q. Creating an index with NOLOGGING has the following benefits:

Space is saved in the redo log files.

The time it takes to create the index is decreased.

Performance improves for parallel creation of large indexes.

In general, the relative performance improvement is greater for larger indexes created

without LOGGING than for smaller ones. Creating small indexes withoutLOGGING has

little effect on the time it takes to create an index. However, for larger indexes the

performance improvement can be significant, especially when you are also parallelizing the

index creation.

Page 31: CS101 Introduction of computingapi.ning.com/files/PHKC1AOWfhzq4Ke6NcoQ3xSUT85V8MeX23...Reserved words are always written as they are i.e. in capital. Reserve words are the words which

CS101 Introduction of computing

www.Virtualins .pk Prepared by Imran Baloch

www.virtualians.pk Prepared by: Persian Prince

Q. Understand When to Use Unusable or Invisible Indexes

Use unusable or invisible indexes when you want to improve the performance of bulk loads,

test the effects of removing an index before dropping it, or otherwise suspend the use of an

index by the optimizer.

Q. Unusable indexes ?

An unusable index is ignored by the optimizer and is not maintained by DML. One reason

to make an index unusable is to improve bulk load performance. (Bulk loads go more

quickly if the database does not need to maintain indexes when inserting rows.) Instead of

dropping the index and later re-creating it, which requires you to recall the exact

parameters of the CREATE INDEX statement, you can make the index unusable, and then

rebuild it.

You can create an index in the unusable state, or you can mark an existing index or index

partition unusable. In some cases the database may mark an index unusable, such as when

a failure occurs while building the index. When one partition of a partitioned index is

marked unusable, the other partitions of the index remain valid.

An unusable index or index partition must be rebuilt, or dropped and re-created, before it

can be used. Truncating a table makes an unusable index valid.

Beginning with Oracle Database 11g Release 2, when you make an existing index unusable,

its index segment is dropped.

Lec 43:

Incremental Log with Deferred Updates We are discussing the deferred updates approach

regarding the database recovery techniques. In the previous lecture we studied the

structure of log file entries for the deferred updates approach. In today‟s lecture we will

discuss the recovery process.

Write Sequence: First we see what the sequence of actions is when a write operation is

performed. On

encountering a „write‟ operation, the DBMS places an entry in the log file buffer

mentioning the effect of the write operation. For example, if the transaction includes the

Page 32: CS101 Introduction of computingapi.ning.com/files/PHKC1AOWfhzq4Ke6NcoQ3xSUT85V8MeX23...Reserved words are always written as they are i.e. in capital. Reserve words are the words which

CS101 Introduction of computing

www.Virtualins .pk Prepared by Imran Baloch

www.virtualians.pk Prepared by: Persian Prince

operations: ……. X = X + 10

Write X ……. Supposing that the value of X before the addition operation is 23 and after

the execution of operation it becomes 33. Now against the write operation, the entry made

in the log file will be

<Tn, X, 33>

In the entry, Tn reflects the identity of the transaction, X is the object being updated

and 33 is the value that has to be placed in X. Important point to be noted here is that the

log entry is made only for the write operation. The assignment operation and any other

mathematical or relational operation is executed in RAM. For a „read‟ operation

the value may be read from the disk (database) or it may already be in RAM or cache. But

the log entry results only from a „write‟ operation.

Q. Invisible Indexes

Ans

Beginning with Oracle Database 11g Release 1, you can create invisible indexes or make an

existing index invisible. An invisible index is ignored by the optimizer unless you explicitly

set the OPTIMIZER_USE_INVISIBLE_INDEXES initialization parameter to TRUE at

the session or system level. Unlike unusable indexes, an invisible index is maintained during

DML statements. Although you can make a partitioned index invisible, you cannot make

an individual index partition invisible while leaving the other partitions visible.Using

invisible indexes, you can do the following:

Test the removal of an index before dropping it.

Use temporary index structures for certain operations or modules of an application

without affecting the overall application. Q. i can not understand the use of WHERE clause plz explain it with a example .

ANs

WHERE clause is used to specify a condition on which you want to extract your desired records

from a table.

Let us suppose you have a table of Employee. This table has some attributes like Emp_ID,

Emp_Name, Emp_Dept and Emp_Salary. Now if you are interested to know employees who are

taking salary greater than 20000, then how you will come to know?

In this case WHERE clause servers the purpose.

You will write a SELECT statement as follows.

Page 33: CS101 Introduction of computingapi.ning.com/files/PHKC1AOWfhzq4Ke6NcoQ3xSUT85V8MeX23...Reserved words are always written as they are i.e. in capital. Reserve words are the words which

CS101 Introduction of computing

www.Virtualins .pk Prepared by Imran Baloch

www.virtualians.pk Prepared by: Persian Prince

SELECT * FROM Employee WHERE Emp_Salary > 20000.

I hope this will clear the idea to you.

Q. Some database systems require a semicolon at the end of each SQL statement. in which type

of steatments semicolon is essential?

Ans

Semi colon is used to separate one instruction from another. It is not statement specific, it

depends on the DBMS. In MS Access and SQL Server, it is not necessary to put a semi colon at

the end. Both of them do not force to use semi colon, commands will execute correctly in both

cases i.e. with semi colon or without semi colon.

Q. kindly tell me what is correct answer of this question

SQL stands for ______________. I - Structured Query Language II – Standard Query Language

lll- Status Query Language

ONLY I

ONLY II

BOTH I AND II

ONLY III

Ans

„ONLY I‟ is the correct answer. SQL stands for Structured Query Language.

Lec 44: Uncommitted Update Problem It reflects a situation when a transaction updates an

object and another transaction

reads this updated value but later the first transaction is aborted. The problem in this

situation is that the second transaction reads the value updated by an aborted

transaction. This situation is shown in the table below:

Table 1:

Uncommitted update problem As is shown in the table, at time t2, transaction TA updates

the value of object „BAL‟ by adding 100 in its initial value 1000 and at time t3 it writes this

updated value to

database. So „BAL‟ is written as 1100. Now at time t4, TB reads the value of „BAL‟ and it

gets 1100 then TB updates the value multiplying it by 1.5 and writes it at time t6. So the

Page 34: CS101 Introduction of computingapi.ning.com/files/PHKC1AOWfhzq4Ke6NcoQ3xSUT85V8MeX23...Reserved words are always written as they are i.e. in capital. Reserve words are the words which

CS101 Introduction of computing

www.Virtualins .pk Prepared by Imran Baloch

www.virtualians.pk Prepared by: Persian Prince

new value written for „BAL‟ is 2650. However at time t7 transaction TA is rolled back as a

result of this rollback the changes made by TA stand cancelled, but TB has already

performed certain processing on the value set by TA. This is an

inconsistent state of the database.

Q. To understand the codes written in the handouts please help me.

What does [ ] means?

what does { } means?

what does ( ) means?

what does | means?

what does < > means?

and if we have [{ }] or [( )] or {[ ]} what does they will stand for?

i know things are optional, not-optional, later but for better understanding i need your help.

Regards

Ans

1. [ ] is used for optional syntax items.

2. { } the items which are required are enclosed in these.

3. ( ) are used pass the items to any table, variable, or function.

4. | separates syntax items enclosed in brackets or braces. You can use only one of the

items.

5. < > This is the name for a block of syntax. This convention is used to group and label

sections of lengthy syntax or a unit of syntax that can be used in more than one location

within a statement.

Q. create table sale

(

Sale_ID int primary key not null,

Invoicedate Datetime,

invoiceNumber int,

Discount Decimal,

customer_id Int,

Discription varchar (200)

);

insert into sale values(1,'2013-01-28',23,23.50,88,'profit');

insert into sale values(2,'2013-01-28',24,24,89,'Average');

Page 35: CS101 Introduction of computingapi.ning.com/files/PHKC1AOWfhzq4Ke6NcoQ3xSUT85V8MeX23...Reserved words are always written as they are i.e. in capital. Reserve words are the words which

CS101 Introduction of computing

www.Virtualins .pk Prepared by Imran Baloch

www.virtualians.pk Prepared by: Persian Prince

insert into sale values(3,'2013-01-28',25,25,90,'loss');

select * from sale;

ORDER BY invoiceNumber ASC;

ERROR:

Server: Msg 156, Level 15, State 1, Line 2

Incorrect syntax near the keyword 'ORDER'.

DEAR sir ,, kindly tell me how to remove this error ??

Ans

There is problem with your “select * from sale;

ORDER BY invoiceNumber ASC;” statement. There should be no‟;‟ after sale. Please try

rewriting. Hope it will resolve error.

Q. CREATE TABLE product

(

productID int primary key not null,

Name char,

VendorID int,

Quantity int);

Select * from product

insert into product VALUES(1,'Cream',2,5)

ERROR

Server: Msg 8152, Level 16, State 9, Line 1

String or binary data would be truncated.

The statement has been terminated.

DEAR SIR ,, still GIVING ME the same error.....

Ans

You have not specified length for your char that is why this error is coming up. Please try writing

Name char (20). Also specify length of other attributes.

I hope this will resolve your error.

Lec 45:

Locking Idea

Traditionally, transaction isolation levels are achieved by taking locks on the data that they

access until the transaction completes. There are two primary modes for taking

Page 36: CS101 Introduction of computingapi.ning.com/files/PHKC1AOWfhzq4Ke6NcoQ3xSUT85V8MeX23...Reserved words are always written as they are i.e. in capital. Reserve words are the words which

CS101 Introduction of computing

www.Virtualins .pk Prepared by Imran Baloch

www.virtualians.pk Prepared by: Persian Prince

locks: optimistic and pessimistic. These two modes are necessitated by the fact that when a

transaction accesses data, its intention to change (or not change) the data may not be

readily apparent.

Some systems take a pessimistic approach and lock the data so that other transactions may

read but not update the data accessed by the first transaction until the first transaction

completes. Pessimistic locking guarantees that the first transaction can always apply a

change to the data it first accessed.

In an optimistic locking mode, the first transaction accesses data but does not take a lock

on it. A second transaction may change the data while the first transaction is in progress. If

the first transaction later decides to change the data it accessed, it has to detect the fact that

the data is now changed and inform the initiator of the fact. In optimistic locking,

therefore, the fact that a transaction accessed data first does not guarantee that it can, at a

later stage, update it.

A deadlock occurs when the first transaction has locks on the resources that the second

transaction wants to modify, and the second transaction has locks on the resources that the

first transaction intends to modify. So a deadlock is much like an

infinite loop: If you let it go, it will continue until the end of time, until your server crashes,

or until the power goes out (whichever comes first). Deadlock is a situation when two

transactions are waiting for each other to release a lock.

Q. ALTER TABLE sale

ADD CONSTRAINT customer_id Foreign Key (customer_id)

REFERENCES customer (customer_id);

After applying the FK this error occurs..

(

Server: Msg 1769, Level 16, State 1, Line 1

Foreign key 'customer_id' references invalid column 'customer_id' in referencing table 'sale'.

Server: Msg 1750, Level 16, State 1, Line 1

Could not create constraint. See previous errors.

)

Sir i can't understand this.. what to do now. kindly tell me how can i resolve it ??

i created the customer table , it is also showing in sql

Ans

Page 37: CS101 Introduction of computingapi.ning.com/files/PHKC1AOWfhzq4Ke6NcoQ3xSUT85V8MeX23...Reserved words are always written as they are i.e. in capital. Reserve words are the words which

CS101 Introduction of computing

www.Virtualins .pk Prepared by Imran Baloch

www.virtualians.pk Prepared by: Persian Prince

This error shows that you do not have a CustomerID column in your Sale table. Please first

create a column of CustomerID in Sale table and after that apply foreign key constraint on it. It

will resolve the error.

Q. Kindly give any practical example of Sequential File Organizaition>?

Ans

Tape derive is the best practical example of sequential file organization. A decade ago, tape

derives were very popular source of entertainment. So called cassettes were mostly in use instead

of CD‟s.

For example, if you have a cassette of 10 songs and you want to listen to 4th song then you have

to first go through first 3 songs and then you will be able to access your required record i.e. to

access data in the middle of a tape, the tape drive must pass through all the preceding data.

Q. If company has decided that it will maintain its Database using RAID-4 structure, then what

all hardware elements are required to implement it? In other words, if i goto computer market,

what tell them what i want?

Ans

simply you will have to purchase a server computer for it!

Normal Harddisk comprises of multiple disks inside, then can a normal single Hard disk can be

used in RAID architecture?

Ans

Basically RAID purpose is to store large amount of data, such as on servers. A normal hard disk

can also be categorized as RAID if it needs to store data in bulk but we usually do not need it.