Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Insert SP takes Forever
Message
 
 
À
25/02/2016 11:12:40
Information générale
Forum:
Microsoft SQL Server
Catégorie:
Stored procedures, Triggers, UDFs
Versions des environnements
SQL Server:
SQL Server 2008 R2
Divers
Thread ID:
01632022
Message ID:
01632058
Vues:
29
>>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
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform