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.
| Author |
Topic |
|
gannina
Starting Member
5 Posts |
Posted - 2008-03-07 : 15:51:30
|
| Hi, I just started using SQL Server 2005 and I'm trying to find out how to do a sql dump on a table, but this is proving more challenging then it should be. I usually use mysql with a program called navicat, and all you do is right click on the table and select dump... Inserting the data back in is just as simple. I have also used sql server 2000 awhile back and I know there was a dumping utility for it.Can someone point me in the right direction on how to dump data to a .sql file and reinsert that data? Thanks! |
|
|
spirit1
Cybernetic Yak Master
11752 Posts |
Posted - 2008-03-07 : 16:05:15
|
| you mean generate the insert statements?_______________________________________________Causing trouble since 1980blog: http://weblogs.sqlteam.com/mladenpSSMS Add-in that does a few things: www.ssmstoolspack.com |
 |
|
|
gannina
Starting Member
5 Posts |
Posted - 2008-03-07 : 16:47:30
|
| Generate the table structure and the insert statements |
 |
|
|
spirit1
Cybernetic Yak Master
11752 Posts |
Posted - 2008-03-07 : 17:18:38
|
| well management studio doesn't have insert script generation built in.it does have scripting of db schema though.for generating insert statements:you can use this if you want a T-SQL wayhttp://vyaskn.tripod.com/code.htm#insertsor you can use SSMS Tools Pack add-in for Management Studio 2005you can download it from the link below._______________________________________________Causing trouble since 1980blog: http://weblogs.sqlteam.com/mladenpSSMS Add-in that does a few things: www.ssmstoolspack.com |
 |
|
|
jdaman
Constraint Violating Yak Guru
354 Posts |
Posted - 2008-03-07 : 17:50:04
|
You could use this script that I think I stole from Peso (I dont remember for sure):USE AdventureWorks2000declare @TABLE_NAME sysnamedeclare @TABLE_SCHEMA sysnamedeclare @sql nvarchar(4000)declare @table_alias sysnameset @TABLE_NAME = 'Address'set @TABLE_SCHEMA = 'dbo'set @table_alias = 'a'set @sql = ''select @sql = @sql+ case when a.ORDINAL_POSITION = 1 then 'select'+char(13)+Char(10) else '' end+ char(9)+ @table_alias+'.'+ quotename(a.COLUMN_NAME)+ case when a.ORDINAL_POSITION = b.LAST_ORDINAL_POSITION then '' else ',' end+ char(13)+Char(10)+ case when a.ORDINAL_POSITION = b.LAST_ORDINAL_POSITION then 'into'+char(13)+Char(10)+char(9)+'#temp'+char(13)+Char(10)+ 'from'+char(13)+Char(10)+char(9)+ quotename(@TABLE_SCHEMA)+'.'+quotename(@TABLE_NAME)+' '+@table_alias else '' endfrom INFORMATION_SCHEMA.COLUMNS a cross join ( select LAST_ORDINAL_POSITION = max(bb.ORDINAL_POSITION) from INFORMATION_SCHEMA.COLUMNS bb where bb.TABLE_SCHEMA = @TABLE_SCHEMA and bb.TABLE_NAME = @TABLE_NAME ) bwhere a.TABLE_SCHEMA = @TABLE_SCHEMA and a.TABLE_NAME = @TABLE_NAMEorder by a.ORDINAL_POSITION--exec (@sql)select [@sql] = @sql |
 |
|
|
gannina
Starting Member
5 Posts |
Posted - 2008-03-07 : 18:34:41
|
| Thanks a lot for the help! I ended up installing the SMSS Tools and it works great. I'm just shocked that something like that isn't included in SQL Server by default, seems like an essential feature to me... |
 |
|
|
spirit1
Cybernetic Yak Master
11752 Posts |
Posted - 2008-03-07 : 18:39:00
|
| note that the ssms tools pack only scripts binary data up to 5 Mb._______________________________________________Causing trouble since 1980blog: http://weblogs.sqlteam.com/mladenpSSMS Add-in that does a few things: www.ssmstoolspack.com |
 |
|
|
|
|
|