Need help for this SQL Query

Mary Sachet 41 Reputation points
2022-11-08T01:53:10.73+00:00

Hi thank you @CosmogHong-MSFT @Olaf Helper @Pio Virzi , I also have an issue with this other Query it keeps saying

Failed to execute query. Error: There are fewer columns in the INSERT statement than values specified in the VALUES clause. The number of values in the VALUES clause must match the number of columns specified in the INSERT statement.

INSERT INTO Unit_Building
VALUES
(200,109,3,1,1,1, SQUARE (110)),
(201,111,1,2,1,1, SQUARE (125)),
(202,112,2,3,1,1, SQUARE (130)),
(203,113,3,1,1,1, SQUARE (140)),
(204,114,4,1,1,1, SQUARE (150)),
(205,115,2,3,1,1, SQUARE (120)),
(206,116,1,1,1,1, SQUARE (180)),
(207,117,4,2,1,1, SQUARE (190)),
(208,118,3,1,1,1, SQUARE (175)),
(209,119,3,2,1,1, SQUARE (200));

Azure SQL Database
SQL Server
SQL Server
A family of Microsoft relational database management and analysis systems for e-commerce, line-of-business, and data warehousing solutions.
12,692 questions
Transact-SQL
Transact-SQL
A Microsoft extension to the ANSI SQL language that includes procedural programming, local variables, and various support functions.
4,552 questions
{count} votes

3 answers

Sort by: Most helpful
  1. CosmogHong-MSFT 22,861 Reputation points Microsoft Vendor
    2022-11-08T02:25:51.823+00:00

    Hi @Mary Sachet

    Error: There are fewer columns in the INSERT statement than values specified in the VALUES clause. The number of values in the VALUES clause must match the number of columns specified in the INSERT statement.

    You have 4 columns in the insert( [Number_of_bedrooms],[Number_of_Kitchens],[Number_of_livingrooms],[Unit_area] ). However you are passing 7 values: (200,109,3,1,1,1, SQUARE (110)),
    As the error said, the number of values in the VALUES clause must match the number of columns specified in the INSERT statement.

    Best regards,
    LiHong


  2. Mary Sachet 41 Reputation points
    2022-11-08T03:38:09.52+00:00

    This is how it looks like I have changed it around now its saying this

    Failed to execute query. Error: Incorrect syntax near the keyword 'VALUES'.

    INSERT INTO Unit_Building (Unit_Building_Number, Public_Housing_Number, Number_of_bedrooms,Number_of_Kitchens,Number_of_livingrooms, Unit_area
    VALUES
    (200,109,3,1,1,tinyint(110)),
    (201,111,1,2,1,tinyint(125)),
    (202,112,2,3,1,tinyint(130)),
    (203,113,3,1,1,tinyint(140)),
    (204,114,4,1,1,tinyint(150)),
    (204,114,4,1,1,tinyint(150)),
    (204,114,4,1,1,tinyint(150)),
    (205,115,2,3,1,tinyint(120)),
    (206,116,1,1,1,tinyint(180)),
    (207,117,4,2,1,tinyint(190)),
    (208,118,3,1,1,tinyint(175)),
    (209,119,3,2,1,tinyint(200));


  3. Mary Sachet 41 Reputation points
    2022-11-08T06:03:55.707+00:00

    where would I insert this ALTER TABLE Unit_Building ALTER COLUMN Unit_area INT;