Professional Documents
Culture Documents
createtable Mytrantest
(
OrderId intPrimarykeyIdentity
Begintran Transtart
Insertinto Mytrantest
defaultvalues
Savetran firstpoint
insertinto Mytrantest
defaultvalues
rollbacktran firstpoint
Committran transtart
Select*from Mytrantest
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
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?
A. Read Uncommited
B. Read Commited
C. Repeatable Read
D. Serializable
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).
createtable Mytrantest
(
OrderId intPrimarykeyIdentity
Begintran Transtart
Insertinto Mytrantest
defaultvalues
Savetran firstpoint
insertinto Mytrantest
defaultvalues
rollback
Select*from Mytrantest
Question7. Find the largest order amount for each salesperson and the associated order number,
along with the customer to whom that order belongs to.
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.
Question11. Write syntax to alter the above View name CustomerOrders_vw in order to bind with
underlying tables
Question12. You have created the stored procedure, shown below, to report the year-to-date sales
for a specific book title.
Createprocedure get_sales_for_title
@title varchar(80), @ytd_sales intoutput
AS
SELECT @ytd_sales= ytd_sales from titles where title=@title
IF@@rowcount=0
Return (-1)
Else
Return 0
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 ‘Yeartodatesales: ‘+STR(@ytd)
GO
createtable UnionTest1
(
idcol intIDENTITY,
col2 char(3)
)
createtable UnionTest2
(
idcol intIDENTITY,
col4 char(3)
)
Insertinto UnionTest1
VALUES ('AAA')
Insertinto UnionTest1
VALUES ('BBB')
Insertinto UnionTest1
VALUES ('CCC')
Insertinto UnionTest2
VALUES ('CCC')
Insertinto UnionTest2
VALUES ('DDD')
Insertinto UnionTest2
VALUES ('EEE')
Question14. What would happen when you execute the code given below in query
Analyzer?
createPROCEDUREsp_who
AS
PRINT'SURPRISE'
GO
EXECUTEsp_who
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?
Question16. Now write syntax to create AFTER INSERT Trigger which will insert the
rows inserted in Employee_Test table into Employee_Test_Audit table.
EmployeeInfo
EmpId EmpName EmpLogin Emppassword EmploymentDate
EmpProjInfo
EmpId Projectname
1 IBS
EmpId Projectname
2 Tata Steel
3 Godrej
4 OITDS
5 Godrej
Question21. Write syntax to create a view which gives the empid, empname,
employmentdate as the output.
Question22. Write syntax to create a view which gives the information about the
employees and its projects as the output.
Question24. Write syntax to ALTER a view which gives the information about the
employees and its projects who are working on Godrej Project.
Question25. Write syntax to alter the above View name in order to bind with underlying
tables
Scenario Based: - there is a table called tbl_Students whose structure is given below:
(
[Studentid] [int] IDENTITY(1,1) NOT NULL,
[Firstname] [nvarchar](200) NOT NULL,
[Lastname] [nvarchar](200) NULL,
[Email] [nvarchar](100) NULL
)
Studentid Firstname Lastname Email
1 Vivek Johari vivek@abc.com
2 Pankaj Kumar pankaj@abc.com
3 Amit Singh amit@abc.com
4 Manish Kumar manish@abc.comm
5 Abhishek Singh abhishek@abc.com
Question27. Write syntax to create a stored procedure which will returns student name
whose Studentid is given as input parameter.
Question28. Write syntax to execute the above stored procedure
Question29. Write syntax to create a stored procedure which will returns student name
in the output parameter.
Question31. Write a syntax to alter a stored procedure which will returns student email
address along with student name in the output parameter.
Scenario based Question:- You are working as a database developer at CMC. CMC has
a database named HumanResources that contain information about all employees and
office locations. The database also includes information about potential employees and
office locations, which are stored in the tables as shown in the exhibit below:
Existing employees are assigned to a location and existing location have one or more
employees assigned to them. Potential employees are not assigned to a location, and
potential office locations do not have any employees. You have received instruction
from CEO to create a report that displays all existing and potential employees and office
locations. The report has to list every existing and potential location, followed by any
employees who have been assigned to that location. Also, potential employees have to
be listed together.
Question34. Of the following script, which is the one you should employee to achieve
this objective?
A.
SELECT l.LocationName, e.FirstName, e.LastName
FROM Employee AS e LEFT OUTER JOIN Location as l
ON e. LocationId = l. LocationId
ORDER BY l.LocationName, e.FirstName, e.LastName
B.
SELECT l.LocationName, e.FirstName, e.LastName
FROM Location AS l LEFT OUTER JOIN Employee as l
ON e. LocationId = l. LocationId
ORDER BY l.LocationName, e.FirstName, e.LastName
C.
SELECT l.LocationName, e.FirstName, e.LastName
FROM Employee AS e FULL OUTER JOIN Location as l
ON e. LocationId = l. LocationId
ORDER BY l.LocationName, e.FirstName, e.LastName
D.
SELECT l.LocationName, e.FirstName, e.LastName
FROM Employee AS e FULL OUTER JOIN Location as l
ORDER BY l.LocationName, e.FirstName, e.LastName
Question35. Which of the above script you should use to create a list of all possible
location and employee combinations?
You must populate the Countries table by moving the country information from the
Instructors table to the Countries Table. You must accomplish this task by using cursor.
Write Transact-SQL query to accomplish the job.
Question37. All customer companies that purchase significant amount of products are
offered discounts. Prices of the products with a category ID of 15 have been increased
by 10%. To compensate for customer companies that placed there orders on the day of
the price increase the discounts for those products must also be increased by 10%.
Both UPDATE statements must be implemented together. In the event of either update
failing, then the other update must not be implemented.
BEGIN TRAN
UPDATE Products SET Unitprice = Unitprice * 1.1 WHERE CategoryID =15
UPDATE OrderDetails SET Discount=Discount*1.1
FROM OrderDetails od JOIN Products p ON od.PRODUCTID= p.PRODUCTID
JOIN orders o ON o.OrderID= od. OrderID
WHERE CategoryID =15 AND OrderDate= '18 NOV 2013'
COMMIT
B. You should use the following script:
BEGIN TRAN
UPDATE Products SET Unitprice = Unitprice * 1.1 WHERE CategoryID =15
COMMIT
BEGIN TRAN
UPDATE OrderDetails SET Discount=Discount*1.1
FROM OrderDetails od JOIN Products p ON od.PRODUCTID= p.PRODUCTID
JOIN orders o ON o.OrderID= od. OrderID
WHERE CategoryID =15 AND OrderDate= '18 NOV 2013'
COMMIT
Write a Transact SQL Script to produce the result as shown below. You must use the
CURSOR.
exec test1
go
A. UPDATE customer
set c.name =c.name
FROM customer c, customerdetail cd
WHERE c.custid=cd.custid
B. UPDATE c
set c.name =u.name
FROM customer c, customerdetail cd
WHERE c.custid=cd.custid
C.UPDATE customer
set name =c.name
FROM customer c, customerdetail cd
WHERE c.custid=cd.custid
D.None of the Above