GeekInterview.com
Series: Subject:

SQL Server FAQs

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

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 t1
inner inner join table_name t2
on 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.

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

SQL key

Asked By: sachin_ambre | Asked On: Aug 1st, 2010

What is a key in SQL?

Answered by: Mayank Tripathi on: Jan 18th, 2012

Candidate Key, Alternate Key, Composite Key are also the parts of SQL Server: A candidate key is one that can identify each row of a table uniquely. Generally a candidate key becomes the primary ke...

Answered by: psingla on: Nov 8th, 2010

We have different types of keys in sql:primary key      identify record uniquely     max one per table     do not contain null values &...

Fill factor in indexes

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

What is fill factor?What should be the ideal value of fill factor for any index?Justify the answer.

Answered by: raiyaans on: Jan 11th, 2012

The fill factor simply says how large or how full to get our index pages
you can set it as 70% ,

If set to 100% it might me a bad thing if we had a lot of DML activity but if this is a read only table then
fill factor=100% is fine.

Subqueries vs joins in SQL

Asked By: t1tankster | Asked On: Feb 9th, 2008

What is the difference between subqueries and joins? Which is better and why? Give an example of each.

Answered by: Hiren on: Nov 29th, 2011

Its true, I would like to add some more information about it, Subquery take separate temp table and checking condition ………….. Besides join is checks conditions first and then put it into tabl...

Answered by: abdullah on: Sep 12th, 2011

I am software engineer and iam working on oracle mysql and sql so i have lot of experience on this ,basically joins are using there should be connection two or more than two tables ,joins are always o...

I have a table in SQL server with two fields named 'start_time' and 'stop_time'. Both fields have datatype set as 'datetime'. Now I want to subtract the 'start_time' from 'stop_time'? I have tried datediff()...

Asked By: mun25_khanna | Asked On: Nov 16th, 2006

Answered by: satheyaraaj on: Jul 9th, 2011

select DATEDIFF(MI,FromTime,ToTime) From ShiftMaster  -- between no of minutes


select DATEDIFF(HH,FromTime,ToTime) From ShiftMaster -- between no of Hours


Answered by: swathi660 on: Jan 15th, 2009

select starttime,stoptime,datediff(day,starttime,stoptime) as newtime from date.try this...........

What are the advantages of SQL server 2005 over SQL server 2000/ SQL server 7.0 ?

Asked By: rajesh | Asked On: Jan 22nd, 2007

Answered by: gvs on: Jan 3rd, 2008

SQL Server 2005 has reduced application downtime, increased scalability and performance, and tight yet flexible security controls. SQL Server 2005 makes it simpler and easier to deploy, manage, and op...

Answered by: chandrasekhar on: May 17th, 2007

sql server 2005 is exclusively designed for dot net developers. what ever the function or procedure that we write in  dot net environment those function or procedure that  we direcly exucute in sql server environment. this is the new feature in sql 2005.

What is a co-related query in databases?

Asked By: sivaprasademani | Asked On: Mar 3rd, 2007

Answered by: sakthi.jaganathan on: Aug 25th, 2008

CO-RELATED Query: It used to find the exits or doesnot exits value. It has two select statement, the outer select statement will execute first and then the inner select statement execute.There is no need of relation between the two select statement.

Answered by: srinu.tenali on: Dec 14th, 2007

the sub query is executed more than one time i.e,the inner query depends on outer query output is called co-related query.

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

How to find out the no of connections in SQL server?

Asked By: gopi | Asked On: Aug 10th, 2007

Answered by: ahmeds08 on: May 30th, 2011

sp_who2

Answered by: Phani Kiran Gullapalli on: May 21st, 2011

Use SP_WHO2

Rename database

Asked By: seemu123 | Asked On: Oct 22nd, 2008

How can we rename a database with query?

Answered by: Priya Lakshmi on: May 25th, 2011

sp_rename 'old_db_name','new_db_name';

Answered by: dinu_26 on: Nov 11th, 2008

Syntax of renaming the database:

sp_renamedb old_database name new_database name



Eg:  name of the database is tree. Now if you need to change the database as three. So the query for changing the database as follows:


sp_renamedb tree three

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

Clustered & non clustered indexes

Asked By: laxminarayanag | Asked On: Aug 26th, 2010

What is difference between clustered & non clustered indexes?

Answered by: itmasterw on: Dec 28th, 2010

In general you put a clustered index on the key columns that you will be querying on and you can put a non clustered index on other key columns in the select statement. But you need to really look at ...

Answered by: psingla on: Nov 8th, 2010

The index in the sql server are in the form of btree having root and leaf nodes.The root node contains the column key value contained in the index and the leaf node contains the table data or pointer ...

How do I lock a column

Asked By: nicoleyoungabney10 | Asked On: Sep 6th, 2007

How do I lock a column, once records are entered into the table they can not be edited. Also how can I lock the field where only certain values are accepted?

Answered by: binita007 on: Dec 21st, 2010

For this purpose, Views are there in SQL Server.

You can Create a view by leaving the column you need to restrict

User can edit all the fields in the view except the one you restrict .

Binita.

Answered by: Kiran Patil on: Mar 26th, 2008

May be you can use Constraints.

Db mirroring

Asked By: laxminarayanag | Asked On: Aug 26th, 2010

What are the steps to configure db mirroring?

Answered by: sthakk3 on: Dec 9th, 2010

Database mirroring maintains two copies of a single database that must reside on different server instances of SQL Server Database Engine.
Database mirroring is a primarily software solution for increasing database availability.

Insert multiple rows

Asked By: dineshsivam | Asked On: May 27th, 2010

How to insert multiple rows in a single insert query?

Answered by: psingla on: Nov 8th, 2010

Commas are getting deleted here, so put commas between columns and values.

Answered by: psingla on: Nov 8th, 2010

1)
insert into table (col1,col2) values (val1,val2),(val3,val4)
2)
insert into table (col1,col2)
select val1,val2
union all
select val3,val4

Store images in SQL server 2005

Asked By: Paliwal1989 | Asked On: Aug 4th, 2010

How to store images in SQL server 2005?

Answered by: vigneshmca on: Sep 9th, 2010

You can store images by BLOB (Binary Large object). Conversion should take place in front-end or SQL supports image as datatype. Try it.

Replication overview

Asked By: laxminarayanag | Asked On: Aug 26th, 2010

Explain the replication overview?

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.