'CREATE VIEW' must be the first statement in a query batch

后端 未结 5 699
逝去的感伤
逝去的感伤 2020-12-09 15:36

Basically its what the title says. This is my code.

USE Assignment2;
GO

/* Player View (2 marks)
    Create a view which shows the following details of all          


        
5条回答
  •  粉色の甜心
    2020-12-09 16:30

    Batches are delimited by the word GO - which is an instruction to client tools, not to SQL Server, specifically telling those tools how to split your query into batches.

    The error tells you that CREATE VIEW must be the first statement in a batch:

    USE Assignment2;
    GO
    
    /* Player View (2 marks)
        Create a view which shows the following details of all players:
            • The ID number of the player
            • The first name and surname of the player concatenated and given an alias of “full_name”
            • The team ID number of the player (if applicable)
            • The team name of the player (if applicable)
            • The coach ID number of the player (if applicable)
            • The name of the player’s coach (if applicable)
    
       Creating this view requires a select statement using multiple joins and concatenation of names.  
       Make sure that you use the appropriate type of join to ensure that players without teams or coaches are still included in the results.
    
    */
    
    
    -- Write your Player View here
    PRINT 'Creating Player View'
    
    GO -->-- New GO here
    
    CREATE VIEW playerView AS 
    

    So I've added a GO before CREATE VIEW

提交回复
热议问题