Top SQL And SQL SERVER Interview Questions Part 3

Category > ASP.NET || Published on : Monday, May 11, 2015 || Views: 3078 || Top SQL And SQL SERVER Interview Questions Part 3 SQL SERVER Interview Questions Interview Questions


Question 1: What is a Scheduled Jobs or What is a Scheduled Tasks?
Ans: Scheduled tasks let user automate processes that run on regular or predictable cycles. User can
schedule administrative tasks, such as cube processing, to run during times of slow business activity.
User can also determine the order in which tasks run by creating job steps within a SQL Server Agent
job. E.g. Back up database, Update Stats of Tables. Job steps give user control over flow of execution.
If one job fails, user can configure SQL Server Agent to continue to run the remaining tasks or to stop
execution.


Question 2:  How to get @@error and @@rowcount at the same time?
Ans: If @@Rowcount is checked after Error checking statement then it will have 0 as the value of
@@Recordcount as it would have been reset.
And if @@Recordcount is checked before the error-checking statement then @@Error would get reset.
To get @@error and @@rowcount at the same time do both in same statement and store them in local
variable. SELECT @RC = @@ROWCOUNT, @ER = @@ERROR


Question 3:  What is data integrity? Explain constraints?
Ans: Data integrity is an important feature in SQL Server. When used properly, it ensures that data is
accurate, correct, and valid. It also acts as a trap for otherwise undetectable bugs within applications.
A PRIMARY KEY constraint is a unique identifier for a row within a database table. Every table should
have a primary key constraint to uniquely identify each row and only one primary key constraint can be
created for each table. The primary key constraints are used to enforce entity integrity.
A UNIQUE constraint enforces the uniqueness of the values in a set of columns, so no duplicate values
are entered. The unique key constraints are used to enforce entity integrity as the primary key
constraints.
A FOREIGN KEY constraint prevents any actions that would destroy links between tables with the
corresponding data values. A foreign key in one table points to a primary key in another table. Foreign
keys prevent actions that would leave rows with foreign key values when there are no primary keys
with that value. The foreign key constraints are used to enforce referential integrity.
A CHECK constraint is used to limit the values that can be placed in a column. The check constraints
are used to enforce domain integrity.
A NOT NULL constraint enforces that the column will not accept null values. The not null constraints
are used to enforce domain integrity, as the check constraints.
What are the properties of the Relational tables?
Relational tables have six properties:

  • · Values are atomic.
  • · Column values are of the same kind.
  • · Each row is unique.
  • · The sequence of columns is insignificant.
  • · The sequence of rows is insignificant.
  • · Each column must have a unique name.

 

Question 4:  What are primary keys and foreign keys?
Ans: Primary keys are the unique identifiers for each row. They must contain unique values and cannot be
null. Due to their importance in relational databases, Primary keys are the most fundamental of all keys
and constraints. A table can have only one Primary key.
Foreign keys are both a method of ensuring data integrity and a manifestation of the relationship
between tables.


Question 5:  What is the difference between a local and a global variable?
Ans: A local temporary table exists only for the duration of a connection or, if defined inside a compound
statement, for the duration of the compound statement.
A global temporary table remains in the database permanently, but the rows exist only within a given
connection. When connection are closed, the data in the global temporary table disappears. However,
the table definition remains with the database for access when database is opened next time.


Question 6:  What is the basic functions for master, msdb, model, tempdb databases?
Ans: The Master database holds information for all databases located on the SQL Server instance and is the
glue that holds the engine together. Because SQL Server cannot start without a functioning master
database, you must administer this database with care.
The msdb database stores information regarding database backups, SQL Agent information, DTS
packages, SQL Server jobs, and some replication information such as for log shipping.
The tempdb holds temporary objects such as global and local temporary tables and stored procedures.
The model is essentially a template database used in the creation of any new user database created in
the instance.


Question 7 :  Using query analyzer, name 3 ways to get an accurate count of the number of records in a
table?

Ans:

  • SELECT * FROM table1
  • SELECT COUNT(*) FROM table1
  • SELECT rows FROM sysindexes WHERE id = OBJECT_ID(table1) AND indid < 2

Question 8: How to rebuild Master Database?
Ans: Shutdown Microsoft SQL Server 2000, and then run Rebuildm.exe. This is located in the Program
Files\Microsoft SQL Server\80\Tools\Binn directory.
In the Rebuild Master dialog box, click Browse.
In the Browse for Folder dialog box, select the \Data folder on the SQL Server 2000 compact disc or in
the shared network directory from which SQL Server 2000 was installed, and then click OK.
Click Settings. In the Collation Settings dialog box, verify or change settings used for the master
database and all other databases.
Initially, the default collation settings are shown, but these may not match the collation selected during
setup. You can select the same settings used during setup or select new collation settings. When done,
click OK.
In the Rebuild Master dialog box, click Rebuild to start the process.
The Rebuild Master utility reinstalls the master database.
To continue, you may need to stop a server that is running.
Source: http://msdn2.microsoft.com/en-us/library/aa197950(SQL.80).aspx


Question 9:  What does it mean to have quoted_identifier on? What are the implications of having it off?
Ans:  When SET QUOTED_IDENTIFIER is ON, identifiers can be delimited by double quotation marks, and
literals must be delimited by single quotation marks. When SET QUOTED_IDENTIFIER is OFF, identifiers
cannot be quoted and must follow all Transact-SQL rules for identifiers.


Question 10: What is the STUFF function and how does it differ from the REPLACE function?
Ans: STUFF function to overwrite existing characters. Using this syntax, STUFF(string_expression, start,
length, replacement_characters), string_expression is the string that will have characters substituted,
start is the starting position, length is the number of characters in the string that are substituted, and
replacement_characters are the new characters interjected into the string.
REPLACE function to replace existing characters of all occurance. Using this syntax
REPLACE(string_expression, search_string, replacement_string), where every incidence of
search_string found in the string_expression will be replaced with replacement_string.

 

Web Development Interview Questions
Database Interview Questions
Mobile Development Interview Questions
Others Interview Questions