Question : Increment Field Record by 1

I want to import a series of csv files into my db tables every morning. But the existing tables already have a Primary key (Int, no nulls) with a seed of 1 and increment of 1, and for whatever reason, I cannot get the imports to work without failing due to No Nulls in that key column. I tried to bring the CSV's into temp files and then increment a column by 1 to create the key before pulling the temp into the real tables but I don't not know how to get that to increment. Am I going about this the wrong way? Any suggestions?  

Answer : Increment Field Record by 1

The identity column cannot be added to. You need to allow it to autogrow the way it wants (or you can override, but often leads to further problems).

If you are inserting new rows into the destination table, then best to simply ignore that identity column in the insert altogether and allow SQL to take care of it for you.

I believe you should always use a staging table for this type of process, regardless of the current identity column usage. That way you can validate the import before committing to the live table.

1) Import CSV to Staging Table
2) Validate data in Staging Table (can include checking for dupes and other yucky bits like datatype conversions)
3) Insert into Live Table (spell out columns that you want to populate leaving out the identity column of the destination "live table" ) select from staging table
4) Tidy up / archive CSV when all processing is complete


Random Solutions  
 
programming4us programming4us