anyone know how to optimize SQL query for inserting data from select statement and so the log file won’t grow too fast? I tried WITH (NOLOCK) already. It works but the log file grow quite fast.
Currently I have SQL Scheduler to move the data from one database to another database under the same server and the same instance.
TRUNCATE TABLE Mobile.dbo.[Customer]
INSERT INTO Mobile.dbo.[Customer]
SELECT
CST.[No], CST.[Name], CST.[Address], CST.[Address 2], CST.[Post Code], CST.[City], CST.[County] AS [State],
CST.[Country_Region Code] AS [Country Code], CST.[Contact], CST.[Phone No_], CST.[Fax No_], CST.[Telex No_] AS [Mobile No_],
CST.[E-Mail], CST.[Home Page], CAST(CST.[Credit Limit] AS DECIMAL (38,2)) AS [Credit Limit],
CASE
WHEN (CAST(INV.[Amount] AS DECIMAL) IS NOT NULL) THEN CAST((INV.[Amount]) AS DECIMAL (38,2))
ELSE '0.00'
END AS [Balance],
CST.[Salesperson Code], CST.[Payment Terms], CST.[Payment Code], CST.Zone Code]
FROM Live.dbo.[Customer] AS CST
WITH (NOLOCK)
LEFT JOIN(
SELECT ORIamt.[Customer No_], SUM(ORIamt.[Amount]) AS [Amount]
FROM (
SELECT CLE.[Entry No_], CLE.[Customer No_], CLE.[Document No_], DCLE.[Amount]
FROM Live.dbo.[Entry] AS CLE
WITH (NOLOCK)
LEFT JOIN(
SELECT [Cust_ Entry No_], SUM([Amount]) AS [Amount]
FROM Live.dbo.[Detailed Entry]
WITH (NOLOCK)
GROUP BY [Cust_ Entry No_]
) DCLE ON CLE.[Entry No_] = DCLE.[Cust_ Entry No_]
) AS ORIamt
GROUP BY ORIamt.[Customer No_]
) AS INV ON INV.[Customer No_] = CST.[No_]
As you all can see, I have one database named Mobile. And Actually this database is used for showing the data only. Since this database is for showing the data only, I wonder how to optimize my SQL Scheduler and so the log file won’t grow too fast.
Since you’re truncating
Mobile.dbo.Customer, and Mobile is in Simple recovery mode, would it be feasible instead to dropMobile.dbo.Customerand then recreate it withSelect..into Mobile.dbo.Customer.., instead ofinsert into? That approach should provide the minimal logging you need.