Adl SQL Cheatsheet
Adl SQL Cheatsheet
October 3, 2012
By Tony Patton
There are many approaches to measuring technical aptitude during an interview process. These questions
(which all apply to SQL Server 2008) are not meant to be the only way to ascertain a candidates technical
expertise during an interview, but rather one piece of the puzzle that may spawn more thorough discussions.
The depth of the questions may vary according to the level of the open position; for instance, you would expect
more from a senior level candidate than from a junior level candidate.
2: What are temp tables? What is the difference between global and local temp tables?
Temporary tables are temporary storage structures. You may use temporary tables as buckets to store data that
you will manipulate before arriving at a final format. The hash (#) character is used to declare a temporary table
as it is prepended to the table name. A single hash (#) specifies a local temporary table.
CREATE TABLE #tempLocal ( nameid int, fname varchar(50), lname varchar(50) )
Local temporary tables are available to the current connection for the user, so they disappear when the user
disconnects.
Global temporary tables may be created with double hashes (##). These are available to all users via all
connections, and they are deleted only when all connections are closed.
CREATE TABLE ##tempGlobal ( nameid int, fname varchar(50), lname varchar(50) )
Once created, these tables are used just like permanent tables; they should be deleted when you are finished
with them. Within SQL Server, temporary tables are stored in the Temporary Tables folder of the tempdb
database.
Page 1
Copyright 2012 CNET Networks, Inc., a CBS Company. All rights reserved. TechRepublic is a registered trademark of CNET Networks, Inc
For more downloads and a free TechRepublic membership, please visit www.techrepublic.com.
8: What is a CTE?
A common table expression (CTE) is a temporary named result set that can be used within other statements like
SELECT, INSERT, UPDATE, and DELETE. It is not stored as an object and its lifetime is limited to the query. It is
defined using the WITH statement, as the following example shows:
WITH ExampleCTE (id, fname, lname)
AS
(
SELECT id, firstname, lastname FROM table
)
SELECT * FROM ExampleCTE
A CTE can be used in place of a view in some instances.
Page 2
Copyright 2012 CNET Networks, Inc., a CBS Company. All rights reserved. TechRepublic is a registered trademark of CNET Networks, Inc
For more downloads and a free TechRepublic membership, please visit www.techrepublic.com.
9: What is a view? What is the WITH CHECK OPTION clause for a view?
A view is a virtual table that consists of fields from one or more real tables. Views are often used to join multiple
tables or to control access to the underlying tables.
The WITH CHECK OPTION for a view prevents data modifications (to the data) that do not conform to the
WHERE clause of the view definition. This allows data to be updated via the view, but only if it belongs in the
view.
11: What does the SQL Server Agent Windows service do?
SQL Server Agent is a Windows service that handles scheduled tasks within the SQL Server environment (aka
jobs). The jobs are stored/defined within SQL Server, and they contain one or more steps that define what
happens when the job runs. These jobs may run on demand, as well as via a trigger or predefined schedule. This
service is important when determining why a certain job did not run as plannedoften it is as simple as the SQL
Server Agent service not running.
Keep your engineering skills up to date by signing up for TechRepublics free Software
Engineer newsletter, delivered each Tuesday. Automatically subscribe today!
Page 3
Copyright 2012 CNET Networks, Inc., a CBS Company. All rights reserved. TechRepublic is a registered trademark of CNET Networks, Inc
For more downloads and a free TechRepublic membership, please visit www.techrepublic.com.