Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 insert test data into my table

Author  Topic 

abenitez77
Yak Posting Veteran

53 Posts

Posted - 2011-10-21 : 09:28:18
I have a db that I want to insert test data into. I want to enter in specific info.

table name: demo_ImageTable
Columns: RecKey(int), ImageSeq(int), ImagePath(varchar), ImageName(varchar)

I want to insert data to this table.

I want Reckey to be incremental by "1", starting with "51"
ImageSeq is a set value - "2"
ImagePath is a set value (\\usatl02eras40\Audit Strategy\ASTRATEGY\Projects\Middleware\Demo\Claims\)
ImageName is "SupportDoc.pdf" with a number at the end of the name, incrementing with every record (ie, "SupportDoc1.pdf", "SupportDoc2.pdf", etc..) starting with number "1".

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2011-10-21 : 09:33:00
make reckey as identity type with seed as 1 and increment as 1 ie IDENTITY(1,1)
and make insert like


INSERT INTO demo_ImageTable (ImageSeq, ImagePath, ImageName)
SELECT 2,
'\\usatl02eras40\Audit Strategy\ASTRATEGY\Projects\Middleware\Demo\Claims\',
'SupportDoc'+ CAST(number AS varchar(2)) + '.pdf'
FROM master..spt_values
WHERE type='p'
AND number BETWEEN 1 AND 51


------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

abenitez77
Yak Posting Veteran

53 Posts

Posted - 2011-10-21 : 09:54:32
reckey can't be an identity column. It already has data in it and it can have duplicate values. Also, I said below incremental by "1" , starting with "51". I was wrong, it should be incremental by "1", starting with "1". Think of it as a value that is a primary key of another table.
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2011-10-21 : 10:00:46
quote:
Originally posted by abenitez77

reckey can't be an identity column. It already has data in it and it can have duplicate values. Also, I said below incremental by "1" , starting with "51". I was wrong, it should be incremental by "1", starting with "1". Think of it as a value that is a primary key of another table.


then put it as number itself


INSERT INTO demo_ImageTable (RecKey,ImageSeq, ImagePath, ImageName)
SELECT number,2,
'\\usatl02eras40\Audit Strategy\ASTRATEGY\Projects\Middleware\Demo\Claims\',
'SupportDoc'+ CAST(number AS varchar(2)) + '.pdf'
FROM master..spt_values
WHERE type='p'
AND number BETWEEN 1 AND 51


------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

abenitez77
Yak Posting Veteran

53 Posts

Posted - 2011-10-21 : 10:21:33
thanks! worked great.
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2011-10-21 : 10:29:00
wc

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -