.NET Programming With Me

SQL update from one Table to another based on an ID


The simple Way to copy the content from one table to other is as follow:

UPDATE Table2
SET t2.FieldName1 = t1.FieldName, t2.FieldName2 = t1.FieldName2
FROM Table1 t1, Table2 t2
WHERE t1.FieldName0 = t2.FieldName0


Example:

UPDATE t1 SET t1.InvoiceNumber = t2.sn
FROM [Transaction] t1,
     (SELECT row_number() over (order by dttmCreated asc) as sn, id FROM [Transaction] 

       WHERE Convert(date,dttmCreated) >= Convert(date,'2018-05-17')) t2
WHERE t1.id = t2.id



Original article here...

SQL Server : How to find the table size?

sp_spaceused 'tablename'