0% found this document useful (0 votes)
87 views4 pages

Define Candidate Key, Alternate Key, Composite Key.: Atomicity

A candidate key uniquely identifies rows in a table and can become the primary key. Alternate keys are other candidate keys not used as the primary key. A composite key is formed from multiple columns. A transaction ensures data integrity by having ACID properties - Atomicity, Consistency, Isolation, and Durability. Atomicity means all changes succeed or fail together. Consistency means transactions leave data valid. Isolation means transactions don't see other's uncommitted changes. Durability means committed changes persist after failures.

Uploaded by

rajeshlivetech
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
87 views4 pages

Define Candidate Key, Alternate Key, Composite Key.: Atomicity

A candidate key uniquely identifies rows in a table and can become the primary key. Alternate keys are other candidate keys not used as the primary key. A composite key is formed from multiple columns. A transaction ensures data integrity by having ACID properties - Atomicity, Consistency, Isolation, and Durability. Atomicity means all changes succeed or fail together. Consistency means transactions leave data valid. Isolation means transactions don't see other's uncommitted changes. Durability means committed changes persist after failures.

Uploaded by

rajeshlivetech
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 4

Define candidate key, alternate key, composite key.

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.
A key formed by combining at least two or more columns is called
composite key.
What is a transaction and what are ACID properties?
A transaction is a logical unit of work in which, all the steps must be
performed or none. ACID stands for Atomicity, Consistency, Isolation,
Durability. These are the properties of a transaction. For more
information and explanation of these properties, see SQL Server books
online or any RDBMS fundamentals text book.
Atomicity
A transaction must be an atomic unit of work; either all of its data modifications are
performed, or none of them is performed.
Consistency
When completed, a transaction must leave all data in a consistent state. In a relational
database, all rules must be applied to the transaction's modifications to maintain all data
integrity. All internal data structures, such as B-tree indexes or doubly-linked lists, must
be correct at the end of the transaction.
Isolation
Modifications made by concurrent transactions must be isolated from the modifications
made by any other concurrent transactions. A transaction either sees data in the state it
was in before another concurrent transaction modified it, or it sees the data after the
second transaction has completed, but it does not see an intermediate state. This is
referred to as serializability because it results in the ability to reload the starting data and
replay a series of transactions to end up with the data in the same state it was in after the
original transactions were performed.
Durability
After a transaction has completed, its effects are permanently in place in the system. The
modifications persist even in the event of a system failure.
CREATE INDEX myIndex ON myTable(myColumn)

What type of Index will get created after executing the above statement?
Non-clustered index. Important thing to note: By default a clustered
index gets created on the primary key, unless specified otherwise.
What's the maximum size of a row?
8060 bytes. Don't be surprised with questions like 'what is the
maximum number of columns per table'. Check out SQL Server books
online for the page titled: "Maximum Capacity Specifications".
What's the difference between DELETE TABLE and TRUNCATE TABLE
commands?
DELETE TABLE is a logged operation, so the deletion of each row gets
logged in the transaction log, which makes it slow. TRUNCATE TABLE
also deletes all the rows in a table, but it won't log the deletion of each
row, instead it logs the deallocation of the data pages of the table,
which makes it faster. Of course, TRUNCATE TABLE can be rolled back.
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?
This question is generally asked to see how current is your knowledge.
Generally there is a section in the beginning of the books online titled
"What's New", which has all such information. Of course, reading just
that is not enough, you should have tried those things to better answer
the questions. Also check out the section titled "Backward
Compatibility" in books online which talks about the changes that have
taken place in the new version.
What are constraints? Explain different types of constraints.
Constraints enable the RDBMS enforce the integrity of the database
automatically, without needing you to create triggers, rule or defaults.
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.
Indexes are of two types. Clustered indexes and non-clustered indexes.
When you craete a clustered index on a table, all the rows in the table
are stored in the order of the clustered index key. So, there can be only
one clustered index per table. Non-clustered indexes have their own

storage separate from the table data storage. Non-clustered indexes


are stored as B-tree structures (so do clustered indexes), with the leaf
level nodes having the index key and it's row locater. The row located
could be the RID or the Clustered index key, depending up on the
absence or presence of clustered index on the table.
If you create an index on each column of a table, it improves the query
performance, as the query optimizer can choose from all the existing
indexes to come up with an efficient execution plan. At the same t ime,
data modification operations (such as INSERT, UPDATE, DELETE) will
become slow, as every time data changes in the table, all the indexes
need to be updated. Another disadvantage is that, indexes need disk
space, the more indexes you have, more disk space is used.
Explian different types of BACKUPs avaialabe in SQL Server? Given a
particular scenario, how would you go about choosing a backup plan?
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
What is a self join? Explain it with an example.
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.
CREATE TABLE emp
(
empid int,
mgrid int,
empname char(10)
)
INSERT
INSERT
INSERT
INSERT
INSERT

emp
emp
emp
emp
emp

SELECT
SELECT
SELECT
SELECT
SELECT

1,2,'Vyas'
2,3,'Mohan'
3,NULL,'Shobha'
4,2,'Shridhar'
5,2,'Sourabh'

SELECT t1.empname [Employee], t2.empname [Manager]


FROM emp t1, emp t2
WHERE t1.mgrid = t2.empid

How to programmatically find out when the SQL Server service started? <top>
Everytime SQL Server starts, it recreates the tempdb database. So, the
creation date and time of the tempdb database tells us the date and
time at which SQL Server service started. This information is stored in
the crdate column of the sysdatabases table in master database.
Here's the query to find that out:
SELECT crdate AS 'SQL Server service started approximately
at:'
FROM master.dbo.sysdatabases
WHERE name = 'tempdb'
How to get rid of the time part from the date returned by GETDATE function?
<top>
We have to use the CONVERT function to strip the time off the date.
Any of the following commands will do this:
SELECT
SELECT
SELECT
SELECT

CONVERT(char,GETDATE(),101)
CONVERT(char,GETDATE(),102)
CONVERT(char,GETDATE(),103)
CONVERT(char,GETDATE(),1)

How to get the first day of the week, last day of the week and last day of the
month using T-SQL date functions? <top>
Here's the code:
DECLARE @Date datetime
SET @Date = '2001/08/31'
SELECT DATEADD(dd,-(DATEPART(dw, @Date) - 1),@Date) AS
'First day of the week'
SELECT DATEADD(dd,-(DATEPART(dw, @Date) - 7),@Date) AS 'Last
day of the week'
SELECT DAY(DATEADD(d,
-DAY(DATEADD(m,1,@Date)),DATEADD(m,1,@Date))) AS 'Last day
of the month'

You might also like