Wednesday, June 25, 2008

General SQL Questions

Q. What's the difference between a primary key and a unique key?
Ans - Both primary key and unique enforce uniqueness of the column on whichthey are defined. But by default primary key creates a clustered indexon the column, where are unique creates a nonclustered index bydefault. Another major difference is that, primary key doesn't allowNULLs, but unique key allows one NULL only.

Q . What are "user defined datatypes" ?
Ans - User defined datatypes is a good feature provided by SQL. User defined datatypes let you extend the base SQL Server datatypes byproviding a descriptive name, and format to the database. Take forexample, in your database, there is a column called Flight_Num whichappears in many tables. In all these tables it should be varchar(8).In this case you could create a user defined datatype calledFlight_num_type of varchar(8) and use it across all your tables.

Q. Define candidate key, alternate key, composite key.
Ans - 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 thetable has more than one candidate key, one of them will become theprimary key, and the rest are called alternate keys.
A key formed by combining at least two or more columns is calledcomposite key.

Q. What is a transaction and what are ACID properties?
Ans - A transaction is a logical unit of work in which, all the steps mustbe performed or none. ACID stands for Atomicity, Consistency,Isolation, Durability. These are the properties of a transaction. Formore information and explanation of these properties, see SQL Serverbooks online or any RDBMS fundamentals text book.

Q. What's the maximum size of a row?
Ans - 8060 bytes.

Just answer a simple question - What is the maximum number of columns per table?
Loking forward for your comments.

No comments: