Click here to Skip to main content
Licence CPOL
First Posted 10 Jan 2007
Views 15,777
Downloads 111
Bookmarked 13 times

A Little Sqlserver Script Helper

By | 17 Jan 2007 | Article
When you want to get the data script from sqlserver, use this, it can be fun.

Introduction

I found that it is hard to get data script from SQL Server 2005, so I made this little tool to do the job. You can update it in your own style. Have fun!

Step 1: Get the tables within the database.

Step 2: Get the data script by selected table.

Step 3: Copy the data to clipboard.

It's only raw code, more upgrades in the future.

This is GetFields() method to assemble the fields:

private string GetFields(Type t, object Value)
{            
 string strLeft = "'";
 string strRight = "'";
 if (t == typeof(Int32) || t == typeof(int) || t == typeof(Int16) || t == typeof(Int64))
 {
 return Value.ToString();
 }

 if (t == typeof(string))
 {
   return "N" + strLeft + Value.ToString() + strRight;
 }
 return strLeft + Value.ToString() + strRight;
}

To get the tables within the dababase, use this:

SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_TYPE = 'BASE TABLE'

Updated

  1. Add update script for single and multi table
  2. Add update and insert script for sync between source and destination databases
  3. Add TABLE_CONSTRAINTS

To use this, click More.

Start the main UI

Then click GenAll, by gen script between the 2 databases.

Sample screenshot

You can update it in your own style, then you'll get your script helper!

Thanks for your feedback!

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

About the Author

ddrk

Program Manager

China China

Member



Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
QuestionAre you Chinese? Pinmembersunweichao14:36 5 Feb '09  
GeneralIt's easy to use! Pinmemberlemonex@163.com19:20 20 Jan '07  
GeneralA challenge... PinmemberESTANNY6:22 11 Jan '07  
GeneralRe: A challenge... Pinmemberddrk15:07 11 Jan '07  
GeneralSource code missing PinmemberTony Bermudez15:48 10 Jan '07  
QuestionRe: Source code missing Pinmemberddrk16:19 10 Jan '07  

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Mobile
Web02 | 2.5.120517.1 | Last Updated 18 Jan 2007
Article Copyright 2007 by ddrk
Everything else Copyright © CodeProject, 1999-2012
Terms of Use
Layout: fixed | fluid