﻿<?xml version='1.0' encoding='UTF-8'?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/"><channel><title>SQLServerCentral / SQL Server 2008 / SQL Server Newbies  / it takes too long to insert data to different tables / Latest Posts</title><generator>InstantForum.NET v2.9.0</generator><description>SQLServerCentral</description><link>http://www.sqlservercentral.com/Forums/</link><webMaster>notifications@sqlservercentral.com</webMaster><lastBuildDate>Sun, 19 May 2013 21:54:04 GMT</lastBuildDate><ttl>20</ttl><item><title>RE: it takes too long to insert data to different tables</title><link>http://www.sqlservercentral.com/Forums/Topic1422131-1292-1.aspx</link><description>Why do 1 insert call per temp table row on a 10,000 row temp table?justINSERTINTO [dbo].[Computers]([NetBIOSName], [IP])select netbiosname,ip from temptablewhere temptable.netbiosname not in ( select netbiosname from computers))</description><pubDate>Thu, 21 Feb 2013 13:05:11 GMT</pubDate><dc:creator>bdloving 4446</dc:creator></item><item><title>RE: it takes too long to insert data to different tables</title><link>http://www.sqlservercentral.com/Forums/Topic1422131-1292-1.aspx</link><description>thank you for tips. Very respectful.</description><pubDate>Thu, 21 Feb 2013 08:33:16 GMT</pubDate><dc:creator>huy1002</dc:creator></item><item><title>RE: it takes too long to insert data to different tables</title><link>http://www.sqlservercentral.com/Forums/Topic1422131-1292-1.aspx</link><description>Agreed.  Make sure you have a PK on the table.  If it were me, I would make an integer field as the primary key and add a unique nonclustered index to the computer name field so SQL won't worry about sort order based on a string field.One more tip - use an appropriate data type for the computer name before you index it.  If you're storing computer names, you probably don't need an nvarchar(max) or anything like that.  More companies have strict policies on computer names, so get yours and go 2 bytes beyond it for when they exceed their own limit.</description><pubDate>Thu, 21 Feb 2013 06:44:44 GMT</pubDate><dc:creator>Ed Wagner</dc:creator></item><item><title>RE: it takes too long to insert data to different tables</title><link>http://www.sqlservercentral.com/Forums/Topic1422131-1292-1.aspx</link><description>[quote][b]huy1002 (2/20/2013)[/b][hr]I was trying to dump data from a Temp table to 4 different tables (Computers,  ComputerInfo, Vulnerabilities, and AuditInfo) in C# with different methods I created in classes.if (_NetBIOSName != string.Empty){//Only add the computers that are not existed in Computers tableAddCompSucc = cc.AddComputer(_NetBIOSName, _IP);  //add compputer's detailsCompId = cc.GetComputer(_NetBIOSName).ID;AddCompInfoSucc = cci.AddComputerInfo(CompId, _DNSName, _MAC, _OS, _NetBIOSDomain);//add vulneribilitiesAddIavSucc = ciav.AddIAVulnerability(CompId, _IAV, _Name, _AuditDate, 0);//add audit detailsIavId = ciav.GetIAVulnerability(CompId, _IAV, _Name, _AuditDate).ID;AddAuditInfoSucc = cai.AddAuditInfo(IavId, _AuditID, _AuditDate, _SevCode, _Risk, _PCILevel, _Exploit, _Context);}In each method to insert data to tables, I used “if not exists…” statement to prevent duplicated data to be inserted.IF NOT EXISTS (SELECT DISTINCT NetBIOSNameFROM            ComputersWHERE        NetBIOSName = @NetBIOSName) BEGIN    INSERT             INTO               [dbo].[Computers]([NetBIOSName], [IP])VALUES        (@NetBIOSName,@IP) ENDIssue: it takes forever to insert data to 4 tables when the Temp database is big, like having 10000 rows.Any suggestion on how to do this differently to cut down the processing time. Very Respectfully,[/quote]Define a PK constraint - or at least a unique index on NetBIOSName column, get rid of the "IF NOT EXIST" block, handle the duplicate key exception.Hope this helps.</description><pubDate>Wed, 20 Feb 2013 17:37:56 GMT</pubDate><dc:creator>PaulB-TheOneAndOnly</dc:creator></item><item><title>it takes too long to insert data to different tables</title><link>http://www.sqlservercentral.com/Forums/Topic1422131-1292-1.aspx</link><description>I was trying to dump data from a Temp table to 4 different tables (Computers,  ComputerInfo, Vulnerabilities, and AuditInfo) in C# with different methods I created in classes.if (_NetBIOSName != string.Empty){//Only add the computers that are not existed in Computers tableAddCompSucc = cc.AddComputer(_NetBIOSName, _IP);  //add compputer's detailsCompId = cc.GetComputer(_NetBIOSName).ID;AddCompInfoSucc = cci.AddComputerInfo(CompId, _DNSName, _MAC, _OS, _NetBIOSDomain);//add vulneribilitiesAddIavSucc = ciav.AddIAVulnerability(CompId, _IAV, _Name, _AuditDate, 0);//add audit detailsIavId = ciav.GetIAVulnerability(CompId, _IAV, _Name, _AuditDate).ID;AddAuditInfoSucc = cai.AddAuditInfo(IavId, _AuditID, _AuditDate, _SevCode, _Risk, _PCILevel, _Exploit, _Context);}In each method to insert data to tables, I used “if not exists…” statement to prevent duplicated data to be inserted.IF NOT EXISTS (SELECT DISTINCT NetBIOSNameFROM            ComputersWHERE        NetBIOSName = @NetBIOSName) BEGIN    INSERT             INTO               [dbo].[Computers]([NetBIOSName], [IP])VALUES        (@NetBIOSName,@IP) ENDIssue: it takes forever to insert data to 4 tables when the Temp database is big, like having 10000 rows.Any suggestion on how to do this differently to cut down the processing time. Very Respectfully,</description><pubDate>Wed, 20 Feb 2013 08:54:57 GMT</pubDate><dc:creator>huy1002</dc:creator></item></channel></rss>