exam questions

Exam 70-761 All Questions

View all questions & answers for the 70-761 exam

Exam 70-761 topic 1 question 133 discussion

Actual exam question from Microsoft's 70-761
Question #: 133
Topic #: 1
[All 70-761 Questions]

DRAG DROP -
You have a database that contains a table named Users. The table is defined as follows:

You have the following Comma Separated Values (CSV) file:

You need to load data from the CSV file into the Users table while meeting the following requirements:
✑ If a field value is not provided in the file, insert a NULL value for the corresponding column
✑ Load all records into the table with the correct UserId from the file
Which three Transact-SQL segments should you use to develop the solution? To answer, move the appropriate Transact-SQL segments from the list of Transact-
SQL segments to the answer area and arrange them in the correct order.
Select and Place:

Show Suggested Answer Hide Answer
Suggested Answer:
Reference:
https://docs.microsoft.com/en-us/sql/t-sql/functions/openrowset-transact-sql?view=sql-server-2017

Comments

Chosen Answer:
This is a voting comment (?). It is better to Upvote an existing comment if you don't have anything to add.
Switch to a voting comment New
M4x
Highly Voted 5 years, 9 months ago
Wrong! bulk insert users from N'F:\users.txt' with ( fieldterminator = ',', keepidentity, keepnulls ) keepnulls because otherwise all records with null became active (there are a default on IsActive column)
upvoted 33 times
okh
5 years, 9 months ago
Agree, tested
upvoted 6 times
...
chaoxes
4 years, 11 months ago
This is correct based on https://docs.microsoft.com/en-us/sql/t-sql/statements/bulk-insert-transact-sql?view=sql-server-ver15
upvoted 1 times
...
kiri2020
4 years, 8 months ago
the only problem with text file, should remove spaces after comma, otherwise it give error for the second column: 1,,User1 10,1,User 10 11,0,User 11 2,,user2
upvoted 2 times
...
...
Billybob0604
Most Recent 4 years, 5 months ago
M4x is right.. you can't use fieldterminator with openrowset ----> https://docs.microsoft.com/en-us/sql/relational-databases/import-export/specify-field-and-row-terminators-sql-server?view=sql-server-ver15
upvoted 1 times
...
Vermonster
4 years, 5 months ago
Mx4 is correct - works as is - the OPENROWSET has issues
upvoted 1 times
...
Joce_IT
4 years, 11 months ago
For the solution with OPENROWSET, we need to have a .fmt file. The content of Users.fmt is: 13.0 3 1 SQLCHAR 0 7 "," 1 UserId "SQL_Latin1_General_CP1_CI_AS" 2 SQLCHAR 0 1 "," 2 IsActive "SQL_Latin1_General_CP1_CI_AS" 3 SQLCHAR 0 100 "\r\n" 3 UserName "SQL_Latin1_General_CP1_CI_AS" Maybe it can work using SQLINT for UserId, and SQLBIT for IsActive, but I have not succeeded in that way. And the Transact-SQL for the current question is: SET IDENTITY_INSERT Users ON; INSERT INTO Users (UserId, IsActive, UserName) SELECT * FROM OPENROWSET ( BULK N'F:\Users.txt', FORMATFILE = N'F:\Users.fmt', FORMAT = 'CSV' ) AS R ; SET IDENTITY_INSERT Users OFF; GO
upvoted 1 times
...
Community vote distribution
A (35%)
C (25%)
B (20%)
Other
Most Voted
A voting comment increases the vote count for the chosen answer by one.

Upvoting a comment with a selected answer will also increase the vote count towards that answer by one. So if you see a comment that you already agree with, you can upvote it instead of posting a new comment.

SaveCancel
Loading ...