Professional Documents
Culture Documents
What is an Entity?
The basic data item stored in database is called entity. An
entity can be any object, item, place, person, concept, or
activity about which data is stored.
What is an attribute?
An attribute is a property of an entity. It describes a part of
an entity. Entity could have one or more attributes.
What is ER diagram?
An
Entity
Relationship
Diagram
is
diagrammatic
representation of the logical structure of a database
system.
constraints.
Unique constraints are used to enforce uniqueness on nonprimary key columns. It allows null values but only one row
can have a null value.
Multiple unique constraints can be created on a table.
Foreign Key constraint
You can use the foreign key constraint to remove the
inconsistency in two tables when the data in the one table is
dependant on the other table.
Check constraint
It enforces domain integrity by restricting the values to be
inserted in a column. It is possible to define multiple check
constraints on a single column. These are evaluated in the
order in which they are defined.
Default Constraint
A default constraint can be use to assign a constant value to
a column and the user need not insert values in to that
column.
1. What is a rule?
The required integrity can be enforced by specifying a check
constraint or by defining a rule. But check constraint
modifies the table structure. The constraint can there fore be
implemented using rules with out changing the table
structure. This rule is applied before an insert or update
statement .
A rule must be bound to a column or a user-define d data
type. This is done using stored procedure sp_bindrule. Rules
do not apply to data that has already been inserted in the
table. The existing values in tables do not have to meet the
criteria specified by the rule.
What are indexes?
To speed up data retrieval indexes are used. Indexes also
enforce the uniqueness of rows.
3
Advantages
Improves the speed of execution.
Enforces uniqueness of data.
Speeds up joins between tables.
Disadvantages
1.Takes disk space to store.
2.Data modification takes longer.
3.Takes time to create index.
Types of indexes
Clustered index
1.The data is physically sorted
2.One clustered index can be created per table, so you
should build it on attributes that have a high percentage
of unique values and that are not modified often.
Nonclustered index
1.The physical order of the rows is not the same as the index
order.
2.There can be as many as 249 nonclustered indexes per
column.
What are views?
A view is a virtual table, which gives access to a subset of
columns from one or more tables. It is a query stored as
an object in the database. Hence a view is an object that
derives it data from one or more tables.
Advantages
1.A view serves as a security mechanism.
4
Cursor Types
So you can specify the four-cursor types for Transact-SQL
cursors. These cursors vary in their ability to detect changes
to the result set and in the resources, such as memory and
space in tempdb, they consume. The four API server cursor
types supported by SQL Server are:
Static cursors
Dynamic cursors
Forward-only cursors
Key set-driven cursors
10
Although the database API cursor models consider a forwardonly cursor to be a distinct type of cursor, SQL Server does
not. SQL Server considers both Forward only and scroll to be
options that can be applied to static, key set-driven, and
dynamic cursors.
4. What is Encryption option in SQL Server?
Encryption is a method for keeping sensitive information
confidential by changing data into an unreadable form.
Encryption ensures that data remains secure by keeping the
information hidden from everyone, even if the encrypted
data is viewed directly. Decryption is the process of
changing encrypted data back into its original form and so
authorized users can view it.
5. What are time-stamped data types?
It is a database-wide unique number. The storage size is 8
bytes. A table can have only one timestamp column. The
value in the timestamp column is updated every time a row
containing a timestamp column is inserted or updated. This
property makes a timestamp column a poor candidate for
keys, especially primary keys. Any update made to the row
changes the timestamp value, thereby changing the key
value. If the column is in a primary key, the old key value is
no longer valid, and foreign keys referencing the old value
are no longer valid. If the table is referenced in a dynamic
cursor, all updates change the position of the rows in the
cursor. If the column is in an index key, all updates to the
data row also generate updates of the index.
6. Correlated queries.
In correlated queries a sub query is executed for each row
the parent query is executed.
Ex:
Select e. * from EMP e where e.sal >(select Avg (Sal) from
emp where e.deptno = emp.deptno
11
Recursive triggers
Multiple triggers per
DELETE statement
INSERT,
UPDATE,
or
SQL-Server
Truncate & Delete
1.Truncate a table means data will be lost, but structure of
the table will be present in the database.
Syntax: Truncate table <table name>;
2.If you drop a table then the structure of the table also goes
along with the data.
Syntax: drop table <table name>;
3.You cant delete a table; you can delete the data in a
record wise manner.
Syntax: delete from <table name> where <condition>
4.The difference between the truncate and delete is you can
delete the data at a stretch buy using the truncate, by using
the delete you can delete only one record at a time.
5.When you have truncated the table then all the records will
lose. Then immediately if you add a record to that table the
row number will be 1 only.
Index:
13
14
Replication:
Definition:
Replication is an important and powerful technology for
distributing data and the execution of stored procedures
across an enterprise.
The replication technology allows you to make duplicate
copies of your data, move those copies to different locations,
and synchronize the data automatically so that all copies
have the same data values. Replication can be implemented
between databases on the same server or different servers
connected by LANs, WANs, or the Internet.
24.What are the types of replication?
Types of the replications:
Snapshot Replication
Option: Snapshot, with immediate-updating Subscribers
Transactional Replication
Option:
Transactional,
Subscribers
with
immediate-updating
Merge Replication
16
SQL-Server: Transact-SQL
Oracle: ANSI-SQL
28.Is it possible to create a view with out a base table?
Actually the answer is NO.
But this is possible by using the FORCED VIEWS
Syntax:
Create force view XYZ
As
Select * from ZZZ;
29.Index is the only second object, which holds data in the
database.
30. MODIFY is a keyword only it is not a clause.
31.What will happen if you add a not null constraint on to a
column if that column is already having the null values and
what is the status of those null values, which are already
present?
An error is given stating that null values are found.
32.I am doing a transaction, I am having four activities in
those four fourth activity got some problem, then will be the
transaction committed or roll backed?
Automatically it will rollback, because a transaction is said to
be committed when all the activities of that transaction is
perfectly executed.
Joins
33.What is a join?
34.How many types of joins are there?
35.What is the difference between the outer join and left
outer join?
17
18
19
seqno
20
21
SELECT *
FROM TableX a
WHERE 10 >= (SELECT COUNT(DISTINCT maxcol)
FROM tableX b
WHERE b.maxcol >= a.maxcol)
ORDER BY maxcol DESC;
How to implement if-then-else in a select statement?
The Oracle decode function acts like a procedural statement
inside an SQL statement to return different values or
columns based on the values of other columns in the select
statement.
Example:
select decode(sex, 'M', 'Male',
'F', 'Female',
'Unknown'
)
from employees;
Note: The decode function is not ANSI SQL and are rarely
implemented in other RDBMS offerings. It is one of the good
things about Oracle, but use it sparingly if portability is
required.
How can one dump/ examine the exact content of a
database column?
SELECT DUMP(col1)
FROM tab1
WHERE cond1 = val1;
DUMP(COL1)
------------------------------------Typ=96 Len=4: 65,66,67,32
22
For this example the type is 96, indicating CHAR, and the
last byte in the column is 32, which is the ASCII code for a
space. This tells us that this column is blank-padded.
Can one drop a column from a table?
Oracle does not provide a way to DROP a column.
1. update t1 set column_to_drop = NULL;
rename t1 to t1_base;
create view t1 as select <specific columns> from t1_base;
2. create table t2 as select <specific columns> from t1;
drop table t1;
rename t2 to t1;
Can one rename a column in a table?
No
1. rename t1 to t1_base;
create view t1 <column list with new name> as select *
from t1_base;
2. create table t2 <column list with new name> as select *
from t1;
drop table t1;
rename t2 to t1;
How can I change my Oracle password?
Issue the following SQL command: ALTER USER <username>
IDENTIFIED BY <new_password>
/
From Oracle8 you can just type "password" from SQL*Plus,
or if you need to change another user's password, type
"password user_name".
Workaround
columns
for
snapshots
on
tables
with
LONG
23
24