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.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 SQL Compare

Author  Topic 

h8Society
Starting Member

7 Posts

Posted - 2007-10-27 : 16:04:08
Hi all !

i'm new in sql and new in database.

And my question :

i m trying to compare sql database tables,views,columns,stored procedures.

First i compared tables,columns, but i can't do it with stored Procedure.



Why ? Because stored Procedures are code...

Ex... When i Compare table and columns use these codes.

"if (sourceColumn.IsString)
{
strSize = sourceColumn.Type.ToString()+"(" + sourceColumn.Size + ")";
sqlAddColumn = string.Format(@"ALTER TABLE {0} ADD {1} {2}", target.Name, sourceColumn.Name.ToString(), strSize);

....
This is my StoredProcedure Compare method

public string Compare(StoredProcedure storedTarget)

{
string storedScript = string.Empty;
if (storedTarget.RoutineDefinition != this.RoutineDefinition)
{
// string storedScript = (@"ALTER PROCEDURE ); <--- How can i put new stored procedure ?????? What is sql code for this work ?
}
}
Thank You all sql guru s

rmiao
Master Smack Fu Yak Hacker

7266 Posts

Posted - 2007-10-27 : 16:14:04
Is it for sql server? I believe you can find something by searching this site.
Go to Top of Page

dataguru1971
Master Smack Fu Yak Hacker

1464 Posts

Posted - 2007-10-27 : 16:16:33
You would have to have the entire procedure spelled out as you want it altered. Assuming you simply want to alter the procedure so that it equals the stored script you would just append the Procedure name to be modified and the replacement script (based on your C# it looks like you are storing 1 and comparing it to the other, just append the stored one into the @"Alter Proc" string you are creating.
Go to Top of Page

h8Society
Starting Member

7 Posts

Posted - 2007-10-27 : 17:00:16
Yes it is for sql server.

and i want to say that... Ýt doesn't matter what codes "stored procedures" are.

Only i want to add or drop them.

public string Compare(StoredProcedure storedTarget)

{
string storedScript = string.Empty;
if (storedTarget.RoutineDefinition != this.RoutineDefinition)
{
string storedScript = // ex. DROP target's "stored procedure" and "ADD" source's to target's stored procedure
}
}
}
Go to Top of Page

dataguru1971
Master Smack Fu Yak Hacker

1464 Posts

Posted - 2007-10-27 : 18:34:43
Well the script would be the same essentially, but you don't add proc's you Create them.

"Drop Proc [ProcedureName]" or "Create Proc [ProcedureName]"
Go to Top of Page

h8Society
Starting Member

7 Posts

Posted - 2007-10-28 : 04:00:53
Thank you !

i did both of them.
Go to Top of Page
   

- Advertisement -