| Back to Questions Page |
| |
| Question |
What is Files and Filegroups in SQL Server & it's
implementation. |
Rank |
Answer Posted By |
|
Question Submitted By :: Compmastbipin@yahoo.com |
| This Interview Question Asked @ Zenith |
|
I also faced this Question!! |
© ALL Interview .com |
| Answer | Usage of different filegroups is a very good feature that
is available in SQL Server as well as many other RDBMS
(though in other RDBMS like Oracle and DB2 UDB, the concept
is a bit different for tablespaces but similar feature
exists). Filegroups allow files to be grouped together for
administrative and data allocation/placement purposes. For
example, three files (data1.ndf, data2.ndf, and data3.ndf)
can be created on three disk drives, respectively, and
assigned to the filegroup fgroup1. A table can then be
created specifically on the filegroup fgroup1. Queries for
data from the table will be spread across the three disks,
thereby improving performance.
The same performance improvement can be accomplished with a
single file created on a RAID/SAN stripe set. Files and
filegroups, however, allow you to easily add new files on
new disks. Additionally, if your database exceeds the
maximum size for a single Windows file, you can use
secondary data files to allow your database to continue to
grow. The advantage of using such an approach is that for
large database systems you can keep the filegroups on
separate disks, thus increasing response time for your
queries.
One other advantage relates to quick backup and recovery.
You can take the backup of separate filegroups and hence
restore only a particular filegroup and continue working.
This can be particularly useful in cases of production
databases where these activities are time critical and, of
course, minimizing downtime is always desirable.
You should never store objects in the primary filegroup
which is also used for storing the system objects in the
user database. Filegroups are also a good choice if you
have decided to implement partitioning for Very Large
Databases (VLDBs). Where RAID disk technology is being
used, multiple filegroups can be set up to span different
stripe sets. The objective here is to spread the I/O as
evenly as possible across the physical disk devices.
When you are using filegroups, how often have you seen
scenarios where-in you have a multi-processor powerful box
but all the processors are not being utilized ? You take a
look at the processor usage, either through task manager or
Performance (System) Monitor, and notice only one processor
seems to be hard at work, the others are just idling.
Well, before you start cursing Microsoft, have a look at
how many files you have for your database out on disk. Is
it one .mdf and one .ldf – the default ? Yes? Well that’s
most likely your problem – you can only write to one file
with one thread. Your database has become IO bound as only
one processor can write to the database at any one time.
The solution is to create a new database (or add to the
existing database) with as many data files (all the same
size) as you have processors and transfer the data from the
old database into this new one – this is to ensure you get
an even proportional fill across the files.
You can still run into issues at times though even after
you do this. If you do create the files properly and still
see this issue, then you have had automatic database growth
turned on for this database. Assuming when you created the
database you created it with all the database data files
the same size, then in such a scenario, at least one of
those files would have now grown beyond that size? If this
is the case then I think your problem is you’ve
lost ‘proportional fill’. Look at the following excerpt
from Books Online (BOL).
From Books Online: As data is written to the filegroup,
Microsoft® SQL Server™ writes an amount proportional to the
free space in the file to each file within the filegroup,
rather than writing all the data to the first file until
full and then writing to the next file. As soon as all the
files in a filegroup are full, SQL Server automatically
expands one file at a time in a round-robin fashion to
accommodate more data (provided that the database is set to
grow automatically).
You can loose proportional fill because now you only have
the one, newly expanded, file to write to; all the others
are full! With only one file to write to, you are
essentially only able to use one CPU
Solution is to avoid automatic database growth on multi-
processor system and have alerts in place to notify you
well in advance when the size is going to become an issue.  |
| Compmastbipin@yahoo.com |
| |
| |
| Question |
WHICH INDEX IS FAST CLUSTER AND NON CLUSTER INDEX |
Rank |
Answer Posted By |
|
Question Submitted By :: Jabamit |
| This Interview Question Asked @ L&T |
|
I also faced this Question!! |
© ALL Interview .com |
| Answer | CLUSTER INDEX BCZ THAT WORK PHYSICALLY(MEANS ALREADY IN DEC
OR ASC ORDER) BUT NON CLUSTER INDEX WORK DYNAMICALLY.  |
| Jabamit |
| |
| |
| Answer | Cluster Index is faster because it has data in the leaf
nodes along with the key. Non cluster on the other hand uses
cluster index key to search the data and therefore
relatively less fast.  |
| Shaurabh Thapa |
| |
| |
|
|
| |
| Question |
event classes in sql server |
Rank |
Answer Posted By |
|
Question Submitted By :: Ranjit Kumar Routhu |
| This Interview Question Asked @ Accenture |
|
I also faced this Question!! |
© ALL Interview .com |
| Answer | cursors,t-sql,stored procedures,databse,errors and warnings,
locks,objects,performance,scans,security audit,transactions,
user configurable these comes under sql server profile  |
| Ranjit Kumar Routhu |
| |
| |
| Question |
WHAT IS UNIQUE IDENTIFIER DATA TYPE? |
Rank |
Answer Posted By |
|
Question Submitted By :: Ranjit Kumar Routhu |
| This Interview Question Asked @ Sparsh |
|
I also faced this Question!! |
© ALL Interview .com |
| Answer | unique identifier data type size is 16 bits.
while creating table we have to create unique identifier
datatype column. it will create unique identity column
with 16 charcters
ex: create table a( id uniqueidentifier default newid
(),....),newid() generates new 16 unique charcter values  |
| Ranjit Kumar Routhu |
| |
| |
| Answer | unique identifier data type size is 16 bits.
while creating table we have to create unique identifier
datatype column. it will create unique identity column
with 32 charcters and not 16 characters  |
| Tauseef |
| |
| |
| Question |
how to get the maximum among two tables,for example table 1
(dep1) have (emp_id,emp_name,salary) columns and table 2
(dept2) have (emp_id,emp_name,salary) columns,i want which
employee have the maximum salary among two tables? |
Rank |
Answer Posted By |
|
Question Submitted By :: Sabarish.2meet |
| This Interview Question Asked @ Lason |
|
I also faced this Question!! |
© ALL Interview .com |
| Answer | Use Cursors:
declare Cursor_Name cursor scroll
for
select max(salary) as salary from dep1
union
select max(salary) as salart from dep2 order by salary desc
open Cursor_Name
fetch absolute 1 from Cursor_Name
deallocate Cursor_Name  |
| Sumathy |
| |
| |
| Answer | SELECT
OUTERTABLE.EMPID,
MAX(OUTERTABLE.SALARY)
FROM
(SELECT EMPID,MAX(SALARY) AS SALARY
FROM DEP1
GROUP BY EMPID
UNION ALL
SELECT EMPID,MAX(SALARY) AS SALARY
FROM DEP2
GROUP BY EMPID) AS OUTERTABLE
GROUP BY OUTERTABLE.EMPID  |
| Swati Tripathi |
| |
| |
| Question |
Delete duplicate rows from a table without primary key by
using a single query
Table Employee
empname salary
A 200
B 300
A 200
C 400
D 500
D 500
Output should be
A 200
B 300
C 400
D 500
|
Rank |
Answer Posted By |
|
Question Submitted By :: Ayanb1302@yahoo.com |
|
I also faced this Question!! |
© ALL Interview .com |
| Answer | Execute the following query for each duplicate value.
1.Delete duplicate of empname='A'
delete top(select count(*)-1 from employee where
empname='A') from employee where empname='A'
2.Delete duplicate of empname='D'
delete top(select count(*)-1 from employee where
empname='D') from employee where empname='D'  |
| Sumathy |
| |
| |
| Answer | declare myCursor cursor for
select empid
from employee
group by empid
having count(*) > 1
declare @EmpId int
OPEN myCursor;
FETCH NEXT FROM myCursor INTO @EmpId
WHILE @@FETCH_STATUS = 0
BEGIN
delete top(select count(*)-1 from employee where
empid=@EmpId) from employee where empid=@EmpId
FETCH NEXT FROM myCursor INTO @EmpId
END
close myCursor
deallocate myCursor  |
| Swati Tripathi |
| |
| |
| Question |
Please get the 4 th maximum salary from a table without
using any sql keyword (TOP,MAX are mot allowed) |
Rank |
Answer Posted By |
|
Question Submitted By :: Ayanb1302@yahoo.com |
|
I also faced this Question!! |
© ALL Interview .com |
| Answer | DECLARE @test TABLE(Empnm VARCHAR(10), Salary VARCHAR(10))
INSERT INTO @test (Empnm, Salary )
SELECT 'A', '200'
UNION ALL
SELECT 'B', '300'
UNION ALL
SELECT 'A', '200'
UNION ALL
SELECT 'B', '300'
UNION ALL
SELECT 'C', '400'
UNION ALL
SELECT 'C', '400'
UNION ALL
SELECT 'E', '100'
UNION ALL
SELECT 'D', '500'
SELECT * FROM @test
SELECT Empnm, Salary, (SELECT COUNT(DISTINCT(SALARY)) FROM
@test AS B WHERE A.Salary <= B.SALARY)
FROM @test AS A
GROUP BY Empnm, Salary
HAVING 4 = (SELECT COUNT(DISTINCT(SALARY)) FROM @test AS B
WHERE A.Salary <= B.SALARY)  |
| Pradeep |
| |
| |
| Answer | Create Table 'Employee' with columns 'Emp_Name'
and 'Salary'. And, Insert some data.....
Cursor:
declare Cursor_Name cursor scroll
for select salary from Emploee order by salary desc
open Cursor_Name
fetch absolute 2 from Cursor_Name
deallocate Cursor_Name  |
| Sumathy |
| |
| |
| Answer | Am Sumathy the above answer was posted by me.
For the above Answer 'absolute 2' will fetch 2nd maximum
value.
To fetch 4th maximum value use 'absolute 4'
To fetch 'n'th maximum value use 'absolute n'  |
| Sumathy |
| |
| |
| Answer | select payout,emp_cd from empmas e where 2>(select count(payout) from empmas s where s.payout>e.payout);  |
| Suresh |
| |
| |
| Answer | select * from (select *,row_number()over (order by salary
asc)as a from Employee)as b where b.a=4  |
| Gajendra |
| |
| |
| Question |
9. Write a query to list a new column with the
difference in temp of the cities Delhi and Mumbai, Mumbai
and Jammu and soon. Consider the following table :
City_id City Temp.
1 delhi 40
2 Mumbai 35
3 Jammu 32
4 Pune 18
|
Rank |
Answer Posted By |
|
Question Submitted By :: Akjain |
|
I also faced this Question!! |
© ALL Interview .com |
| Answer | select t1.name + ' and ' t2.name , t2.temp -t1.temp from
temp t1
join temp t2 on t2.id=t1.id+1  |
| Pradip Jain |
| |
| |
| Answer | Hi here is my sql code, tested and works :
select t.CityName As 'CityName1',t.CityTemp
As 'CityTemp1' ,t1.CityName As 'CityName2',t1.CityTemp
As 'CityTemp2',(t1.CityTemp-t.CityTemp)*(-1) As Difftemp
From Test as t inner join Test As t1
on
t1.CityId=t.CityId+1
Result is :
Delhi 40 Mumbai 35 5
Mumbai 35 Jammu 32 3
Jammu 32 Pune 18 14
If you want to remove the CityTemp1, CityTemp2, you can do
so from select statement. :)  |
| Milena |
| |
| |
|
| |
|
Back to Questions Page |