PrepAway - Latest Free Exam Questions & Answers

You need to develop a stored procedure named sp_coEvents that retrieves CompanyName for all partners and the E

CORRECT TEXT

You are the database developer at ABC.com. ABC.com has a SQL Server 2012 database
infrastructure that has a database named ComDB with tables named Partners and Events. These
tables were created using the following Transact-SQL code:
CREATE TABLE [dbo].[Partners]
(
[CompanyID] [int] NOT NULL PRIMARY KEY,
[CompanyName] [varchar] (150) NOT NULL,
[Location] [varchar] (150) NOT NULL,
[ContactName] [varchar] (150) NOT NULL,
[Email] [varchar] (150) NOT NULL,
[Phone] [varchar] (10) NOT NULL
)
CREATE TABLE [dbo].[Events]
(
[EventID] [int] NOT NULL PRIMARY KEY,
[CompanyID] [int] NOT NULL,
[EventDescription] [nvarchar] (MAX),
[EventDate] [nvarchar] (50) NOT NULL,
[EventCordinator] [nvarchar] (150) NOT NULL
)
You add a foreign key relationship between the two tables on the CompanyID column.
You need to develop a stored procedure named sp_coEvents that retrieves CompanyName for all
partners and the EventDate for all events that they have coordinated.
To answer, type the correct code in the answer area.

PrepAway - Latest Free Exam Questions & Answers

Answer:

Explanation:
CREATE PROCEDURE sp_coEvent
AS
SELECT CompanyName, EventDate
FROM Partners JOIN Events ON
Partners.CompanyID = Events.CompanyID

11 Comments on “You need to develop a stored procedure named sp_coEvents that retrieves CompanyName for all partners and the E

  1. John says:

    I think the answer is wrong because it uses an INNER JOIN.
    This would not qualify the ask of “CompanyName for all partners” as well as “EventDate for all events that they have coordinated”
    I would use FULL JOIN instead.




    0



    0
      1. Faisal says:

        Left Join will also bring Partners that have no event against them, so the event date will be NULL. I don’t think this is the purpose of this stored proc.
        If you look at the stored proc name, sp_coEvent it also shows that the requirement is to get the company events. What will be the purpose of bringing partners with no events? So I think INNER JOIN is appropriate, i.e. just return the partners who have coordinated an event.




        0



        0
  2. lewis says:

    create procedure sp_coEvents
    @CompanyName varchar (150)
    as
    select partners.CompanyName,events.EventDate from Partners inner join Events
    on Partners.CompanyID=events.CompanyID
    where partners.CompanyName = @CompanyName




    0



    0
  3. Dan says:

    alter table Events
    add Constraint FKConstraint Foreign Key (CompanyID) references dbo.Partners(CompanyID)

    create procedure sp_coEvents
    as
    select P.CompanyName, E.EventDate
    FROM dbo.Partners as P
    inner join dbo.Events as E
    on P.CompanyID=E.CompanyID




    0



    0

Leave a Reply