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
- Add update script for single and multi table
- Add update and insert script for sync between source and destination databases
- Add
TABLE_CONSTRAINTS
To use this, click More.
Then click GenAll, by gen script between the 2 databases.
You can update it in your own style, then you'll get your script helper!
Thanks for your feedback!