Posts

Showing posts with the label SMSS

How to Delete Table with Join Statement

Similar to my previous post on how to update with multiple join statements , this time, I need to delete rows in a table, but with extra criteria which made me need to join the table before deleting the rows. To do this, there are several ways, however, I found this method is the easiest: DELETE A FROM TABLE1 A LEFT JOIN TABLE2 B ON A.ROWID = B.ROWID WHERE A.first_name = 'James' AND B.last_name = 'Bond'

How to UPDATE multiple tables in Microsoft SQL using JOIN query

Sometimes the update query needs to target a complex query and therefore you will need to use this. SQL Syntax: UPDATE      t1 SET      t1.field = value    FROM      t1     [INNER | LEFT] JOIN t2 ON join_predicate    .. WHERE      where_predicate; And MySQL Syntax: UPDATE t1 [INNER | LEFT JOIN] JOIN t2 ON join_predicate SET T1.field = value WHERE condition

How to get size of each table using SQL Management Studio

Image
Sometimes your DB storage bloated so much, without knowing what caused it. Fortunately, there is an easy way to check using SQL Management Studio (SMSS). In this scenario, I am using SQL Management Studio 18. Open SQL Management Studio and connect to your DB Click View -> Object Explorer (F7) -> Databases From the list of databases, navigate to the DB you want to investigate Right-click on the header of the table list, choose Data Space Used (KB) Click on the Data Space header to sort based on the biggest to lowest data usage. Not surprising, usually the culprit is the log that does not have an auto-delete function.