Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

1 A series of SQL statements that you can store in a file is called a script cat

ID: 3790280 • Letter: 1

Question

1

A series of SQL statements that you can store in a file is called a

script

catalog view

subquery

view

1 points   

QUESTION 2

Code a statement that assigns the value “Test” to a scalar variable named @Name that’s declared with the varchar data type.

DECLARE ‘Test’ @varchar;

DECLARE varchar @Name = ‘Test’;

SET @Name = ‘Test’;

SET Test @Name;

1 points   

QUESTION 3

Code a statement that changes the database context to a database named TestDB.

USE TestDB;

none of the above

GO TestDB;

EXEC TestDB;

1 points   

QUESTION 4

Code a statement that creates a table variable named @TestTable.

CREATE @TestTable;

SET @TestTable = table;

DECLARE @table TestTable;

DECLARE @TestTable table;

1 points   

QUESTION 5

Code a statement that tests whether the database named TestDB exists.

IF DB_ID ('TestDB') EXISTS

IF TestDB IS NOT NULL

IF DB_ID ('TestDB') IS NOT NULL

IF TestDB EXISTS

1 points   

QUESTION 6

Code example 14-1
USE AP;
DECLARE @Date1 smalldatetime;
DECLARE @Date2 smalldatetime;
SELECT @Date1 = MIN(InvoiceDueDate), @Date2 = MAX(InvoiceDueDate)
    FROM Invoices
    WHERE InvoiceTotal - PaymentTotal - CreditTotal > 0;
IF @Date1 < GETDATE()
    IF @Date2 < GETDATE()
        BEGIN
            PRINT 'Earliest past due date: ' + CONVERT(varchar, @Date1, 1);
            PRINT 'Latest past due date: ' + CONVERT(varchar, @Date2, 1);
        END;
    ELSE
        PRINT 'Earliest past due date: ' + CONVERT(varchar, @Date1, 1);
ELSE
    PRINT 'No invoices past due';

(Refer to code example 14-1.) If the current date is 04/04/16, the earliest invoice due date for invoices with unpaid balances is 02/09/16, and the latest invoice due date for invoices with unpaid balances is 03/20/16, what will be printed by this script?

Earliest past due date: 02/09/16
Latest past due date: 03/20/16

Earliest past due date: 02/09/16

Nothing

No invoices past due

1 points   

QUESTION 7

Given the following statements that declare a local variable and set its value, which of the following will cause an error?
DECLARE @Example1 varchar(128);
SET @Example1 = 'Invoices';

SELECT *
FROM @Example1;

SELECT *
FROM sys.tables
WHERE name = @Example1;

PRINT 'Table name is: ' + @Example1;

IF @Example1 = 'Invoices'
SELECT * FROM Invoices;

1 points   

QUESTION 8

The scope of a derived table is limited to what?

the batch in which it’s defined

the script in which it’s defined

the statement in which it’s defined

the database session in which it’s defined

1 points   

QUESTION 9

The scope of a local variable is limited to what?

the statement in which it’s defined

the batch in which it’s defined

the script in which it’s defined

the database session in which it’s defined

1 points   

QUESTION 10

The scope of a temporary table is limited to what?

the script in which it’s defined

the batch in which it’s defined

the statement in which it’s defined

the database session in which it’s defined

1 points   

QUESTION 11

What do you call a local variable that can store a single value?

scalar

single-local

temporary

global

1 points   

QUESTION 12

What statement can you use to divide a script into multiple batches?

EXEC

DECLARE

GO

SET

1 points   

QUESTION 13

What statement do you use to execute a dynamic SQL statement?

CONTINUE

EXEC

GO

SET

1 points   

QUESTION 14

Which of the following statements can be coded in a batch with other statements?

CREATE FUNCTION

CREATE TABLE

CREATE PROCEDURE

CREATE VIEW

1 points   

QUESTION 15

Which statement can you use to control the flow of execution based on a true/false condition?

IF...ELSE

TRY...CATCH

BEGIN...END

EXEC

1

A series of SQL statements that you can store in a file is called a

a.

script

b.

catalog view

c.

subquery

d.

view

1 points   

QUESTION 2

Code a statement that assigns the value “Test” to a scalar variable named @Name that’s declared with the varchar data type.

a.

DECLARE ‘Test’ @varchar;

b.

DECLARE varchar @Name = ‘Test’;

c.

SET @Name = ‘Test’;

d.

SET Test @Name;

1 points   

QUESTION 3

Code a statement that changes the database context to a database named TestDB.

a.

USE TestDB;

b.

none of the above

c.

GO TestDB;

d.

EXEC TestDB;

1 points   

QUESTION 4

Code a statement that creates a table variable named @TestTable.

a.

CREATE @TestTable;

b.

SET @TestTable = table;

c.

DECLARE @table TestTable;

d.

DECLARE @TestTable table;

1 points   

QUESTION 5

Code a statement that tests whether the database named TestDB exists.

a.

IF DB_ID ('TestDB') EXISTS

b.

IF TestDB IS NOT NULL

c.

IF DB_ID ('TestDB') IS NOT NULL

d.

IF TestDB EXISTS

1 points   

QUESTION 6

Code example 14-1
USE AP;
DECLARE @Date1 smalldatetime;
DECLARE @Date2 smalldatetime;
SELECT @Date1 = MIN(InvoiceDueDate), @Date2 = MAX(InvoiceDueDate)
    FROM Invoices
    WHERE InvoiceTotal - PaymentTotal - CreditTotal > 0;
IF @Date1 < GETDATE()
    IF @Date2 < GETDATE()
        BEGIN
            PRINT 'Earliest past due date: ' + CONVERT(varchar, @Date1, 1);
            PRINT 'Latest past due date: ' + CONVERT(varchar, @Date2, 1);
        END;
    ELSE
        PRINT 'Earliest past due date: ' + CONVERT(varchar, @Date1, 1);
ELSE
    PRINT 'No invoices past due';

(Refer to code example 14-1.) If the current date is 04/04/16, the earliest invoice due date for invoices with unpaid balances is 02/09/16, and the latest invoice due date for invoices with unpaid balances is 03/20/16, what will be printed by this script?

a.

Earliest past due date: 02/09/16
Latest past due date: 03/20/16

b.

Earliest past due date: 02/09/16

c.

Nothing

d.

No invoices past due

1 points   

QUESTION 7

Given the following statements that declare a local variable and set its value, which of the following will cause an error?
DECLARE @Example1 varchar(128);
SET @Example1 = 'Invoices';

a.

SELECT *
FROM @Example1;

b.

SELECT *
FROM sys.tables
WHERE name = @Example1;

c.

PRINT 'Table name is: ' + @Example1;

d.

IF @Example1 = 'Invoices'
SELECT * FROM Invoices;

1 points   

QUESTION 8

The scope of a derived table is limited to what?

a.

the batch in which it’s defined

b.

the script in which it’s defined

c.

the statement in which it’s defined

d.

the database session in which it’s defined

1 points   

QUESTION 9

The scope of a local variable is limited to what?

a.

the statement in which it’s defined

b.

the batch in which it’s defined

c.

the script in which it’s defined

d.

the database session in which it’s defined

1 points   

QUESTION 10

The scope of a temporary table is limited to what?

a.

the script in which it’s defined

b.

the batch in which it’s defined

c.

the statement in which it’s defined

d.

the database session in which it’s defined

1 points   

QUESTION 11

What do you call a local variable that can store a single value?

a.

scalar

b.

single-local

c.

temporary

d.

global

1 points   

QUESTION 12

What statement can you use to divide a script into multiple batches?

a.

EXEC

b.

DECLARE

c.

GO

d.

SET

1 points   

QUESTION 13

What statement do you use to execute a dynamic SQL statement?

a.

CONTINUE

b.

EXEC

c.

GO

d.

SET

1 points   

QUESTION 14

Which of the following statements can be coded in a batch with other statements?

a.

CREATE FUNCTION

b.

CREATE TABLE

c.

CREATE PROCEDURE

d.

CREATE VIEW

1 points   

QUESTION 15

Which statement can you use to control the flow of execution based on a true/false condition?

a.

IF...ELSE

b.

TRY...CATCH

c.

BEGIN...END

d.

EXEC

Explanation / Answer

1. A series of SQL statements that you can store in a file is called a
   a. Script. Script is a collection of sql statements that can be saved, and executed whenever required.
2. Code a statement that assigns the value “Test” to a scalar variable named @Name that’s declared with the varchar data type.
   c. SET @Name = ‘Test’;   wo;; assign Test to the variable @Name.
3. Code a statement that changes the database context to a database named TestDB.
   a. USE TestDB; will use the specified database.
4. Code a statement that creates a table variable named @TestTable.
   d. DECLARE @TestTable table; will create a table variable.
5. Code a statement that tests whether the database named TestDB exists.          
   c. IF DB_ID ('TestDB') IS NOT NULL will check if the TestDB exists.