Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Insert SP takes Forever
Message
 
 
To
25/02/2016 11:12:40
General information
Forum:
Microsoft SQL Server
Category:
Stored procedures, Triggers, UDFs
Environment versions
SQL Server:
SQL Server 2008 R2
Miscellaneous
Thread ID:
01632022
Message ID:
01632058
Views:
31
>>Couple of questions:
>>
>>1. Why timestamp column defined as nullable? Are you allowing NULLs there? If not, make it not nullable. Check also other columns if they really should allow NULLs or not.
>
>The data is being imported from spreadsheets and the value in the timestamp column of the spreadsheet can possibly be null, so can almost any of the columns.
>
>>
>>2. What are these 2 columns - [OID] [nvarchar](max) NULL,
>> [PNR] [nvarchar](max) NULL, and why they are nvarchar(max)?
>>
>
>I have inherited the database recently so I do not know the thinking behind the field definitions. They really don't look like they should be huge values so I'll see if I can change them without causing too many changes in the code.
>
>>Also, you're then trying to check for existence based on the nvarchar(max) parameter (and timestamp but I don't see an index on timestamp). It will be a table scan and it will be really slow. Can you use something better for checking if row already existed?
>>
>
>No, those are the fields that determin if the record exists already or not. I suppose I could create the relevant indexes if necessary.
>
>>3. Instead of IF EXISTS INSERT I suggest to use MERGE command. It should be much better.
>>
>
>I've never heard of MERGE, I'll check it out.
>
You would not be able to create an index on nvarchar(max) column, that's why I suggest to chose appropriate type for all your columns.
If it's not broken, fix it until it is.


My Blog
Previous
Reply
Map
View

Click here to load this message in the networking platform