SQL SERVER – Interview Questions and Answers – Frequently Asked Questions – Day 8 of 31

Click here to get free chapters (PDF) in the mailbox

Please read the Introductory Post before continue reading interview question and answers.

List of all the Interview Questions and Answers Series blogs

Which Command using Query Analyzer will give you the Version of SQL Server and Operating System?

SELECT SERVERPROPERTY('Edition') AS Edition,
SERVERPROPERTY('ProductLevel') AS ProductLevel,
SERVERPROPERTY('ProductVersion') AS ProductVersion
GO

(Read more here)

What is an SQL Server Agent?

The SQL Server agent plays an important role in the day-to-day tasks of a database administrator (DBA). It is often overlooked as one of the main tools for SQL Server management. Its purpose is to ease the implementation of tasks for the DBA, with its full-function scheduling engine, which allows you to schedule your own jobs and scripts. (Read more here)

Can a Stored Procedure call itself or a Recursive Stored Procedure? How many levels of SP nesting is possible?

Yes. As T-SQL supports recursion, you can write stored procedures that call themselves. Recursion can be defined as a method of problem solving wherein the solution is arrived at by repetitively applying it to subsets of the problem. A common application of recursive logic is to perform numeric computations that lend themselves to repetitive evaluation by the same processing steps. Stored procedures are nested when one stored procedure calls another or executes managed code by referencing a CLR routine, type, or aggregate. You can nest stored procedures up to 32 levels. Any reference to managed code from a Transact-SQL stored procedure counts as one level against the 32-level nesting limit. Methods invoked from within managed code do not count against this limit. (Read more here) (Courtesy: Vinod Kumar)

What is Log Shipping?

Log shipping is the process of automating the backup of database and transaction log files on a production SQL server and then restoring them onto a standby server. All Editions (except Express Edition) supports log shipping. In log shipping, the transactional log file from one server is automatically updated into the backup database on the other server. If one server fails, the other server will have the same db and can be used this as the Disaster Recovery plan. The key feature of log shipping is that it will automatically backup transaction logs throughout the day and automatically restore them on the standby server at defined intervals. (Courtney: Rhys)

Name 3 ways to get an Accurate Count of the Number of Records in a Table?

SELECT * FROM table1

SELECT COUNT(*) FROM table1

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

What does it mean to have QUOTED_IDENTIFIER ON? What are the Implications of having it OFF?

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 T-SQL rules for identifiers. (Read more here)

What is the Difference between a Local and a Global Temporary Table?

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 accessible across the connections. Once the connection where original global table is declared dropped this becomes unavailable.

What is the STUFF Function and How Does it Differ from the REPLACE Function?

STUFF function is used to overwrite existing characters using this syntax: STUFF (string_expression, start, length, replacement_characters), where 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 is used to replace existing characters of all occurrences. Using the syntax REPLACE (string_expression, search_string, replacement_string), every incidence of search_string found in the string_expression will be replaced with replacement_string.

What is PRIMARY KEY?

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.

What is UNIQUE KEY Constraint?

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.

What is FOREIGN KEY?

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.

List of all the Interview Questions and Answers Series blogs

Reference: Pinal Dave (https://blog.sqlauthority.com)

Previous Post
SQL SERVER – Introduction to expressor Datascript Modules
Next Post
SQL SERVER – Interview Questions and Answers – Frequently Asked Questions – Day 9 of 31

Related Posts

No results found.

15 Comments. Leave new

  • Yuvraj Gautam
    July 8, 2011 3:17 pm

    This may also be an alternate way to Count of the Number of Records.

    select max(rn) as counts from (
    select row_number() OVER (ORDER BY NEWID()) as rn from [tablename]
    )tb1

    Reply
  • “Enterprise Editions only supports log shipping” – every version except express supports log shipping. https://www.microsoft.com/en-us/sql-server/sql-server-2016

    Reply
  • fastsolutionca
    July 8, 2011 7:22 pm

    Unless you’re trying to cater to folks interviewing for jobs involving SQL Server 2000, I would swap out the query against sys.indexes for a query against sys.dm_db_partition_stats. I’d also drop the select * suggestion, and explain the difference between COUNT(*) against the table, and using the DMV.

    Reply
  • What about

    select count(1) from Table1

    This is more efficient on large datasets than count(*)

    Reply
  • Dear Pinal Sir,

    In foreign key , Not only primary key but also unique key can have reference.

    Reply
  • “A global temporary table remains in the database accessible across the connections. Once the connection where original global table is declared dropped this becomes unavailable.” – Actually the temp table is available until the last connection that references it is dropped, not the originating connection.

    Reply
  • HI,

    can we use group by clause in sub query?

    Reply
  • Ravikant sharma
    October 1, 2012 12:22 pm

    Vry usefull knowladge here

    Reply
  • Hello,
    I have xml document contains non-english text iei.heybru . I want to parse that xml and inser data into table.

    I have created proc and taking paramenter as nvarchar(max) for xml.
    when I parse the xml heybru text gets converted into quetionmarks.
    kindly guide on the same.

    Reply
  • A local temporary table, I thought it was important to realise that it only exists at the level it is created in a call stack, and higher, so there is no question of calling a stored procedure from a stored procedure that makes a temporary table, then using that temp table in the original calling stored proc

    Reply
  • Very informative and helpful

    Reply

Leave a Reply