GeekInterview.com
Answered Questions

Changing rows into colums

Asked By: karthizen | Asked On: May 28th, 2008

How to change rows to columns and columns into rows?

Answered by: Santhoshkandula on: May 11th, 2011

create table #temptable(rowid int,colorname varchar(25),Hexa varchar(7),R tinyint,G tinyint,B tinyint) GO insert into #temptable values(1,'Violet','#8B00FF',139,0,255); insert into #te...

Answered by: krishnaindia2007 on: Jun 20th, 2008

Use decode function.

What is the effect of 'delete' on primary key and foreign key

Asked By: saritha_racharla | Asked On: Nov 20th, 2007

Answered by: Santhoshkandula on: May 18th, 2011

when you have to delete the records on primary key and foreigh key then there is problem will hapen as primary key violation

at that time you have to provide delete rules when you create the tables
those are

1. on delete no action
2. on delete cascade
3. on delete set null
4. on delete set default

Answered by: caveatashish on: Dec 14th, 2007

For primary key if that record is being refered by some other (Child Table)  sql server won't let you to delete that record.While creating relationship if you had mention "Dele...

How to delete records from two tables. There is relationship between two tables.

Asked By: kathir | Asked On: Nov 14th, 2007

It's working in MySQL but not in SQL-server.

Answered by: Santhoshkandula on: May 18th, 2011

  For deleting the records from the relational tables there are 4 options available. These options can be used when you create the tables then you have to use these options and create tables and ...

Answered by: caveatashish on: Dec 14th, 2007

Use a procedure which will delete record from child table first and then it will delete the same record from parent table

Same thing can be achieved using cascade delete and cascade update, this feature was not there in sql server 7.0

Query to find the list of employees age > 30

Asked By: rekssql | Asked On: Jan 11th, 2007

Write a query to find the list of employees whos age is greater than 30 or so given a date of birth column

Answered by: maninder singh on: Apr 9th, 2012

Please tell me,
How to get age of all employee by using query

Answered by: Santhoshkandula on: May 18th, 2011



      SELECT *,DATEDIFF(YY,,GETDATE()) AS AGE FROM WHERE DATEDIFF(YY,,GETDATE()) > 30




  Thanks & Regards
  K.santhosh

Can I retrieve column name using the column number of that column in the table? If yes then how?

Asked By: deshaniprashant | Asked On: Apr 17th, 2006

Answered by: Santhoshkandula on: May 11th, 2011


   No, It's not possible because select statement only selects the values.



   Thanks & Regards 
   K.Santhosh

Answered by: RK on: Apr 24th, 2006

FOR EXAMPLE TO RETRIEVE 2ND COLUMN(ENAME)  IN EMP TABLE:

SELECT COLUMN_NAME FROM USER_TAB_COLUMNS

WHERE TABLE_NAME ='EMP'

AND COLUMN_ID = 2

Syntax for getting the table witout any contents

Asked By: deeptipreeti | Asked On: Mar 29th, 2006

Answered by: sampra on: Mar 6th, 2012

create table emp as select * from student where 1=2;

Answered by: Satish Kopalle on: Jun 7th, 2011

select * from faculty where rownum=0;

Is there any way we can change the column name in a table

Asked By: sheela | Asked On: Nov 23rd, 2005

Star Read Best Answer

Editorial / Best Answer

Answered by: Praveena

Answered On : Dec 14th, 2005

Yes we can alter Column name in a table using the following query:

alter table <tablename> rename column <old Column Name> to <New Column Name>

Regards,

Praveena

 

 

Answered by: dude_8550 on: Jun 15th, 2011

u can change the column name and also column definition that is whether the data type and its size by the ALTER command.

ALTER TABLE RENAME COLUMN <old column name> TO <new coumn name>;

Answered by: Santhoshkandula on: May 11th, 2011


   yes, it's possible to change the column name by using the following query in SQL server


       SP_RENAME ' <TABLE_NAME.OLD_COLUMN_NAME> ' , ' NEW_COLUMN_NAME '



   Thanks & Regards
    K.Santhosh

When do you use where clause and when do you use having clause?

Asked By: Interview Candidate | Asked On: Aug 29th, 2004

Having clause is used when you want to specify a condition for a group function and it is written after group by clause. The where clause is used when you want to specify a condition for columns, single row functions except group functions and it is written before group by clause if it is used.

Answered by: Santhoshkandula on: May 11th, 2011



   we have to apply the condition Before grouping the records then you have to use WHERE clause.
   we have to apply the condition after grouping the records then you have to apply HAVING clause.


  Thanks & Regards

    K.Santhosh

Answered by: anupsunder92 on: Jun 10th, 2010

The WHERE clause is a conditional construct used to restrict or limit rows based on some condition.If the condition is satisfied then the filtered rows are returned as output.  Consider this exam...

What are various joins used while writing subqueries?

Asked By: Interview Candidate | Asked On: Jul 27th, 2005

Self join-its a join foreign key of a table references the same table. Outer join--its a join condition used where one can query all the rows of one of the tables in the join condition even though they don't satisfy the join condition.Equi-join--its a join condition that retrieves rows from one or more...

Answered by: Santhoshkandula on: May 11th, 2011

    
    There are 5 types of joins. Those  are

   1. Equi Join /  Inner Join
   2. Non-Equi Join
   3. Outer Join ( Left Outer Join, Right Outer Join, Full Outer Join )
   4. Self Join
   5. Cross Join

Answered by: thirupathireddy on: Feb 2nd, 2010

Two join conidtion we can use for subqueries:
Equi Join,
Self Join

Interview Question

 Ask Interview Question?

 

Career Counselling

 Have Career Question?

 Ask Chandra

 Ask Only Career questions.

Follow us: