SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Script all data of a table


Script all data of a table

Author
Message
Florian Reischl
Florian Reischl
SSCrazy Eights
SSCrazy Eights (8.6K reputation)SSCrazy Eights (8.6K reputation)SSCrazy Eights (8.6K reputation)SSCrazy Eights (8.6K reputation)SSCrazy Eights (8.6K reputation)SSCrazy Eights (8.6K reputation)SSCrazy Eights (8.6K reputation)SSCrazy Eights (8.6K reputation)

Group: General Forum Members
Points: 8577 Visits: 3934
Comments posted to this topic are about the item Script all data of a table


The more I learn, the more I know what I do not know
Blog: Things about Software Architecture, .NET development and T-SQL

How to Post Data/Code to get the best Help How to Post Performance Problems
Linson.Daniel
Linson.Daniel
SSC-Addicted
SSC-Addicted (417 reputation)SSC-Addicted (417 reputation)SSC-Addicted (417 reputation)SSC-Addicted (417 reputation)SSC-Addicted (417 reputation)SSC-Addicted (417 reputation)SSC-Addicted (417 reputation)SSC-Addicted (417 reputation)

Group: General Forum Members
Points: 417 Visits: 391
Nice script there, I too had written a similar script

http://www.sqlservercentral.com/scripts/insert+script+generator/65407/

but the bad thing about mine would be the fact that I had made use of cursors....and also since it was written for sql server 2000 it has its limitation when tried in 2005.....
dipetersen
dipetersen
SSC Journeyman
SSC Journeyman (80 reputation)SSC Journeyman (80 reputation)SSC Journeyman (80 reputation)SSC Journeyman (80 reputation)SSC Journeyman (80 reputation)SSC Journeyman (80 reputation)SSC Journeyman (80 reputation)SSC Journeyman (80 reputation)

Group: General Forum Members
Points: 80 Visits: 10
When I used it, there was an Error if the @column_names = 0. The word VALUES would concatenate at the end of the table name without a space(i.e. INSERT INTO dbo.FolderLevelLookupVALUES (0, 'None')
) . I just added a space before the word VALUES to fix it in the script.

...

PRINT ' '' VALUES ('' +'

...


Great script. Thanks


Kindest Regards,

David Petersen
dipetersen.com
Florian Reischl
Florian Reischl
SSCrazy Eights
SSCrazy Eights (8.6K reputation)SSCrazy Eights (8.6K reputation)SSCrazy Eights (8.6K reputation)SSCrazy Eights (8.6K reputation)SSCrazy Eights (8.6K reputation)SSCrazy Eights (8.6K reputation)SSCrazy Eights (8.6K reputation)SSCrazy Eights (8.6K reputation)

Group: General Forum Members
Points: 8577 Visits: 3934
Linson.Daniel (6/17/2009)
Nice script there, I too had written a similar script

http://www.sqlservercentral.com/scripts/insert+script+generator/65407/

but the bad thing about mine would be the fact that I had made use of cursors....and also since it was written for sql server 2000 it has its limitation when tried in 2005.....

Hi Daniel

Sorry for the very late answer!! Seems I lost the response mail...

Just had a look at your script, maybe you should include QUOTENAME or REPLACE to avoid SQL injection by "'". For smaller tables cursors should be okay.


The more I learn, the more I know what I do not know
Blog: Things about Software Architecture, .NET development and T-SQL

How to Post Data/Code to get the best Help How to Post Performance Problems
Florian Reischl
Florian Reischl
SSCrazy Eights
SSCrazy Eights (8.6K reputation)SSCrazy Eights (8.6K reputation)SSCrazy Eights (8.6K reputation)SSCrazy Eights (8.6K reputation)SSCrazy Eights (8.6K reputation)SSCrazy Eights (8.6K reputation)SSCrazy Eights (8.6K reputation)SSCrazy Eights (8.6K reputation)

Group: General Forum Members
Points: 8577 Visits: 3934
dipetersen (7/10/2009)
When I used it, there was an Error if the @column_names = 0. The word VALUES would concatenate at the end of the table name without a space(i.e. INSERT INTO dbo.FolderLevelLookupVALUES (0, 'None')
) . I just added a space before the word VALUES to fix it in the script.

...

PRINT ' '' VALUES ('' +'

...


Great script. Thanks


Thanks for the feedback! :-)

Thanks also for the bug report, I will fix this. Usually it takes some days until it becomes updated by admins.


The more I learn, the more I know what I do not know
Blog: Things about Software Architecture, .NET development and T-SQL

How to Post Data/Code to get the best Help How to Post Performance Problems
Chirag Prajapati
Chirag Prajapati
Say Hey Kid
Say Hey Kid (670 reputation)Say Hey Kid (670 reputation)Say Hey Kid (670 reputation)Say Hey Kid (670 reputation)Say Hey Kid (670 reputation)Say Hey Kid (670 reputation)Say Hey Kid (670 reputation)Say Hey Kid (670 reputation)

Group: General Forum Members
Points: 670 Visits: 77
Hi,

Excellent Script.

I m not sure whether you have updated it or not.
But it gives error in some cases where datatype is used as DbStamp of in case of Datetime.

Thanks,
Chirag.
Florian Reischl
Florian Reischl
SSCrazy Eights
SSCrazy Eights (8.6K reputation)SSCrazy Eights (8.6K reputation)SSCrazy Eights (8.6K reputation)SSCrazy Eights (8.6K reputation)SSCrazy Eights (8.6K reputation)SSCrazy Eights (8.6K reputation)SSCrazy Eights (8.6K reputation)SSCrazy Eights (8.6K reputation)

Group: General Forum Members
Points: 8577 Visits: 3934
Hi Craig

Chirag Prajapati (8/10/2009)
But it gives error in some cases where datatype is used as DbStamp of in case of Datetime.

Thanks for the feedback!

Could you explain the error and how it happens? What do you mean with DbStamp?

Greets
Flo


The more I learn, the more I know what I do not know
Blog: Things about Software Architecture, .NET development and T-SQL

How to Post Data/Code to get the best Help How to Post Performance Problems
sbowell
sbowell
SSC Veteran
SSC Veteran (207 reputation)SSC Veteran (207 reputation)SSC Veteran (207 reputation)SSC Veteran (207 reputation)SSC Veteran (207 reputation)SSC Veteran (207 reputation)SSC Veteran (207 reputation)SSC Veteran (207 reputation)

Group: General Forum Members
Points: 207 Visits: 118
Hi,

Love the script.

I had a small problem when I tried running it due to the collation being wrong. I was getting the error

Cannot resolve collation conflict for column 1 in SELECT statement.

To fix this I changed the following at the end of the script

-- Script the end of the statement
PRINT ' '') COLLATE Latin1_General_CI_AS'''
PRINT ' FROM ' + @table_name

This then worked a treat.

Thanks again
gtasneem
gtasneem
Grasshopper
Grasshopper (16 reputation)Grasshopper (16 reputation)Grasshopper (16 reputation)Grasshopper (16 reputation)Grasshopper (16 reputation)Grasshopper (16 reputation)Grasshopper (16 reputation)Grasshopper (16 reputation)

Group: General Forum Members
Points: 16 Visits: 47
Nice post.
Here's a script to just update data in a particular column in a table

select
'update @tablename set @columnname = ',
'''' + @columnname + '''',
'where @primarykeycolumn = ',
@primarykeycolumn
from @tablename

It generates a script which when run, updates that particular column in that table.
Jeff Moden
Jeff Moden
SSC Guru
SSC Guru (208K reputation)SSC Guru (208K reputation)SSC Guru (208K reputation)SSC Guru (208K reputation)SSC Guru (208K reputation)SSC Guru (208K reputation)SSC Guru (208K reputation)SSC Guru (208K reputation)

Group: General Forum Members
Points: 208427 Visits: 41973
I missed this before, Flo... it's written well enough that it probably should have been an article. Well done.

--Jeff Moden

RBAR is pronounced ree-bar and is a Modenism for Row-By-Agonizing-Row.
First step towards the paradigm shift of writing Set Based code:
Stop thinking about what you want to do to a row... think, instead, of what you want to do to a column.
If you think its expensive to hire a professional to do the job, wait until you hire an amateur. -- Red Adair

Helpful Links:
How to post code problems
How to post performance problems
Forum FAQs
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search