SQ L Questions
SQ L Questions
SQ L Questions
4. 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.
[sql]CREATE TABLE #<tablename>[/sql]
Global temporary tables are visible to all users, and are deleted when the
connection that created it is closed.
[sql]CREATE TABLE ##<tablename>[/sql]
The SQL Server agent plays a vital role in day to day tasks of SQL server
administrator(DBA). Server agents purpose is to implement the tasks easily with
the scheduler engine which allows our jobs to run at scheduled date and time.
14. Can we check locks in database? If so, how can we do this lock check?
Yes, we can check locks in the database. It can be achieved by using in-built stored
procedure called sp_lock.
15. What is the use of SIGN function?
SIGN function is used to determine whether the number specified is Positive,
Negative and Zero. This will return +1,-1 or 0.
Example
[sql]SIGN(-35) returns -1[/sql]
20. What will be query used to get the list of triggers in a database?
Query to get the list of triggers in database-
[sql]Select * from sys.objects where type=tr[/sql]
22. How Global temporary tables are represented and its scope?
Global temporary tables are represented with ## before the table name. Scope will
be the outside the session whereas local temporary tables are inside the session.
Session ID can be found using @@SPID.
23. What are the differences between Stored Procedure and the dynamic
SQL?
Stored Procedure is a set of statements which is stored in a compiled form.
Dynamic SQL is a set of statements that dynamically constructed at runtime and it
will not be stored in a Database and it simply execute during run time.
26. What is the command used to get the version of SQL Server?
[sql]Select SERVERPROPERTY(productversion)[/sql]
is used to get the version of SQL Server.
29. Which SQL server table is used to hold the stored procedure scripts?
Sys.SQL_Modules is a SQL Server table used to store the script of stored
procedure. Name of the stored procedure is saved in the table called Sys.Procedure.
31. What is the difference between SUBSTR and INSTR in the SQL Server?
The SUBSTR function is used to return specific portion of string in a given string.
But, INSTR function gives character position in a given specified string.
[sql]SUBSTR(Smiley,3)[/sql]
Gives result as Smi
[sql]INSTR(Smiley,i,1)[/sql]
Gives 3 as result as I appears in 3rd position of the string
39. What is the command used to Recompile the stored procedure at run
time?
Stored Procedure can be executed with the help of keyword called RECOMPILE.
Example
[sql]Exe <SPName> WITH RECOMPILE[/sql]
Or we can include WITHRECOMPILE in the stored procedure itself.
41. Where are SQL Server user names and passwords stored in SQL Server?
User Names and Passwords are stored in sys.server_principals and sys.sql_logins.
But passwords are not stored in normal text.
42. What is the difference between GETDATE and SYSDATETIME?
Both are same but GETDATE can give time till milliseconds and SYSDATETIME
can give precision till nanoseconds. SYSDATE TIME is more accurate than
GETDATE.
43. How data can be copied from one table to another table?
INSERT INTO SELECT
This command is used to insert data into a table which is already created.
SELECT INTO
This command is used to create a new table and its structure and data can be
copied from existing table.
49. What are the methods used to protect against SQL injection attack?
Following are the methods used to protect against SQL injection attack:
Use Parameters for Stored Procedures
Filtering input parameters
Use Parameter collection with Dynamic SQL
In like clause, user escape characters
50. What is Filtered Index?
Filtered Index is used to filter some portion of rows in a table to improve query
performance, index maintenance and reduces index storage costs. When the index
is created with WHERE clause, then it is called Filtered Index
----------------------------------------------------------------------------------------------
--second heighest salary from employee table
select * from
( select salary ,ROW_NUMBER() over (order by salary desc) as id
from employee ) as a
where a.id=2
---------------------------------------------------------------------------------------------
--how can you create an empty table from an existing table
-------------------------------------------------------------------------------
----------------------------------------------------------------------------------
--how to fetch alternate records from a single table
with duplicates
as
(
select empid,
empname,
ROW_NUMBER() over (partition by empid order by empid desc) as id
from dbo.emptable )
select empid from duplicates
where id >1
Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.
Alternative Proxies: