Solved

SQL Server - Keep track of changes in Management Studio as sql command

Posted on 2008-09-30
11
349 Views
Last Modified: 2012-05-05
In SQL server 2000, I'm adding some columns into tables using Management Studio. Is there any way I can get the changes into a sql script, so that I can run the script in another sql server.

Basically, I want to sql server to generate a script for me whatever I have done in sql mangement studio. Is that possible?

Thank in advance!
0
Comment
Question by:winmyan
11 Comments
 
LVL 31

Assisted Solution

by:James Murrell
James Murrell earned 100 total points
ID: 22605308
only way i can think off is once you have completed each change do a right click and select all tasks then generate script
0
 
LVL 143

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 200 total points
ID: 22605340
I agree: before SAVING the change to the table/indexes, hit the GENERATE SCRIPT button.
for stored procedures, triggers etc you just need to take the most recent version of the code.


and indeed, in sql 2005 all of this could be saved into an audit table with the DDL triggers...
0
 

Author Comment

by:winmyan
ID: 22605567
Awesome. Seem that I need to generate script for each table then. :)

Thank both of you for your help!
0
Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

 
LVL 39

Expert Comment

by:BrandonGalderisi
ID: 22605809
No... Before saving your table changes there is a button to save as change script.
0
 
LVL 39

Assisted Solution

by:BrandonGalderisi
BrandonGalderisi earned 200 total points
ID: 22605821
Right click table > modify
Make cxhanges > 
Below the "NEW QUERY" button there is a button called "Generate Change Script".  It export the changes you just made as SQL Script for you to run/save.
0
 
LVL 39

Expert Comment

by:BrandonGalderisi
ID: 22605842
Sorry, that's in SQL 2005.

In 2000

It is right below the Window Menu bar item.
0
 

Author Comment

by:winmyan
ID: 22620599
After adding columns into the existing table, I generated the script.

In the script, the temporary table is created first and copy the existing data into the temp table. Then delete the exisiting table and rename the temporary table to the deleted (old) table name.

Is it how the script is always generated (for adding columns into existing table)? Is it acceptable behavior? Does it (negative) affect in Referential integrity?

Thank you all for your responses...
0
 
LVL 39

Expert Comment

by:BrandonGalderisi
ID: 22624776
I bet you attempted to inject a column in the middle, instead of appending it to the end.  If you do, that is how it will be done.  You can add on to the end without it having to go through those steps.
0
 

Author Comment

by:winmyan
ID: 22625062
Hi BrandonGalderisi,

Yes, I'm trying to insert columns in the middle becuase I want the last column to be DateCreated. :)

Is there any work around? Thank you for your answer.
0
 
LVL 39

Expert Comment

by:BrandonGalderisi
ID: 22626115
No, there is no workaround (except the REALLY BAD IDEA I MENTION BELOW).  Also, why are you so caught up on the order of your columns.  You can select them out in any way you desire and since you should always be specifying a field list when you do an insert, that doesn't matter either.



If all you care about is putting it before the LAST column, you can always:

drop any constraints or indexes that reference datecreated
rename the column
add the new column
add the datecreated column
move the data from the old datecreated column
drop the old datecreated column
reapply any indexes and constraints

but again, why worry, the order of the fields in the table doesn't matter.
0
 

Author Closing Comment

by:winmyan
ID: 31501539
Thank you all for your Comments!
0

Featured Post

NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
SSIS GUID Variable 2 30
T-SQL to copy a database 37 65
how to make geography query faster?  SQL 7 41
Finding Where Clause Value in SQL Views and SP 21 30
JSON is being used more and more, besides XML, and you surely wanted to parse the data out into SQL instead of doing it in some Javascript. The below function in SQL Server can do the job for you, returning a quick table with the parsed data.
Ever wondered why sometimes your SQL Server is slow or unresponsive with connections spiking up but by the time you go in, all is well? The following article will show you how to install and configure a SQL job that will send you email alerts includ…
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.

685 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question