|
.Net Database Interview Questions and Answers
Using query analyzer, name 3 ways you can get an
accurate count of the number of records in a table.
Answer1.
a. Select count(*) from table1
b. SELECT object_name(id) ,rowcnt FROM sysindexes WHERE
indid IN (1,0) AND OBJECTPROPERTY(id, ‘IsUserTable’) = 1
c. exec sp_table_validation @table = ‘authors’
Answer2.
SELECT count( * ) as totalrecords FROM employee
This will display total records under the name
totalrecords in the table employee
use COUNT_BIG
Returns the number of items in a group.
@@ROWCOUNT
Returns the number of rows affected by the last
statement.
Use this statement after an SQL select * statement, to
retrieve the total number of rows in the table
What is the purpose of using COLLATE in a query?
Answer1.
Collation refers to a set of rules that determine how
data is sorted and compared. Character data is sorted
using rules that define the correct character sequence,
with options for specifying case-sensitivity, accent
marks, kana character types and character width.
Answer2.
COLLATE is a clause that can be applied to a database
definition or a column definition to define the
collation, or to a character string expression to apply
a collation cast.
What is one of the first things you would do to increase
performance of a query? For example, a boss tells you
that “a query that ran yesterday took 30 seconds, but
today it takes 6 minutes”?
Answer1.
Use Storedprocedure for any optimized result, because it
is an compiled code.
Answer2.
One of the best ways to increase query performance is to
use indexes.
What is an execution plan? When would you use it? How
would you view the execution plan?
The Query Analyzer has a feature called Show Execution
Plan. This option allows you to view the execution plan
used by SQL Server’s Query Optimizer to actually execute
the query. This option is available from the Query menu
on the main menu of Query Analyzer, and must be turned
on before the query is executed. Once the query is
executed, the results of the execution plan are
displayed in graphical format in a separate window,
available from a tab that appears below the query
results window on the screen.
What is the STUFF function and how does it differ from
the REPLACE function?
Answer1:
stuff-> inserts into it without removing any thing.
Replace->replace the given text with the new one.
Answer2:
STUFF - it deletes a specified length of characters and
inserts another set of characters at a specified
starting point. REPLACE -Replaces all occurrences of a
specified string value with another string value.
What does it mean to have quoted_identifier on? What are
the implications of having it off?
SET QUOTED_IDENTIFIER ON- Causes SQL Server to follow
the SQL-92 rules regarding quotation mark delimiting
identifiers and literal strings. Identifiers delimited
by double quotation marks can be either Transact-SQL
reserved keywords or can contain characters not usually
allowed by the Transact-SQL syntax rules for
identifiers.
What is the difference between a Local temporary table
and a Global temporary table? How is each one used?
Answer1:
Local templrary table will have a single # (#tablename)
appended with the table name.Global templrary table will
have Double # (##tablename) appended with the table
name.
Ex:create table #table1
local temp. table will be available until the session
who created it logs out, but global temp. table is
available till the last session gets close in SQLServer.
Answer1:
Local temporary tables are visible only in the current
session; global temporary tables are visible to all
sessions.Prefix local temporary table names with single
number sign (#table_name), and prefix global temporary
table names with a double number sign (##table_name).
What are cursors? Name four type of cursors and when
each one would be applied?
Opening a cursor on a result set allows processing the
result set one row at a time.
The four API server cursor types supported by SQL Server
are:
a) Static cursors
b) Dynamic cursors
c) Forward-only cursors
d) Keyset-driven cursors
What is the purpose of UPDATE STATISTICS?
UPDATE STATISTICS- it updates information about the
distribution of key values for one or more statistics
groups (collections) in the specified table or indexed
view.
How do you use DBCC statements to monitor various
ASPects of a SQL Server installation?
Database Consistency Checker (DBCC) - Is a statement
used to check the logical and physical consistency of a
database, check memory usage, decrease the size of a
database, check performance statistics, and so on.
Database consistency checker (DBCC) ensures the physical
and logical consistency of a database, but is not
corrective. DBCC can help in repairing or checking the
installation in case of any failure.
What is referential integrity and how can we achieve it?
Referential integrity preserves the defined
relationships between tables when records are entered or
deleted. In SQL Server, referential integrity is based
on relationships between foreign keys and primary keys
or between foreign keys and unique keys. Referential
integrity ensures that key values are consistent across
tables. Such consistency requires that there be no
references to nonexistent values and that if a key value
changes, all references to it change consistently
throughout the database.
We can achieve this by using foreign key.
Page Numbers :
1
2
3
4
5
Have a Question ?
post your questions here. It
will be answered as soon as possible.
Check
Microsoft .Net Interview
Questions for more Microsoft .Net Interview Questions with answers
Check
Asp .Net Interview
Questions for more Asp .Net Interview Questions with answers
Check
.Net
Deployment Interview
Questions for more .Net Deployment Interview Questions with answers
|