Advertisement
makispaiktis

Query 4 - Update table, delete records, temporary tables

Jun 6th, 2023
1,121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
SQL 0.97 KB | Source Code | 0 0
  1. USE [AdventureWorks2012]
  2.  
  3. SELECT * FROM [Production].[Product]
  4. SELECT Name, ListPrice FROM [Production].[Product]
  5.  
  6. -- Calculated columns
  7. SELECT Name, ListPrice, ListPrice + 10
  8. AS AdjustedListPrice
  9. FROM [Production].[Product]
  10.  
  11. -- I want it to be stored in a different table
  12. SELECT Name, ListPrice, ListPrice + 10
  13. AS AdjustedListPrice
  14. INTO [Production].[Product2]
  15. FROM [Production].[Product]
  16.  
  17. SELECT * FROM [Production].[Product2]
  18.  
  19. -- Temporary table only for me, this table will vanish after I close the window
  20. -- Even a new session-query file can not "see" it
  21. SELECT Name, ListPrice, ListPrice + 10
  22. AS AdjustedListPrice
  23. INTO #TempTable
  24. FROM [Production].[Product]
  25.  
  26. SELECT * FROM #TempTable
  27.  
  28. -- Delete data from table
  29. DELETE FROM [Production].[Product2]
  30. WHERE Name LIKE 'Bearing Ball'
  31.  
  32. SELECT * FROM [Production].[Product2]
  33.  
  34. -- Update statement
  35. UPDATE [Production].[Product2]
  36. SET Name = 'Blade_new'
  37. WHERE Name LIKE 'BLADE'
  38.  
  39. SELECT * FROM [Production].[Product2]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement