Unix Date Format to SQL DateTime

Epoch to SQL Date Time

Advertisements
Read more "Unix Date Format to SQL DateTime"

Script to Generate Dynamic Insert Into statments

Use below script to have dynamic Insert into statments.

Typically may be used to replicate data from one database to another

SELECT DISTINCT ‘SET IDENTITY_INSERT ‘+TABLENAME +’ ON’+’ INSERT INTO ‘+ TABLENAME+’ (‘+(STUFF((
SELECT ‘, ‘ + name
FROM SYS.COLUMNS Z
WHERE Z.object_id=Y.object_id

AND Y.object_id=OBJECT_ID(C.TABLENAME)

FOR XML PATH(”)
), 1, 2, ”)) +’ )’
+
‘SELECT ‘ + (STUFF((
SELECT ‘, ‘ + name
FROM SYS.COLUMNS Z
WHERE Z.object_id=Y.object_id

AND Y.object_id=OBJECT_ID(C.TABLENAME)

FOR XML PATH(”)
), 1, 2, ”))+ ‘ FROM ‘+TABLENAME +’ SET IDENTITY_INSERT ‘+TABLENAME+’ OFF’

FROM (

SELECT [Tables].name AS [TableName],
SUM([Partitions].[rows]) AS [TotalRowCount]
FROM sys.tables AS [Tables]
JOIN sys.partitions AS [Partitions]
ON [Tables].[object_id] = [Partitions].[object_id]
AND [Partitions].index_id IN ( 0, 1 )
WHERE [Tables].name like ‘HL7%’ — Change table Name here
GROUP BY SCHEMA_NAME(schema_id), [Tables].name) AS C

INNER JOIN SYS.COLUMNS Y ON Y.object_id=OBJECT_ID(C.TABLENAME)
WHERE TotalRowCount >0

Read more "Script to Generate Dynamic Insert Into statments"

Merge Join

Merge join is a strategy which sql servers takes up when condition on which the table is joined is a column which is ordered ; this happens when lets say that two table T1, T2 have columns T1C and T2C T1C and T2C are the columns on which the tables are joined these both columns […]

Read more "Merge Join"

Joins Of SQL Server

So this comes in to your mind that the joins in sql are Inner join, left join , right join , cross join well the thing is that sql server does not know that, for sql server its just syntax which is decoded and sql server works on it in the following three plans. Merge […]

Read more "Joins Of SQL Server"

Back up Types

Three types of back up : Full Differential Transnational Full As the name suggests, Full Copy involves taking back up of all the database this also includes log files, this enables to restore database to the state where the backup was taken Differential This involves taking the copy of the latest changed data, a Differential […]

Read more "Back up Types"