GeekInterview.com
Series: Subject: Topic:

SQL Interview Questions

Showing Questions 1 - 6 of 6 Questions
Sort by: 
 | 

Difference between cluster and non-cluster index?

Asked By: bsush | Asked On: Oct 17th, 2006

Star Read Best Answer

Editorial / Best Answer

Answered by: Sushant

Answered On : Oct 25th, 2006

The difference is that, Clustered index is unique for any given table and we can have only one clustered index on a table. The leaf level of a clustered index is the actual data and the data is resorted in case of clustered index. Whereas in case of non-clustered index the leaf level is actually a pointer to the data in rows so we can have as many non-clustered indexes as we can on the db.

Answered by: Sameer on: Nov 1st, 2012

now SQL SERVER 2008 onwards we can have 1 cluster index and 999 non cluster index on one table.

Answered by: primarykey2000 on: Apr 22nd, 2008

clustered index  - the index order matches the order of physically stored data.cluster index can be used on table that doent get changes frequentlyusing DML statement on cluster index column have...

Difference between varchar and varchar2?

Asked By: Sreyas | Asked On: Feb 23rd, 2006

Star Read Best Answer

Editorial / Best Answer

Answered by: muralidhar_batta

View all answers by muralidhar_batta

Member Since Feb-2006 | Answered On : Feb 26th, 2006

varchar means fixed length character data(size) ie., min size-1 and max-2000

where as varchar2 means variable length character data ie., min-1 to max-4000

Answered by: Ravi on: Jul 13th, 2012

Varchar & Varchar2 both having the same size, & working as same.
Bt the main diff is varchar is an ANSI Datatype & Varchar2 is the Oracle datatype.

Answered by: pooja manoja on: Feb 4th, 2012

Varchar - If we declare datatype as varchar then it will occupy space for null values. It can store upto 2000 bytes of character.

Varchar2 - If we declare datatype as varchar2, it will not occupy any space. It can store 4000 bytes of character.

Thanx,

How do you print the last n rows or the first n rows of a table ?

Asked By: bharaniprasanth | Asked On: Mar 3rd, 2008

Star Read Best Answer

Editorial / Best Answer

Answered by: nirmal1in

View all questions by nirmal1in   View all answers by nirmal1in

Member Since Jan-2010 | Answered On : Jan 16th, 2010

This can be accomplished in following way:

Example: table - emp

For First n rows:

SELECT * FROM
(SELECT empno,ename,job,row_number() over (order by ename desc) a
FROM emp) x
WHERE x.a < 5 --- say n is 5 display first 5 records

For last n rows:

SELECT * FROM
(SELECT empno,ename,job,row_number() over (order by ename) a
FROM emp) x
WHERE x.a < 5

FROM )WHERE .a<

This query can be used for finding nth row also say n = 5

SELECT * FROM
(SELECT empno,ename,job,row_number() over (order by ename desc) a
FROM emp) x
WHERE x.a = 5

Answered by: deepthi on: May 17th, 2012

Code
  1. SELECT rownum,a.*FROM(SELECT rownum,b.*FROM emp b ORDER BY rownum DESC) a WHERE rownum <&n;

Answered by: Vasavi Katakam on: Jul 18th, 2011

For First N Rows:

Code
  1.  
  2. SELECT top 5 * FROM table_name
  3.  

For Last N Rows:

Code
  1.  
  2. SELECT * FROM
  3. (SELECT top 5 * FROM
  4. table_name
  5. ORDER BY Columnname DESC)
  6. ORDER BY Columnname ASC
  7.  

What is the main use of foreign key?

Asked By: ramesh_etta | Asked On: Nov 8th, 2006

Star Read Best Answer

Editorial / Best Answer

Answered by: MANAS KUMAR ROUT ( USA ) (TCS) (Eli LILLY ) - PFIZ

Answered On : Jul 5th, 2007

Hey Ramesh,

I understand your interviewer's enthusiasm to know about the Foreign Key.  See foreign key definitions says its states the relationship of one attribute(Column) of one table to the corresponding column on the other table.

So one os a parent and other is child. PARENT is that table which holds the primary key and CHILD is table which holds the referential key. Hence every entry in the PRIMARY table is unique where as same entry might be repeating in the child table. BUT that same has to be present in the PARENT table (Primary KEY).

Now Going by definition Foreign key can be of two types :
========================================
1.  ON DELETE SET NULL
2.  ON DELETE SET CASCADE

DETAILS:
=======
On delete set null :
=======
When a foreign key is created by on delete set null definition then when you delete one row from the primary column (of parent table ) , then the corresponding entry in the foreign key table (Child table ) have the value "NULL" for that particular column.


ON Delete Set Cascade:
================
When the foreign key is created by this definition then when you delete the primary column (any one row -unique data) , then the Child table forcefully deletes all the rows in the child table having same value for that particular column.


I hope u got the crux of the Foreign key
Thanks
Manas Kumar Rout
SAS Consultant
Oracle Certified Associate
Unix Consultant

Answered by: shweta dhumal on: Sep 8th, 2011

foreign key is primary key of other table. for example: 'STUDENT' is one table which stores information about students and 'SID' is primary key in that table and 'MARKS' is another table which stor...

Answered by: shweta dhumal on: Sep 8th, 2011

The purpose of the foreign key is to ensure referential integrity of the data. In other words, only values that are supposed to appear in the database are permitted. For example, say we have two tab...

What is dual table?

Asked By: kumaranvp | Asked On: Jul 12th, 2008

What is dual table which is used as a table in SQL...

Star Read Best Answer

Editorial / Best Answer

Answered by: svsraju81

View all answers by svsraju81

Member Since Jul-2008 | Answered On : Jul 24th, 2008

Dual table is a temporary table, it contains a single row and single column. If we return a data from dual table it gives a single row.

Answered by: sudipta kumar dhal on: Sep 5th, 2011

Dual table is called a dummy table because it is not meant for storing any useful data.

Answered by: d_pranjal on: Sep 5th, 2010

Dual table is owned by SYS. Data dictionary come under SYS, dual is part of data dictionary. Dual table consist only one row and only one column containing value x

Recent row entered

Asked By: akbarali | Asked On: Jun 17th, 2008

I have a very unusual question, how can one check which is the recent row added to a table?

Star Read Best Answer

Editorial / Best Answer

Answered by: biswaranjanbehera

View all answers by biswaranjanbehera

Member Since Jul-2008 | Answered On : Aug 6th, 2008

We can select the recent row enrtered by using the query below.
suppose the table name is employee;
then.
select * from employee where rowid=(select max(rowid) from employee).
This works fine because rowid is assigned for each and every record and in accending order. So the recent record's rowid is the man (rowid). Please send feedback with any concern.

Answered by: bulat on: May 31st, 2010

"Although a rowid uniquely identifies a row in a table, it might change its value if the underlying table is an index organized table or a partitioned table." Also rowid stores information a...

Answered by: dachi316 on: Aug 26th, 2009

SCOPE_IDENTITY() would be a better option to get the most recently added row as the primary key for a table may not necessarily be an auto-incrementing variable. Therefore max(rowid) would not be the optimal solution in that case.

Ads

Connect

twitter fb Linkedin GPlus RSS

Ads

Interview Question

 Ask Interview Question?

 

Latest Questions

Ads

Interview & Career Tips

Get invaluable Interview and Career Tips delivered directly to your inbox. Get your news alert set up today, Once you confirm your Email subscription, you will be able to download Job Inteview Questions Ebook . Please contact me if you there is any issue with the download.