Will my Query affect any rows in the DB??

  • Dear All,

    Hope you are doing well. I am really new to SQL and was wondering whether anyone could just quickly confirm somethinng for me.

    I want write an SQL Query that would create an output which I want to export as a csv. I have already created the query which uses SELECT, CASE, FROM and WHERE. I wanted to run this query in the query window of SQL Server Management Studio, take the output on the bottom of the screen, right click and hit export as csv.

    I'm pretty sure it won't affect any rows in the raw database, but before I run it in the actual database, I just wanted to make sure it's safe.

    Here is what the  Query will look like

    SELECT OrderID,

    CASE

    WHEN OrderID = 10248 OR OrderID = 10250 THEN Quantity*-1

    ELSE Quantity

    END AS NewQty

    FROM OrderDetails

    WHERE OrderID <> 10249 AND OrderID <> 10251

    Note I changed the column names etc. to match w3 sql sandbox i.e. https://www.w3schools.com/sql/trymysql.asp?filename=trysql_case I will just change the column names to match the actual SQL server column names before running the query if you guys can confirm that this won't affect any rows or columns.

     

  • No, a select doesn't insert, delete, or update data.

  • This was removed by the editor as SPAM

  • As @ratbak says, a SELECT won't affect data in tables. Any given SELECT operation can cause blocking as it uses resources, which can slow down things. However, that's extremely common and shouldn't be a concern. You're right to worry about the data in the database. Keep going on your learning.

    "The credit belongs to the man who is actually in the arena, whose face is marred by dust and sweat and blood"
    - Theodore Roosevelt

    Author of:
    SQL Server Execution Plans
    SQL Server Query Performance Tuning

  • Thank you for confirming with me RatBak. appreciate your help

  • Hi Grant, Thank you for your kind words of motivation. Looking forward to expand the learning.

Viewing 6 posts - 1 through 5 (of 5 total)

You must be logged in to reply to this topic. Login to reply