Which Transact-SQL statement should you use?

You use a Microsoft SQL Server 2012 database that contains a table named BlogEntry that has the following
columns:

Id is the Primary Key.
You need to append the “This is in a draft stage” string to the Summary column of the recent 10 entries based
on the values in EntryDateTime. Which Transact-SQL statement should you use?

You use a Microsoft SQL Server 2012 database that contains a table named BlogEntry that has the following
columns:

Id is the Primary Key.
You need to append the “This is in a draft stage” string to the Summary column of the recent 10 entries based
on the values in EntryDateTime. Which Transact-SQL statement should you use?

A.
UPDATE TOP(10) BlogEntry
SET Summary.WRITE(N’ This is in a draft stage’, NULL, 0)

B.
UPDATE BlogEntry
SET Summary = CAST(N’ This is in a draft stage’ as nvarchar(max))
WHERE Id IN(SELECT TOP(10) Id FROM BlogEntry ORDER BY EntryDateTime DESC)

C.
UPDATE BlogEntry
SET Summary.WRITE(N’ This is in a draft stage’, NULL, 0) FROM (
SELECT TOP(10) Id FROM BlogEntry ORDER BY EntryDateTime DESC) AS s
WHERE BlogEntry.Id = s.ID

D.
UPDATE BlogEntry
SET Summary.WRITE(N’ This is in a draft stage’, 0, 0)
WHERE Id IN(SELECT TOP(10) Id FROM BlogEntry ORDER BY EntryDateTime DESC)

Explanation:
Verified answer as correct.



Leave a Reply 13

Your email address will not be published. Required fields are marked *


Josefina

Josefina

Great post. I used to be checking constantly this weblog and I’m impressed!
Very useful information specially the closing section :
) I handle such info a lot. I used to be seeking this particular info for a very long time.
Thanks and good luck.

KAVI

KAVI

I tried C, but it throws error saying “cannot call method on nvarchar”
Option B works but it is not appending, instead it is overwriting.
The right answer is B but replace the line, Summer = concat(Summary, N’This is in a draft stage’)

moumita

moumita

@Kavi
Use nvarchar(max) instead of nvarchar(size) to design the table

Frank Hyatt

Frank Hyatt

This is a bad question because c and d both work. The difference lies in the word “append”. If append means append to the beginning .write(string,0,0) is the right one. If it means “append to the end” then .write(string,null,0) works. Who needs to know this in real life? No one. The fact that .write only works with nvarchar(max) and not varchar(max) or nvarchar(size) is another intricacy no one uses in real life but they test on us to separate the geeks from the married with children.

mantee

mantee

Frank indeed.
For me “append” means add to the end so answer “C”.
I have just one remark. Documentation says
https://msdn.microsoft.com/pl-pl/library/ms177523(v=sql.110).aspx
that varchar(max) is also allowed in expression.

.WRITE (expression,@Offset,@Length)
Specifies that a section of the value of column_name is to be modified. expression replaces @Length units starting from @Offset of column_name. Only columns of varchar(max), nvarchar(max), or varbinary(max) can be specified with this clause.

Gokulakrishnan

Gokulakrishnan

.WRITE (expression,@Offset,@Length):

Specifies that a section of the value of column_name is to be modified. expression replaces @Length units starting from @Offset of column_name. …

expression: is the value that is copied to column_name. … If expression is set to NULL, @Length is ignored, and the value in column_name is truncated at the specified @Offset.

@Offset: is the starting point in the value of column_name at which expression is written. … If @Offset is NULL, the update operation appends expression at the end of the existing column_name value and @Length is ignored. …

malakosa

malakosa

If @Offset is NULL, the update operation appends expression at the end of the existing column_name value and @Length is ignored

C

Kevin

Kevin

i tested it,i promise it.the answer C and D are both work,but they has a little difference.
answer C will add the string forward the value,
answer D will add the string behind the value.
——this is my demo
if object_id(‘testdb1..a’) is not null
drop table a

create table a(id int,a varchar(max))

insert into a
select 1,’abcdefghijklmnopqrstuvwxyz~!~1234567890′
union all
select 2,’aaaaaaaa’
union all
select 3,’bbbbbbbb’

if object_id(‘testdb1..b’) is not null
drop table b

create table b(id int)
insert into b
select 1 union all
select 2 union all
select 3

–UPDATE a
–SET a.WRITE(N’This is in a draft stage’, NULL, 0) FROM (
–SELECT TOP(2) Id FROM b ORDER BY id DESC) AS s
–WHERE a.Id = s.ID

UPDATE a
SET a.WRITE(N’This is in a draft stage’, 0, 0)
WHERE Id IN(SELECT TOP(2) Id FROM b ORDER BY id DESC)

select * from a

Kevin

Kevin

i glad to choose D,it’s easier to understand

Bjoern Werner

Bjoern Werner

New 70-461 Exam Questions and Answers Updated Recently (5/May/2017):

NEW QUESTION 169
You have a database that contains a table named Customer. The customer table contains a column named LastName that has a column definition of varchar(50). An application named App1 reads from the table frequently. You need to change the column definition to nvarchar(100). The solution must minimize the amount of time it takes for App1 to read the data. Which statement should you execute?
Image URL: passleader.org/wp-content/uploads/2017/05/passleader-70-461-dumps-1691.png

Answer: C
Explanation:
To change the data type of a column in a SQL Server (or Microsoft access) table, use the following syntax:
ALTER TABLE table_name
ALTER COLUMN column_name datatype

NEW QUESTION 170
You are maintaining a SQL Server database that uses the default settings. The database contains a table that is defined by the following Transact-SQL statement:
Image URL: passleader.org/wp-content/uploads/2017/05/passleader-70-461-dumps-1701.png

Answer: A
Explanation:
Char(13) is a carriage return. Use the IIF construct to return an empty string for NULL values of the Adressline2 column. IIF returns one of two values, depending on whether theBoolean expression evaluates to true or false in SQL Server.

NEW QUESTION 171
A table named Profits stores the total profit made each year within a territory. The Profits table has columns named Territory, Year, and Profit. You need to create a report that displays the profits made by each territory for each year and its previous year. Which Transact-SQL query should you use?

A. SELECT Territory, Year, Profit, LEAD(Profit, 1, 0) OVER (PARTITION BY Territory ORDER BY Year) AS PreviousYearProfit FROM Profits
B. SELECT Territory, Year, Profit, LAG(Profit, 1, 0) OVER (PARTITION BY Year ORDER BY Territory) AS PreviousYearProfit FROM Profits
C. SELECT Territory, Year, Profit, LAG(Profit, 1, 0) OVER (PARTITION BY Territory ORDER BY Year) AS PreviousYearProfit FROM Profits
D. SELECT Territory, Year, Profit, LEAD(Profit, 1, 0) OVER (PARTITION BY Year ORDER BY Territory) AS PreviousYearProfit FROM Profits

Answer: C

NEW QUESTION 172
Your database contains a table named Products that has columns named ProductID and Name. You want to write a query that retrieves data from the Products table sorted by Name listing 15 rows at a time. You need to view rows 31 through 45. Which Transact-SQL query should you create?
Image URL: passleader.org/wp-content/uploads/2017/05/passleader-70-461-dumps-1721.png

Answer: C

NEW QUESTION 173
A database named AdventureWorks contains two tables named Production.Product and Sales.SalesOrderDetail. The tables contain data on the available products and a detailed order history. The Production.Product table contains the following two columns:
– ProductID
– Name
The Sales.SalesOrderDetail table contains the following three columns:
– SalesOrderID
– ProductID
– OrderQty
You need to create a query listing all of the products that were never ordered. Which statements should you execute?
Image URL: passleader.org/wp-content/uploads/2017/05/passleader-70-461-dumps-1731.png

Answer: A

NEW QUESTION 174
You plan to write a query for a new business report that will contain several nested queries. You need to ensure that a nested query can call a table-valued function for each row in the main query. Which query operator should you use in the nested query?

A. CROSS APPLY
B. INNER JOIN
C. OUTER JOIN
D. PIVOT

Answer: A

NEW QUESTION 175
You are designing a table for a SQL Server database. The table uses horizontal partitioning. You have the following requirements:
– Each record in the table requires a unique key.
– You must minimize table fragmentation as the table grows.
You need to choose the appropriate data type for the key value. What should you do?

A. Use the NEWID function to create a unique identifier.
B. Use the NEWSEQUENTIALID function to create a unique identifier.
C. Generate a random value that uses the bigint datatype.
D. Generate a random value that uses the char(16) data type.

Answer: B

NEW QUESTION 176
You are a database developer of a Microsoft SQL Server database. You are designing a table that will store Customer data from different sources. The table will include a column that contains the CustomerID from the source system and a column that contains the SourceID. A sample of this data is as shown in the following table.
Image URL: passleader.org/wp-content/uploads/2017/05/passleader-70-461-dumps-1761.jpg
You need to ensure that the table has no duplicate CustomerID within a SourceID. You also need to ensure that the data in the table is in the order of SourceID and then CustomerID. Which Transact- SQL statement should you use?

A. CREATE TABLE Customer
(SourceID int NOT NULL,
CustomerID int NOT NULL,
CustomerName varchar(255) NOT NULL
CONSTRAINT UQ_Customer UNIQUE
(SourceID, CustomerID));
B. CREATE TABLE Customer
(SourceID int NOT NULL UNIQUE,
CustomerID int NOT NULL UNIQUE,
CustomerName varchar(255) NOT NULL);
C. CREATE TABLE Customer
(SourceID int NOT NULL PRIMARY KEY CLUSTERED,
CustomerID int NOT NULL UNIQUE,
CustomerName varchar(255) NOT NULL);
D. CREATE TABLE Customer
(SourceID int NOT NULL,
CustomerID int NOT NULL,
CustomerName varchar(255) NOT NULL,
CONSTRAINT PK_Customer PRIMARY KEY CLUSTERED
(SourceID, CustomerID));

Answer: D

NEW QUESTION 177
Drag and Drop Question
You maintain a SQL Server database that is used by a retailer to track sales and salespeople. The database includes two tables and two triggers that is defined by the following Transact-SQL statements:
Image URL: passleader.org/wp-content/uploads/2017/05/passleader-70-461-dumps-1771.jpg
During days with a large sales volume, some new sales transaction fail and report the following error:
Arithmetic overflow error converting expression to data type int.
You need to ensure that the two triggers are applied once per sale, and that they do not interfere with each other. How should you complete the relevant Transact-SQL statement? To answer, drag the appropriate Transact-SQL segments to the correct location or locations. Each Transact-SQL segment may be used once, more than once, or not at all. You may need to drag the split bar between panes or scroll to view content.
Image URL: passleader.org/wp-content/uploads/2017/05/passleader-70-461-dumps-1772.jpg

Answer:
Image URL: passleader.org/wp-content/uploads/2017/05/passleader-70-461-dumps-1773.png
Explanation:
Box 1: OFF
Box 2: 0
Only direct recursion of AFTER triggers is prevented when the RECURSIVE_TRIGGERS database option is set to OFF. To disable indirect recursion of AFTER triggers, also set the nested triggers server option to 0.
Note:
Both DML and DDL triggers are nested whena trigger performs an action that initiates another trigger. These actions can initiate other triggers, and so on. DML and DDL triggers can be nested up to 32 levels. You can control whether AFTER triggers can be nested through the nested triggers server configuration option. If nested triggers are allowed and a trigger in the chain starts an infinite loop, the nesting level is exceeded and the trigger terminates.

NEW QUESTION 178
……

P.S. These New 70-461 Exam Questions Were Just Updated From The Real 70-461 Exam, You Can Get The Newest 70-461 Dumps In PDF And VCE From — http://www.passleader.com/70-461.html (200q VCE and PDF)

Good Luck!