5. What structure can you implement for the database to speed up table reads?- Follow the rules of DB tuning we have to: 1] properly use
indexes ( different types of indexes) 2] properly locate different DB objects across different tablespaces, files and so on.3] create a special space
(tablespace) to locate some of the data with special datatype ( for example CLOB, LOB and …)
6. What are the tradeoffs with having indexes? - 1. Faster selects, slower updates. 2. Extra storage space to store indexes. Updates are slower
because in addition to updating the table you have to update the index.
7. What is a "join"? - ‘join’ used to connect two or more tables logically with or without common field.
8. What is "normalization"? "Denormalization"? Why do you sometimes want to denormalize? - Normalizing data means eliminating
redundant information from a table and organizing the data so that future changes to the table are easier. Denormalization means allowing
redundancy in a table. The main benefit of denormalization is improved performance with simplified data retrieval and manipulation. This is done by
reduction in the number of joins needed for data processing.
9. What is a "constraint"? - A constraint allows you to apply simple referential integrity checks to a table. There are four primary types of constraints
that are currently supported by SQL Server: PRIMARY/UNIQUE - enforces uniqueness of a particular table column. DEFAULT - specifies a default
value for a column in case an insert operation does not provide one. FOREIGN KEY - validates that every value in a column exists in a column of
another table. CHECK - checks that every value stored in a column is in some specified list. Each type of constraint performs a specific type of action.
Default is not a constraint. NOT NULL is one more constraint which does not allow values in the specific column to be null. And also it the only
constraint which is not a table level constraint.
10. What types of index data structures can you have? - An index helps to faster search values in tables. The three most commonly used index-
types are: - B-Tree: builds a tree of possible values with a list of row IDs that have the leaf value. Needs a lot of space and is the default index type for
most databases. - Bitmap: string of bits for each possible value of the column. Each bit string has one bit for each row. Needs only few space and is very
fast.(however, domain of value cannot be large, e.g. SEX(m,f); degree(BS,MS,PHD) - Hash: A hashing algorithm is used to assign a set of characters to
represent a text string such as a composite of keys or partial keys, and compresses the underlying data. Takes longer to build and is supported by
relatively few databases.
11. What is a "primary key"? - A PRIMARY INDEX or PRIMARY KEY is something which comes mainly from
database theory. From its behavior is almost the same as an UNIQUE INDEX, i.e. there may only be one of each value in this column. If you call such
an INDEX PRIMARY instead of UNIQUE, you say something about
your table design, which I am not able to explain in few words. Primary Key is a type of a constraint enforcing uniqueness and data integrity for each
row of a table. All columns participating in a primary key constraint must possess the NOT NULL property.
12. What is a "functional dependency"? How does it relate to database table design? - Functional dependency relates to how one object
depends upon the other in the database. for example, procedure/function sp2 may be called by procedure sp1. Then we say that sp1 has functional
dependency on sp2.
13. What is a "trigger"? - Triggers are stored procedures created in order to enforce integrity rules in a database. A trigger is executed every time a
data-modification operation occurs (i.e., insert, update or delete). Triggers are executed automatically on occurance of one of the data-modification
operations. A trigger is a database object directly associated with a particular table. It fires whenever a specific statement/type of statement is issued
against that table. The types of statements are insert,update,delete and query statements. Basically, trigger is a set of SQL statements A trigger is a
solution to the restrictions of a constraint. For instance: 1.A database column cannot carry PSEUDO columns as criteria where a trigger can. 2. A
database constraint cannot refer old and new values for a row where a trigger can.
14. Why can a "group by" or "order by" clause be expensive to process? - Processing of "group by" or "order by" clause often requires creation of
Temporary tables to process the results of the query. Which depending of the result set can be very expensive.
15. What is "index covering" of a query? - Index covering means that "Data can be found only using indexes, without touching the tables"
16. What types of join algorithms can you have?
17. What is a SQL view? - An output of a query can be stored as a view. View acts like small table which meets our criterion. View is a precomplied SQL
query which is used to select data from one or more tables. A view is like a table but it doesn’t physically take any space. View is a good way to present
data in a particular format if you use that query quite often. View can also be used to restrict users from accessing the tables directly.
why you need indexing ? where that is stroed and what you mean by schema object? For what purpose we are using
view?
We cant create an Index on Index.. Index is stoed in user_index table.Every object that has been created on Schema is Schema
Object like Table,View etc.If we want to share the particular data to various users we have to use the virtual table for the Base
indexing is used for faster search or to retrieve data faster from various table. Schema containing set of tables, basically schema
means logical separation of the database. View is crated for faster retrieval of data. It's customized virtual table. we can create a
single view of multiple tables. Only the drawback is..view needs to be get refreshed for retrieving updated data.
• but trigger is automatically invoked when the action defined in trigger is done.
• Triggers are used to initiate a particular activity after fulfilling certain condition.It need to define and can be enable and
Triggers are fired implicitly on the tables/views on which they are created. There are various advantages of using a trigger. Some of
them are:
• Suppose we need to validate a DML statement(insert/Update/Delete) that modifies a table then we can write a trigger on
the table that gets fired implicitly whenever DML statement is executed on that table.
• Another reason of using triggers can be for automatic updation of one or more tables whenever a DML/DDL statement is
• Triggers can be used to enforce constraints. For eg : Any insert/update/ Delete statements should not be allowed on a
particular table after office hours. For enforcing this constraint Triggers should be used.
• Triggers can be used to publish information about database events to subscribers. Database event can be a system event
like Database startup or shutdown or it can be a user even like User loggin in or user logoff.
What the difference between UNION and UNIONALL?
Union will remove the duplicate rows from the result set while Union all does'nt.
Both will result in deleting all the rows in the table .TRUNCATE call cannot be rolled back as it is a DDL command and all memory
space for that table is released back to the server. TRUNCATE is much faster.Whereas DELETE call is an DML command and can be
rolled back.
Which system table contains information on constraints on all the tables created ?
yes,
USER_CONSTRAINTS,
Explain normalization ?
Normalisation means refining the redundancy and maintain stablisation. there are four types of normalisation :
first normal forms, second normal forms, third normal forms and fourth Normal forms.
How to find out the database name from SQL*PLUS command prompt?
This will give the datbase name which u r currently connected to.....
whereas
Structured Query Language (SQL), pronounced "sequel", is a language that provides an interface to relational database
systems. It was developed by IBM in the 1970s for use in System R. SQL is a de facto standard, as well as an ISO and ANSI
What is diffrence between Co-related sub query and nested sub query?
Correlated subquery runs once for each row selected by the outer query. It contains a reference to a value from the row selected
Nested subquery runs only once for the entire nesting (outer) query. It does not contain any reference to the outer query row.
For example,
Correlated Subquery:
select e1.empname, e1.basicsal, e1.deptno from emp e1 where e1.basicsal = (select max(basicsal) from emp e2 where e2.deptno
= e1.deptno)
Nested Subquery:
select empname, basicsal, deptno from emp where (deptno, basicsal) in (select deptno, max(basicsal) from emp group by deptno)
Pattern matching operator is LIKE and it has to used with two attributes
1. % and
2. _ ( underscore )
% means matches zero or more characters and under score means mathing exactly one character
Oracle's features for distributed transactions, materialized views and replication are not available with MS Access. These features
enable Oracle to efficiently store data for multinational companies across the globe. Also these features increase scalability of
What is database?
A database is a collection of data that is organized so that itscontents can easily be accessed, managed and updated. open this
url : http://www.webopedia.com/TERM/d/database.html
Clustered Index:- A Clustered index is a special type of index that reorders the way records in the table are physically stored.
Therefore table may have only one clustered index.Non-Clustered Index:- A Non-Clustered index is a special type of index in which
the logical order of the index does not match the physical stored order of the rows in the disk. The leaf nodes of a non-clustered
index does not consists of the data pages. instead the leaf node contains index rows.
What are the advantages and disadvantages of primary key and foreign key in SQL?
Primary key
Advantages
1) It is a unique key on which all the other candidate keys are functionally dependent
Disadvantage
1) There can be more than one keys on which all the other attributes are dependent on.
Foreign Key
Advantage
1)It allows refrencing another table using the primary key for the other table
Which date function is used to find the difference between two dates?
datediff
output is 5
Check out the article Q100139 from Microsoft knowledge base and of
course, there's much more information available in the net. It'll be a
good idea to get a hold of any RDBMS fundamentals text book,
especially the one by C. J. Date. Most of the times, it will be okay
if you can explain till third normal form.
Both primary key and unique enforce uniqueness of the column on which
they are defined. But by default primary key creates a clustered index
on the column, where are unique creates a nonclustered index by
default. Another major difference is that, primary key doesn't allow
NULLs, but unique key allows one NULL only.
What are user defined datatypes and when you should go for them?
User defined datatypes let you extend the base SQL Server datatypes by
providing a descriptive name, and format to the database. Take for
example, in your database, there is a column called Flight_Num which
appears in many tables. In all these tables it should be varchar(8).
In this case you could create a user defined datatype called
Flight_num_type of varchar(8) and use it across all your tables.
What is bit datatype and what's the information that can be stored
inside a bit column?
A candidate key is one that can identify each row of a table uniquely.
Generally a candidate key becomes the primary key of the table. If the
table has more than one candidate key, one of them will become the
primary key, and the rest are called alternate keys.
Back to top
SQL Server architecture (top)
What type of Index will get created after executing the above statement?
What's the difference between DELETE TABLE and TRUNCATE TABLE commands?
Check out MOLAP, ROLAP and HOLAP in SQL Server books online for more
infomation.
What are the new features introduced in SQL Server 2000 (or the latest
release of SQL Server at the time of your interview)? What changed
between the previous version of SQL Server and the current version?
Types of constraints: NOT NULL, CHECK, UNIQUE, PRIMARY KEY, FOREIGN KEY
For an explanation of these constraints see books online for the pages
titled: "Constraints" and "CREATE TABLE", "ALTER TABLE"
Whar is an index? What are the types of indexes? How many clustered
indexes can be created on a table? I create a separate index on each
column of a table. what are the advantages and disadvantages of this
approach?
Indexes in SQL Server are similar to the indexes in books. They help
SQL Server retrieve the data quicker.
Back to top
Database administration (top)
What are the steps you will take to improve performance of a poor
performing query?
This is a very open ended question and there could be a lot of reasons
behind the poor performance of a query. But some general issues that
you could talk about would be: No indexes, table scans, missing or out
of date statistics, blocking, excess recompilations of stored
procedures, procedures and triggers without SET NOCOUNT ON, poorly
written query with unnecessarily complicated joins, too much
normalization, excess usage of cursors and temporary tables.
Some of the tools/ways that help you troubleshooting performance
problems are: SET SHOWPLAN_ALL ON, SET SHOWPLAN_TEXT ON, SET
STATISTICS IO ON, SQL Server Profiler, Windows NT /2000 Performance
monitor, Graphical execution plan in Query Analyzer.
What are the steps you will take, if you are tasked with securing an
SQL Server?
Again this is another open ended question. Here are some things you
could talk about: Preferring NT authentication, using server, databse
and application roles to control access to the data, securing the
physical database files using NTFS permissions, using an unguessable
SA password, restricting physical access to the SQL Server, renaming
the Administrator account on the SQL Server computer, disabling the
Guest account, enabling auditing, using multiprotocol encryption,
setting up SSL, setting up firewalls, isolating SQL Server from the
web server etc.
Read the white paper on SQL Server security from Microsoft website.
Also check out My SQL Server security best practices
What is a deadlock and what is a live lock? How will you go about
resolving deadlocks?
How to restart SQL Server in single user mode? How to start SQL Server
in minimal configuration mode?
SQL Server can be started from command line, using the SQLSERVR.EXE.
This EXE has some very important parameters with which a DBA should be
familiar with. -m is used for starting SQL Server in single user mode
and -f is used to start the SQL Server in minimal confuguration mode.
Check out SQL Server books online for more parameters and their
explanations.
As a part of your job, what are the DBCC commands that you commonly
use for database maintenance?
What are statistics, under what circumstances they go out of date, how
do you update them?
Look up SQL Server books online for the following commands: UPDATE
STATISTICS, STATS_DATE, DBCC SHOW_STATISTICS, CREATE STATISTICS, DROP
STATISTICS, sp_autostats, sp_createstats, sp_updatestats
There are lots of options available, you have to choose your option
depending upon your requirements. Some of the options you have are:
BACKUP/RESTORE, dettaching and attaching databases, replication, DTS,
BCP, logshipping, INSERT...SELECT, SELECT...INTO, creating INSERT
scripts to generate data.
Types of backups you can create in SQL Sever 7.0+ are Full database
backup, differential database backup, transaction log backup,
filegroup backup. Check out the BACKUP and RESTORE commands in SQL
Server books online. Be prepared to write the commands in your
interview. Books online also has information on detailed
backup/restore architecture and when one should go for a particular
kind of backup.
* Snapshot replication
* Transactional replication (with immediate updating subscribers,
with queued updating subscribers)
* Merge replication
Back to top
Database programming (top)
What are cursors? Explain different types of cursors. What are the
disadvantages of cursors? How can you avoid cursors?
Disadvantages of cursors: Each time you fetch a row from the cursor,
it results in a network roundtrip, where as a normal SELECT query
makes only one rowundtrip, however large the resultset is. Cursors are
also costly because they require more resources and temporary storage
(results in more IO operations). Furthere, there are restrictions on
the SELECT statements that can be used with some types of cursors.
If you have to give a flat hike to your employees using the following
criteria:
Write down the general syntax for a SELECT statements covering all the
options.
Here's the basic syntax: (Also checkout SELECT in books online for
advanced syntax).
SELECT select_list
[INTO new_table_]
FROM table_source
[WHERE search_condition]
[GROUP BY group_by__expression]
[HAVING search_condition]
[ORDER BY order__expression [ASC | DESC] ]
Types of joins: INNER JOINs, OUTER JOINs, CROSS JOINs. OUTER JOINs are
further classified as LEFT OUTER JOINS, RIGHT OUTER JOINS and FULL
OUTER JOINS.
For more information see pages from books online titled: "Join
Fundamentals" and "Using Joins".
Yes, very much. Check out BEGIN TRAN, COMMIT, ROLLBACK, SAVE TRAN and
@@TRANCOUNT
Yes, you can instantiate a COM (written in languages like VB, VC++)
object from T-SQL by using sp_OACreate stored procedure. Also see
books online for sp_OAMethod, sp_OAGetProperty, sp_OASetProperty,
sp_OADestroy. For an example of creating a COM object in VB and
calling it from T-SQL, see 'My code library' section of this site.
What is the system function to get the current user's user id?
What are triggers? How many triggers you can have on a table? How to
invoke a trigger on demand?
In SQL Server 6.5 you could define only 3 triggers per table, one for
INSERT, one for UPDATE and one for DELETE. From SQL Server 7.0
onwards, this restriction is gone, and you could create multiple
triggers per each action. But in 7.0 there's no way to control the
order in which the triggers fire. In SQL Server 2000 you could specify
which trigger fires first or fires last using sp_settriggerorder
Till SQL Server 7.0, triggers fire only after the data modification
operation happens. So in a way, they are called post triggers. But in
SQL Server 2000 you could create pre triggers also. Search SQL Server
2000 books online for INSTEAD OF triggers.
Also check out books online for 'inserted table', 'deleted table' and
COLUMNS_UPDATED()
There is a trigger defined for INSERT operations on a table, in an
OLTP system. The trigger is written to instantiate a COM object and
pass the newly insterted rows to it for some custom processing. What
do you think of this implementation? Can this be implemented better?
Self join is just like any other join, except that two instances of
the same table will be joined in the query. Here is an example:
Employees table which contains rows for normal employees as well as
managers. So, to find out the managers of all the employees, you need
a self join.
Here's an advanced query using a LEFT OUTER JOIN that even returns the
employees without managers (super bosses)