Click here to Skip to main content
15,888,968 members
Articles / Programming Languages / C#
Article

A Little Sqlserver Script Helper

Rate me:
Please Sign up or sign in to vote.
3.55/5 (4 votes)
17 Jan 2007CPOL 32.6K   392   14   7
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:

C#
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:

SQL
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)


Written By
Program Manager
China China
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
QuestionAre you Chinese? Pin
sunweichao5-Feb-09 14:36
sunweichao5-Feb-09 14:36 
AnswerRe: Are you Chinese? Pin
ddrk5-Dec-13 20:44
ddrk5-Dec-13 20:44 
GeneralIt's easy to use! Pin
lemonex@163.com20-Jan-07 19:20
lemonex@163.com20-Jan-07 19:20 
GeneralA challenge... Pin
ESTAN11-Jan-07 6:22
ESTAN11-Jan-07 6:22 
GeneralRe: A challenge... Pin
ddrk11-Jan-07 15:07
ddrk11-Jan-07 15:07 
GeneralSource code missing Pin
Tony Bermudez10-Jan-07 15:48
Tony Bermudez10-Jan-07 15:48 
Source code links are broken.
QuestionRe: Source code missing Pin
ddrk10-Jan-07 16:19
ddrk10-Jan-07 16:19 

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

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