Kofax Most Frequently Asked Latest SQL Server Interview Questions Answers
How to insert values EXPLICITLY to an Identity Column ?
This has become a common question these days in interviews. Actually we cannot Pass values to Identity column and you will get the following error message when you try to pass value.
Msg 544, Level 16, State 1, Line 3
Cannot insert explicit value for identity column in table 'tablename' when IDENTITY_INSERT is set to OFF.
To pass an external value we can use the property IDENTITY_INSERT. PFB the sysntax of the same.
SET IDENTITY_INSERT <tablename> ON;
Write your Insert statement here by passing external values to the IDENTITY column.
Once the data is inserted then remember to SET the property to OFF.
How to RENAME a table and column in SQL ?
We can rename a table or a column in SQL using the System stored procedure SP_RENAME. PFB the sample queries.
Table – EXEC sp_rename @objname = department, @newname = subdivision
Column – EXEC sp_rename @objname = ‘sales.order_no’ , @newname = ordernumber
How to rename a database ?
To rename a database please use the below syntax.
USE master;
GO
ALTER DATABASE databasename
Modify Name = newname ;
GO
What is the use the UPDATE_STATISTICS command ?
UPDATE_STATISTICS updates the indexes on the tables when there is large processing of data. If we do a large amount of deletions any modification or Bulk Copy into the tables, we need to basically update the indexes to take these changes into account.
How to read the last record from a table with Identity Column ?
We can get the same using couple of ways and PFB the same.
First –
SELECT *
FROM TABLE
WHERE ID = IDENT_CURRENT(‘TABLE’)
Second –
SELECT *
FROM TABLE
WHERE ID = (SELECT MAX(ID) FROM TABLE)
Third –
select top 1 * from TABLE_NAME order by ID desc
What is Worktable ?
A worktable is a temporary table used internally by SQL Server to process the intermediate results of a query. Worktables are created in the tempdb database and are dropped automatically after query execution. Thease table cannot be seen as these are created while a query executing and dropped immediately after the execution of the query.
What is recursive stored procedure?
SQL Server supports recursive stored procedure which calls by itself. Recursive stored procedure can be defined as a method of problem solving wherein the solution is arrived repetitively. It can nest up to 32 levels.
CREATE PROCEDURE [dbo].[Fact]
(
@Number Integer,
@RetVal Integer OUTPUT
)
AS
DECLARE @In Integer
DECLARE @Out Integer
IF @Number != 1
BEGIN
SELECT @In = @Number – 1
EXEC Fact @In, @Out OUTPUT - Same stored procedure has been called again(Recursively)
SELECT @RetVal = @Number * @Out
END
ELSE
BEGIN
SELECT @RetVal = 1
END
RETURN
GO
CREATE PROCEDURE [dbo].[Fact]
(
@Number Integer,
@RetVal Integer OUTPUT
)
AS
DECLARE @In Integer
DECLARE @Out Integer
IF @Number != 1
BEGIN
SELECT @In = @Number – 1
EXEC Fact @In, @Out OUTPUT - Same stored procedure has been called again(Recursively)
SELECT @RetVal = @Number * @Out
END
ELSE
BEGIN
SELECT @RetVal = 1
END
RETURN
GO
What are the differences between local and global temporary tables?
Local temporary tables are visible when there is a connection, and are deleted when the connection is closed.
CREATE TABLE #<tablename>
CREATE TABLE #<tablename>
Global temporary tables are visible to all users, and are deleted when the connection that created it is closed.
CREATE TABLE ##<tablename>
CREATE TABLE ##<tablename>
What are the two authentication modes in SQL Server?
There are two authentication modes –
Windows Mode
Mixed Mode
Modes can be changed by selecting the tools menu of SQL Server configuration properties and choose security page.
What Is SQL Profiler?
SQL Profiler is a tool which allows system administrator to monitor events in the SQL server. This is mainly used to capture and save data about each event of a file or a table for analysis.
What is CHECK constraint?
A CHECK constraint can be applied to a column in a table to limit the values that can be placed in a column. Check constraint is to enforce integrity.
Can SQL servers linked to other servers?
SQL server can be connected to any database which has OLE-DB provider to give a link. Example: Oracle has OLE-DB provider which has link to connect with the SQL server group.
What is COALESCE in SQL Server?
COALESCE is used to return first non-null expression within the arguments. This function is used to return a non-null from more than one column in the arguments.
Example –
Select COALESCE(empno, empname, salary) from employee;
Select COALESCE(empno, empname, salary) from employee;
How exceptions can be handled in SQL Server Programming?
Exceptions are handled using TRY—-CATCH constructs and it is handles by writing scripts inside the TRY block and error handling in the CATCH block.
What is the purpose of FLOOR function?
FLOOR function is used to round up a non-integer value to the previous least integer. Example is given
FLOOR(6.7)
FLOOR(6.7)
Returns 6.
How to insert values EXPLICITLY to an Identity Column ?
This has become a common question these days in interviews. Actually we cannot Pass values to Identity column and you will get the following error message when you try to pass value.
Msg 544, Level 16, State 1, Line 3
Cannot insert explicit value for identity column in table 'tablename' when IDENTITY_INSERT is set to OFF.
To pass an external value we can use the property IDENTITY_INSERT. PFB the sysntax of the same.
SET IDENTITY_INSERT <tablename> ON;
Write your Insert statement here by passing external values to the IDENTITY column.
Once the data is inserted then remember to SET the property to OFF.
How to RENAME a table and column in SQL ?
We can rename a table or a column in SQL using the System stored procedure SP_RENAME. PFB the sample queries.
Table – EXEC sp_rename @objname = department, @newname = subdivision
Column – EXEC sp_rename @objname = ‘sales.order_no’ , @newname = ordernumber
How to rename a database ?
To rename a database please use the below syntax.
USE master;
GO
ALTER DATABASE databasename
Modify Name = newname ;
GO
What is the use the UPDATE_STATISTICS command ?
UPDATE_STATISTICS updates the indexes on the tables when there is large processing of data. If we do a large amount of deletions any modification or Bulk Copy into the tables, we need to basically update the indexes to take these changes into account.
Kofax Most Frequently Asked Latest SQL Server Interview Questions Answers |
How to read the last record from a table with Identity Column ?
We can get the same using couple of ways and PFB the same.
First –
SELECT *
FROM TABLE
WHERE ID = IDENT_CURRENT(‘TABLE’)
Second –
SELECT *
FROM TABLE
WHERE ID = (SELECT MAX(ID) FROM TABLE)
Third –
select top 1 * from TABLE_NAME order by ID desc
What is Worktable ?
A worktable is a temporary table used internally by SQL Server to process the intermediate results of a query. Worktables are created in the tempdb database and are dropped automatically after query execution. Thease table cannot be seen as these are created while a query executing and dropped immediately after the execution of the query.
What is recursive stored procedure?
SQL Server supports recursive stored procedure which calls by itself. Recursive stored procedure can be defined as a method of problem solving wherein the solution is arrived repetitively. It can nest up to 32 levels.
CREATE PROCEDURE [dbo].[Fact]
(
@Number Integer,
@RetVal Integer OUTPUT
)
AS
DECLARE @In Integer
DECLARE @Out Integer
IF @Number != 1
BEGIN
SELECT @In = @Number – 1
EXEC Fact @In, @Out OUTPUT - Same stored procedure has been called again(Recursively)
SELECT @RetVal = @Number * @Out
END
ELSE
BEGIN
SELECT @RetVal = 1
END
RETURN
GO
CREATE PROCEDURE [dbo].[Fact]
(
@Number Integer,
@RetVal Integer OUTPUT
)
AS
DECLARE @In Integer
DECLARE @Out Integer
IF @Number != 1
BEGIN
SELECT @In = @Number – 1
EXEC Fact @In, @Out OUTPUT - Same stored procedure has been called again(Recursively)
SELECT @RetVal = @Number * @Out
END
ELSE
BEGIN
SELECT @RetVal = 1
END
RETURN
GO
What are the differences between local and global temporary tables?
Local temporary tables are visible when there is a connection, and are deleted when the connection is closed.
CREATE TABLE #<tablename>
CREATE TABLE #<tablename>
Global temporary tables are visible to all users, and are deleted when the connection that created it is closed.
CREATE TABLE ##<tablename>
CREATE TABLE ##<tablename>
What are the two authentication modes in SQL Server?
There are two authentication modes –
Windows Mode
Mixed Mode
Modes can be changed by selecting the tools menu of SQL Server configuration properties and choose security page.
What Is SQL Profiler?
SQL Profiler is a tool which allows system administrator to monitor events in the SQL server. This is mainly used to capture and save data about each event of a file or a table for analysis.
A CHECK constraint can be applied to a column in a table to limit the values that can be placed in a column. Check constraint is to enforce integrity.
Can SQL servers linked to other servers?
SQL server can be connected to any database which has OLE-DB provider to give a link. Example: Oracle has OLE-DB provider which has link to connect with the SQL server group.
What is COALESCE in SQL Server?
COALESCE is used to return first non-null expression within the arguments. This function is used to return a non-null from more than one column in the arguments.
Example –
Select COALESCE(empno, empname, salary) from employee;
Select COALESCE(empno, empname, salary) from employee;
How exceptions can be handled in SQL Server Programming?
Exceptions are handled using TRY—-CATCH constructs and it is handles by writing scripts inside the TRY block and error handling in the CATCH block.
What is the purpose of FLOOR function?
FLOOR function is used to round up a non-integer value to the previous least integer. Example is given
FLOOR(6.7)
FLOOR(6.7)
Returns 6.
Post a Comment