GeekInterview.com
Series: Subject: Topic:

SQL Server Interview Questions

Showing Questions 1 - 20 of 118 Questions
First | Prev | | Next | Last Page
Sort by: 
 | 

What are the advantages of views ?

Asked By: doodi | Asked On: Apr 9th, 2013

Answered by: rinusybase on: May 6th, 2013

Define frequently used joins, projections, and selections as views so that users need not specify all the conditions and qualifications each time an operation is performed on that data. Display diffe...

Answered by: rajeev kumar on: Apr 19th, 2013

if you have created view and if you want to update something in view it will also be update in table

Indexing on frequently updated table

Asked By: mahmoodbutt | Asked On: Apr 23rd, 2013

I was asked a question in an interview, where I was given a situation which is: i have registered to an online GAMIng website. It displays my rank on the basis of my score when I play a game. database table has 2 columns: 1. Username 2. Score. since the login page was loading very slowly so the programmers...

What is the datatype of null?

Asked By: kvmahesh99 | Asked On: Feb 26th, 2013

What is describe command in SQL server?

Asked By: Priya | Asked On: Aug 30th, 2006

What is its purpose?How to use it?

Star Read Best Answer

Editorial / Best Answer

Answered by: suji

View all questions by suji   View all answers by suji

Member Since Sep-2005 | Answered On : Nov 5th, 2011

Here are multiple ways to get the table information. The DESCRIBE command does not exist in MS SQL SERVER. This is an Oracle command used to describe the structure of objects within a given database. To achieve the same task in MSSQL Server, there are a series of stored procedures with the prefix SP_ that can be used. To view the structure of a table within the current database, use the command

Code
  1. sp_help 'TABLE_NAME';

If you would like to see more details, Create your custom procedure

Code
  1. CREATE procedure DESCRIBE
  2. (
  3. @tablename varchar(256)
  4. )
  5. AS
  6. begin
  7. SELECT DISTINCT sCols.colid AS 'order', sCols.name, sTyps.name, sCols.length
  8. FROM [syscolumns] sCols
  9. INNER JOIN [systypes] sTyps ON sCols.xtype = sTyps.xtype
  10. INNER JOIN [sysobjects] sObjs ON sObjs.id = sCols.[id]
  11. AND UPPER(sObjs.name) = UPPER(@tablename)
  12. ORDER BY sCols.colid
  13. end

Here is another alternative way to get the same information

Code
  1. sp_columns 'TableName' (e.g. sp_columns 'Employee')
  2. sp_columns [ @table_name = ] object [ , [ @table_owner = ] owner ]
  3. [ , [ @table_qualifier = ] qualifier ]
  4. [ , [ @column_name = ] COLUMN ]
  5. [ , [ @ODBCVer = ] ODBCVer ]

Here is the usage :

Code
  1. EXEC sp_columns @table_name = 'Department', @table_owner = 'sa';
  2. SELECT * FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = 'TableName'

Contributors for the editorial answer : Kewlshiva, srilakshmi.b, raaghav,kevaburg

Answered by: Saket Kale on: Oct 24th, 2012

sp_help dbo.customers;

worked for me just fine.

Thanks to the OP, this runs perfectly on SQL 2008 R2, do not know about other versions

Answered by: gangireddy on: Feb 22nd, 2012

To see the structure (description ) of the table in Sql Server the followed command surely works....
sp_help person

Note:***
to display the structure of the table in Sql Server wer use the followed command ...it has the accurate rating ****
sp_help
sp_help person

Can I update views in SQL

Asked By: rahul.solanke | Asked On: Jan 14th, 2012

Can I update views in SQL if yes in what scenarios? if your view is joining multiple tables

Answered by: abinay on: Oct 6th, 2012

yes,we can update the view as like a table.view is virtual table,basically it is not having any storage data. in a view data will be coming from table.if u delete the table .we wont update the view.

Answered by: Jean Daniel Joseph on: Jan 17th, 2012

Yes but you remember views, represents a virtual table but if you delete the table you wont be able to update the view

SQLdataadapter ,sqlcommand and SQLdatareader

Asked By: sunil thakur | Asked On: Jul 25th, 2012

What are difference between SQLdataadapter ,sqlcommand and SQLdatareader

Answered by: santhosh on: Aug 6th, 2012

sqldatareader means only read the datas in the table..
sqldataadapter means the datas read and writes

Write SQL query for retrieving employee names from employee table who are having salary greater than 5000 without using where clause?

Asked By: Ashok | Asked On: Jul 18th, 2006

Star Read Best Answer

Editorial / Best Answer

Answered by: Parished.D Chennai India

Answered On : Apr 24th, 2007

create table ee (eno int, ename varchar(200), sal int)

insert into ee values(1, 'a', 2000)
insert into ee values(2, 'b', 6000)
insert into ee values(3, 'c', 8000)

select ENO, ENAME, min(sal) AS SAL from ee group by eno,ename having min(sal) > 5000

Answered by: Venkat Rahul on: Jun 5th, 2012

select ename from emp group by ename,sal having sal>5000;

Answered by: Pushpa on: May 3rd, 2012

If we want to check any values to retrieve the data,case is the best.Case statement is simple and easy to understand.

Code
  1. SELECT case when sal>1000 then ename end
  2. FROM emp

How to remove duplicate records from a table?

Asked By: Beena | Asked On: Sep 19th, 2005

Answered by: Vijay on: May 10th, 2012

SELECT ID FROM TBLSAMPLE GROUP BY ID OR SELECT DISTINCT (ID) FROM TBLSAMPLE

Code
  1. SELECT ID FROM TBLSAMPLE GROUP BY ID
  2. OR
  3. SELECT DISTINCT (ID) FROM TBLSAMPLE

Answered by: Mally on: Feb 12th, 2012

Good Code...however the code will delete all the duplicates... you may want to add:

delete top(n) clause in your delete statement to exactly delete the required number of records.

Explain normalization and denormalization with examples?

Asked By: Beena | Asked On: Sep 19th, 2005

Answered by: siva on: Apr 27th, 2012

It is good.I understood if you put some brief explanation with data, is very usable to the persons who are not understanding about normalization like me. ...

Answered by: siva on: Apr 27th, 2012

Your Explnation may be good but it was too dificult to understand with out examples

How to find out duplicate records in SQL server?

Asked By: Srinu | Asked On: Apr 5th, 2006

Star Read Best Answer

Editorial / Best Answer

Answered by: Hanif

Answered On : Apr 12th, 2006

we have to use the group by with having command to get the duplicate values. this query shall show the result of only the users have duplicate values in the employee table.

Syntex:
Select columnName From Table_name
Group By columnName
Having count (*) > 1

Example:
SELECT  UserID FROM employee
GROUP BY userid
HAVING count( * ) > 1

Answered by: nandu on: Apr 26th, 2012

SELECT YourColumn, COUNT(*) TotalCount
FROM YourTable
GROUP BY YourColumn
HAVING COUNT(*) > 1
ORDER BY COUNT(*) DESC

Answered by: Ramakant Sahoo on: Dec 23rd, 2011

Code
  1. SELECT EMAIL, COUNT(*)  "REPETED EMAIL" FROM EMP GROUP BY EMAIL;

Can we replace where clause by having clause. ?

Asked By: bhushan13in | Asked On: Feb 14th, 2012

Interviewer ask.. Can we replace where clause by group by clause let say select * from table_name where some_condition so how we replace where clause by group by clause

Answered by: Mark Haynes on: Feb 16th, 2012

As a basic rule of query building: 1. The WHERE clause should be used to limit the number of rows returned by or affected by the a SQL statement. 2. The GROUP BY clause is used to group a selec...

Is there an import command in SQL 2008 for an excel spreadsheet?

Asked By: merlin1106 | Asked On: Nov 21st, 2011

Answered by: suji on: Jan 15th, 2012

From your SQL Server Management Studio, you open Object Explorer, go to your database where you want to load the data into, right click, then pick Tasks > Import Data. Select the options based on the excel file

How is the error handling in stored proc of T-SQL ?

Asked By: ajay_shu007 | Asked On: Jun 19th, 2008

1 how is the error handling in stored proc of T-SQL2 what is clustered index and non-clustered index? How many clustered indexes and non-clustered indexes can be created in one table? 3-what is disconnected mode?

Answered by: Pradeep Kumar Sharma on: Dec 25th, 2011

Begin Try

--
--
End Try
Begin Catch

Declare @errMsg varchar(1000),@errSev int
select @errMsg=error_message(),@errSev=error_severity()
RaisError(@errMsg,@errSev,1)

End Catch

Answered by: kirangiet on: Aug 16th, 2010

1) CLR is integrated in SQL Server 2005. Hence we can use below code for Exception Handling. BEGIN TRY SELECT * FROM Employees; END TRY BEGIN CATCH SELECT ERROR_NUMBER() ...

Representing SQL server objects

Asked By: polkam.raju | Asked On: Sep 23rd, 2009

How do represent objects in SQL server? Is it possible? If yes, how?If not? Why?

Answered by: Lokesh M on: Dec 12th, 2011

Try using Server Management Objects (SMO) classes

Covering indexes

Asked By: psingla | Asked On: Mar 9th, 2010

List down the advantage and disadvantages of covering indexes.

Answered by: Lokesh M on: Dec 12th, 2011

Covering Indexes are useful for Input / Output intensive workloads.
Covering indexes are smaller in size
Covering Indexes are sorted by values
It is easier to cache date in Covering Indexes

Covering Indexes cannot be used to select all the columns / entire table.

Run PL/SQL block from SQL server

Asked By: vrushali | Asked On: Jan 18th, 2011

How do you run PL/SQL block from SQL server

Answered by: Lokesh M on: Dec 12th, 2011

Try these and see...

Go To Options -> Run SQL
Set "Statement Delimiter" to None

Go To Options -> Technical Parameters
Tick "Use SQLExecDirect"

High water mark

Asked By: hkravipati | Asked On: Jul 9th, 2011

What is high water mark? Give an example where it can be useful ?

Answered by: Lokesh M on: Dec 12th, 2011

High Water Mark (HWM) represents total number of extent blocks used by a table. The value of High Water Mark could sometime be more then the actual size required/used by a table. This is because, some...

How to set GLobal setting for query studio?

Asked By: chandu22.csp | Asked On: Aug 24th, 2011

Answered by: Lokesh M on: Nov 28th, 2011

Steps to set / modify Global Setting for Query Studio: 1. Stop the Cognos 8|ReportNet server. 2. On the Cognos 8|ReportNet Server, go to the directory /c8|crn/templates/ps/async/ 3. Either create a n...

First | Prev | | Next | Last Page

 

 

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.