GeekInterview.com
Series: Subject: Topic:

SQL Server Interview Questions

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

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...

Answered by: Bhanu on: Sep 1st, 2014

Why don't you create both non clustered indexes in one non clustered index.Please let me know on your performance.

How to configure ssis package in SQL server 2008 r2?

Asked By: prettyparamesh | Asked On: Feb 21st, 2012

Answered by: murali chennupati on: Jul 4th, 2014

From jobs->new->step->categories->ssis->select db->select the package & schedule.

What is the difference between SQL server,database server and Oracle server?

Asked By: slaser | Asked On: Oct 10th, 2006

Answered by: mbhsye786 on: Jan 13th, 2014

Your answer is incorrect
Sql Server runs only on windows platform and is hardware dependent
where as
Oracle runs in any platform and hardware independent such as can run on unix and windows.

Answered by: Sivaram on: Dec 31st, 2006

Basic DifferenceSql Server:Runs only on windows platform,Hardware independentoracle:Runs in any platform and hardware dependent..

Full, simple and bulk log recovery models

Asked By: sharath206 | Asked On: Mar 5th, 2008

What is the difference between the full, simple and bulk log recovery models?

Answered by: mbhsye786 on: Jan 13th, 2014

Full recovery model: This model requires log backups, no data is lots due to lost of data file, can be recover data up to point of failure. Bulk Log recovery model: Requires log backups. It is simila...

Answered by: LGSGEEK on: Mar 29th, 2008

SIMPLE: Uses full or differential copies of the database. Truncates the transaction logs automatically. Does not backup the transaction log file(s). Changes made after the last backup cannot be re...

What is the datatype of null?

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

Answered by: Sharanjit kaur on: Nov 29th, 2013

String

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: tinku981 on: Jun 16th, 2013

View can only be updated if it is a simple view. In case you are using INSTEAD OF trigger, simplex or complex view can be updated.

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.

What are the advantages of views ?

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

Answered by: Techiee on: Jun 12th, 2013

1. Hiding Unwanted(users do not have right to see those columns e.g login, password column in table) columns from the user.

2. Reduce the complexity of tables from using joins etc. in your query.

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...

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_helpsp_help person

Server 2003 restore point

Asked By: chiplevelerchandu | Asked On: Dec 14th, 2010

How to create restore point in server 2003?

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

Define unique key in SQL server

Asked By: kathiravan_g | Asked On: Mar 17th, 2008

How to define unique key in table? Is it possible to define one primary key and one unique key in a single table?

Answered by: erik on: Jul 21st, 2012

SQL UNIQUE key... The UNIQUE constraint uniquely identifies each record in a database table. The UNIQUE and PRIMARY KEY constraints both provide a guarantee for uniqueness for a column or set of col...

Answered by: pavan on: Jul 27th, 2011

If a column allows the duplication once is known as a unique key.i.e; Unique Key allows duplication once.But, Primary Key will not allow duplication. "mysql CREATE TABLE Employee (...

Self join

Asked By: karimrdd | Asked On: Mar 10th, 2010

Explain self join with the help of an example?

Answered by: SUNIL JUHI NEHA SINGH on: Jun 28th, 2012

Self Join=It is being defined as a table joins to itself. Example as below, Imagine this Table.. E_ID E_NAME M_ID 111 SUNIL NULL 112 RAKESH 111 113 NEHA 112 114 JUHI 113 ...

Answered by: psingla on: Mar 19th, 2010

joining a table to itself using alias.select * from table_name t1inner inner join table_name t2on t1.x=t2.y

SQL server

Asked By: varun.dtsfi | Asked On: May 24th, 2012

In which scenario I can use the unique key and primary key in SQL server . i mean in real life database how can I judge where I have to use the unique key and primary key.

Answered by: sunil neha juhi singh on: Jun 28th, 2012

Primary key=not allow null values,create cluster index by default.
unique key=allow only one null values and by default it create non cluster index

Answered by: kushgudseva on: May 29th, 2012

A Unique ID and Primary Key Constrain perform the ability to allow unique data in the column but only the Unique constrain allows NULL values in the field along with the unique data. Primary Key constrain fields allow Unique and Not NULL values.

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;

What is query of display the all tables in SQL server ?

Asked By: Interview Candidate | Asked On: Nov 24th, 2006

Star Read Best Answer

Editorial / Best Answer

Answered by: santanukd

View all answers by santanukd

Member Since May-2008 | Answered On : May 14th, 2009

Just replace "[your-schema-name-here]" in the following query with your schema name. Hope it comes handy to some of you out there.


Select OBJECT_TYPE,OBJECT_NAME
FROM
(
Select 'TABLE' as OBJECT_TYPE, TABLE_NAME as OBJECT_NAME, TABLE_SCHEMA as OBJECT_SCHEMA from information_schema.VIEWS
Union
Select 'VIEW' as OBJECT_TYPE, TABLE_NAME as OBJECT_NAME, TABLE_SCHEMA as OBJECT_SCHEMA from information_schema.VIEWS
Union
Select 'INDEX[Type:Name:Table]' as OBJECT_TYPE, concat(CONSTRAINT_TYPE,' : ',CONSTRAINT_NAME,' : ',TABLE_NAME) as OBJECT_NAME,TABLE_SCHEMA AS OBJECT_SCHEMA from information_schema.TABLE_CONSTRAINTS
Union
Select 'Procedure/Functions' as OBJECT_TYPE, ROUTINE_NAME as OBJECT_NAME, ROUTINE_SCHEMA as OBJECT_SCHEMA from information_schema.ROUTINES
) R

Where R.OBJECT_SCHEMA=[your-schema-name-here]

Answered by: Keer on: Apr 25th, 2012

Select * from sys.tables where type = U

Answered by: saikiran on: Jul 22nd, 2011

Select * from sys.tables

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...

First | Prev | | Next | Last Page

 

 

Ads

Connect

twitter fb Linkedin GPlus RSS

Ads

Interview Question

 Ask Interview Question?

 

Latest Questions

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.