SQL SERVER Weekly Test2
SQL SERVER Weekly Test2
SQL SERVER Weekly Test2
Answer - 1
Question2. You are creating a stored procedure that will be called by an application and
will access data stored in one of the databases. The stored procedures must be
configured to return the current value of a parameter to the calling application. What
must you do?
A. Specify an output parameter in the stored procedure using the OUTPUT keyword.
B. Include a select statement in the stored procedure to return the necessary value
C. Specify a return code for the stored procedure using the RETURN statement.
D. Declare a variable using the DECLARE statement
Answer - A
Question3. You have created a view that reference columns from multiple base tables.
You want to modify data in the underlying tables through the view using an UPDATE
statement. What must be done to allow this modification to occur?
Answer - C
Question4. Company policy requires that all sessions accessing the database be
insulated from dirty reads. Non Repeatable reads and phantom reads are acceptable.
What is the lowest isolation level you can set to meet theses requirement ?
A. Read Uncommited
B. Read Commited
C. Repeatable Read
D. Serializable
Answer - B
Scenario Based Question: - There are two tables (User & UserHistory) as shown
below:-
User
user_id
name
phone_num
UserHistory
user_id
date
action
Question5. Given the tables above, write a SQL query to determine which user_ids in the User
table are not contained in the UserHistory table (assume the UserHistory table has a subset of
the user_ids in User table).
rollback
Question7. Scenario Based Question: - There are two tables (Salesperson, Customer&
Orders) as shown below:-
Salesperson Customer
ID Name Age Salary ID Name City Industry Type
1 Abe 61 140000 4 Samsonic pleasant J
2 Bob 34 44000 6 Panasung oaktown J
5 Chris 34 40000 7 Samony jackson B
7 Dan 41 52000 9 Orange Jackson B
8 Ken 57 115000
11 Joe 38 38000
Orders
Number order_date cust_id salesperson_id Amount
10 8/2/96 4 2 2400
20 1/30/99 4 8 1800
30 7/14/95 9 1 460
40 1/29/98 7 2 540
50 2/3/98 6 7 600
60 3/2/98 6 7 720
70 5/6/98 9 7 150
Question7. Find the largest order amount for each salesperson and the associated order number,
along with the customer to whom that order belongs to.
Answer.
select ord.sales_id, sp.name,number as OrderNumber, cust_id ,amount from
orders ord
JOIN
salesperson sp
on sp.sales_id= ord.sales_id
JOIN
(select sales_id , MAX(amount)mx from orders group by sales_id)maxord
on ord.amount= maxord.mx
Question8. Write syntax to create a View name CustomerOrders_vw to display amount of each
salesperson and the associated order number, along with the salesperson name.
Answer.
Answer.
Answer.
DROP VIEW Customerorders_vw
Question11. Write syntax to alter the above View name CustomerOrders_vw in order to bind with
underlying tables
Answer.
Question12. You have created the stored procedure, shown below, to report the year-to-date sales
for a specific book title.
You are now creating a script that will perform this stored
procedure. The stored procedure should report the year-to-date
sales for the book title if it executes successfully. If,
however, the stored procedures fails to execute, it should
report following message:
‘ No Sales Found’
Which of the following illustrates how the script required to
achive this should be created?
A.Declare @retval int
Decalre @ytd int
Exec get_sales_for_title ‘Net Etiquette’,@ytd
IF @retval <0
Print ‘No Sales found’
ELSE
Print ‘Year to date sales: ‘+STR(@ytd)
GO
Answer. D
Question14. What would happen when you execute the code given below in query
Analyzer?
Answer. Information about current SQL Server users and processes is displayed.
The explanation could be found in the Books Online under Creating a Stored
Procedure. One of the sections, named System Stored Procedures which describes
how SQL Server looks up the system stored procedure has this note: Important If any
user-created stored procedure has the same name as a system stored procedure, the
user-created stored procedure will never be executed.
Question15. On Friday, you issued several INSERT statements using Query Analyzer.
You then verified the data had been correctly entered with a SELECT statement. On
Monday, your users report that data is not there. What happened?
In this mode, after inserting or updating the data, you must issue the COMMIT
TRANSACTION statement to save the data permanently. Otherwise, once the
connection is broken all your inserts are rolled back.
. You want to create a table to store Microsoft Word Document. You need to ensure that
the documents must only be accessible via Transact SQL Queries. Which T-SQL
Statement should you use?
Answer10. A
SELECT DB_NAME();
A. MASTER
B. MODEL
C. MSDB
D. Current Database Name in which the Query is executed.
Answer11. D
Question12. You are designing a database for Microsoft.com. The database must
accommodate the customers who want to make reservation online to sit for examination.
To make a reservation, a new customer is required to provide his name, telephone number,
address and relevant examination information. Once a reservation has been confirmed, the
customer will receive a unique customer number, a unique reference number that pertains to
the reservation. The information includes details such as vendor, examination number, name of
certification and date and time of reservation.
1. To make another reservation at a later time, the customer must provide his customer
number.
2. To change existing reservation, the customer must provide the reservation reference
number.
Examination numbers are assigned according to the certification that it contributes toward and
are independent from vendor to vendor. Each vendor may offer one or more examination
towards certain certification. The database should be normalised to the third normal form. You
create the following tables:-
Create table Examinations
(Vendor int,
ExamID int,
Certification nvarchar (20))
Create table TimeTable
(Vendor int,
ExamID int,
ExamDate datetime)
Now you need to define the foreign keys for these tables. Write a script to define foreign keys
for these tables.
Question13. You are asked to design tables for this database, and come up with the design
shown in the exhibit below:
Which of the following is the option that you should take if you want to minimize redundant
data?
Which two of the followings are the columns that you should use to uniquely identify the skills of
each candidate?
A. CandidateID
B. SkillID
C. DateLastUsed
D. Proficiency
Answer14. A, B
Question15. You are currently designing a database named Sales. You have 1 GB of free
space on drive C and the database will be approximately 10 MB in size. Write the script to
create the database.
ANSWER16. A and C
Select Answer:
Question18. Which of the following are new SQLSERVER 2008 date functions?
Select Answer:
A. SYSDATETIME
B. SYSDATETIMEOFFSET
C. SYSUTCDATETIME
D. All of the above.
ANSWER18. A
Select Answer:
ANSWER19. A
Question20. Which of the following queries returns the users whose username starts with any of
the character between v to z?
Select Answer:
ANSWER20. A
Question21. If the following code was run on 31st Dec 2011, What is the result of the below
query:
SELECT DATEDIFF(YEAR, GETDATE(), '8/8/2003') AS 'Difference'
Select Answer:
A. -8
B. 8
C. 0
D. -1
ANSWER21. A
Select Answer:
A. Displays Users with Profession as 'engineer' with PKUserId > 12 as well as the users
with PKUserId of 1
B. Displays Users with Profession as 'engineer' with PKUserId > 12 only
C. Displays Users with Profession as 'engineer' with PKUserId of 1 only
D. None of the above
ANSWER22. A
Select Answer:
ANSWER23. E
Question24. What is the result of the below query:
SELECT PATINDEX('DOT%', 'DOTNET') AS 'Index'
Select Answer:
A. 1
B. 0
C. -1
D. 2
ANSWER24. A
Question25. Which of the following are T-SQL ranking functions that can be used for ranking
data
Select Answer:
A. ROW_NUMBER
B. DENSE_RANK
C. RANK
D. NTILE
E. All of the above
ANSWER25. E
Select Answer:
A. DOT
B. OTN
C. OT
D. None of the above
ANSWER26. A
Question27. Assuming the following query is executed on 31st Dec 2011. What is the result of
the below query.
SELECT CONVERT (varchar (30), GETDATE (), 111) AS Expr1
Select Answer:
A. 11/12/31
B. 31/12/11
C. 31/12/2011
D. 2011/12/31
ANSWER27. D
Answer28. abyyyfghiyyy
Answer30. ab
Answer31. fg
Question32. You have to create table as per the design as shown below:
Write the Syntax to Create the Table as per above schema.
Answer32.
Create table Customers
(CustmerID int PRIMARY KEY,
CompanyName nvarchar (30),
Address nvarchar (50),
City nvarchar (20))
Question33. You have recently received instruction to implement a SQL Server 2008 database
that will be used to store business information. A table named Test will be used to store sales
information and each sale will be uniquely identified by a specific SaleNo column. What should
you do?
Answer33. A
A. int
B. smallint
C. bigint
D. tinyint
Answer34. C
A. int
B. smallint
C. bigint
D. tinyint
Answer35. A
A. int
B. smallint
C. bigint
D. tinyint
Answer36. A
Question37. Assuming the following query is executed on 27st Oct 2013. What is the result of
the below query.
SELECT CONVERT (char (12), GETDATE (), 3) AS Expr1
Select Answer:
A. 27/10/13
B. 27/10/2013
C. 2013/10/27
D. 13/10/27
ANSWER37. A
ANSWER38. 5
USE tempdb;
GO
DECLARE @Num1 int;
SET @Num1 = -5;
SELECT +(@Num1);
GO
ANSWER39. -5
Answer40. Apple
A. The following query finds Contacts with the first name of Cheryl or Sheryl.
B. The following query finds Contacts not with the first name of Cheryl or Sheryl.
C. All of the above
D. None of the Above
Answer41. A
A. Numeric to money
B. Numeric to int
C. Money to int
D. Money to numeric
Answer43. B
Exhibit
A. Non-correlated subquery
B. Cross apply
C. Correlated subquery
Answer44. C
Question45. Write a Query that will retrieve all products from the db.products
table that have a name that starts with a letter in the range of G through M.
Answer45.
SELECT * from dbo.products
WHERE name like ‘[g-m]%’
SQL Statement
Running a select statement against the table produces following result set:-
Results
customer_id customer_name customer_address
Answer46. A
Question47. You are designing a table for multimedia department. They require a column to
store large video files. The file size can range up to 4GB. Which data type should you select for
the columns?
A. Binary
B. Varbinary(max)
C. Image
D. FILESTREAM varbinary(max)
Answer47. D
Question48. There are two tables named table1 and table2. Both tables have same number of
columns. The columns appear in the same order and have same data types. You need to
develop a T-SQL statement that will return all rows in table1 that do not also appear in table2.
Which statement will return the proper results?
Answer48. D
Question49. You need to write a query that will return all employees whose salaries are
higher than the average salary of all employees.
Which of the following option will meet your need?
Options
OPTION A:
OPTION B:
OPTION C:
OPTION D:
Question50. You need to delete all rows the dbo.orders table. The following requirement must
be met:-
- Minimal transaction log space must be used
- Locks must be kept to minimum
- The structure of the table and table definition must remain
Which T-SQL statement will accomplish for you?
A. DELETE
B. TRUNCATE TABLE
C. DROP TABLE
D. REVOKE
Answer50. B