Showing posts with label stored. Show all posts
Showing posts with label stored. Show all posts

Thursday, March 29, 2012

comparing two records field by field

Hi,
a stored proc should find all different fields in two records. This two
records are in two temp tables and have the same fields, but the
recordstructure can be different in every call of the stored proc.
For example, in one call i check the difference of two records from the
customer table, in the next call i check the difference of two records from
the orders table.
So i cannot use field names. In the moment i read all informations from
sysobjects and syscolumns and build sql strings for each column and execute
them to get the value as varchar and compare them.
But this is so performance- and timeconsuming, especially for records with
nearly 200 fields, that i have to find another way.
Any suggestions how to do this?
thanks for all tips,
HelmutIt depends on what your ultimate aim is (other than pain). If you're
just wanting some data analysis there's a tool called SQL data compare
that does that quite well.
If you're aiming for some nice dynamic query, you'll have to post a SQL
example (I'm afraid your description was a tad cryptic).
my approach when comparing things dynamically is to use the stored proc
sp_columns. Shove that up a temporary table, use sp_executesql to then
execute the compare, however it sounds like you're nearly doing that
(shouldn't be too bad performance wise - are you hitting the cursors a
bit too hard?)
I think you'll get better advice if you put some hard examples up of
what you're currently doing, and what you're wanting it to do.
As a load of people write as a generic response - "post your DDL and
code examples and maybe we can help more" - they say "more" as though
that was in some way helpful
anyway,
more info dude
Cheers
Will|||Hello Will,
thanks for your response. Here an example:
let's say, i have two backups of a database. Now i restore both backups and
have a stored proc wich loops through the persons table record by record.
There is an identity field, so i can read the same record from both backups
...
insert into #tbl1 select * from backup1.dbo.persons where id = 123
insert into #tbl2 select * from backup2.dbo.persons where id = 123
...
if both records exists, then i want to find the differences field by field,
for this i call another stored proc, and this proc knows, that it has one
record in #tbl1 and another record in #tbl2 with identical structure.
But it does not know, that this are records from table persons!
So it should do something like:
declare @.tblDiff (
fieldname varchar(20),
oldValue varchar(2000),
newValue varchar(2000) )
for x = 1 to #tbl1.fieldcount do begin
if (#tbl1.field[x].IsNull and not #tbl2.field[x].IsNull) or
(not #tbl1.field[x].IsNull and #tbl2.field[x].IsNull) or
(#tbl1.field[x].Value <> #tbl2.field[x].Value) then
insert into @.tblDiff values(#tbl1.field[x].Name, #tbl1.field[x].Value,
#tbl2.field[x].Value)
end
return select * from @.tblDiff
This is a pseudo code to show what i want to do. Now i need to solve this
in pure TSQL.
thanks,
Helmut|||You could try something like this, but it sounds like you're already at
this solution.
DECLARE @.Table varchar(50)
SET @.Table = 'sysobjects'
DECLARE @.IDvalue int
CREATE TABLE #Cols
(
TABLE_QUALIFIER sysname,
TABLE_OWNER sysname,
TABLE_NAME sysname,
COLUMN_NAME sysname,
DATA_TYPE smallint,
TYPE_NAME sysname,
[PRECISION] int,
LENGTH int,
SCALE smallint,
RADIX smallint,
NULLABLE smallint,
REMARKS varchar(254),
COLUMN_DEF nvarchar(4000),
SQL_DATA_TYPE smallint,
SQL_DATETIME_SUB smallint,
CHAR_OCTET_LENGTH int,
ORDINAL_POSITION int,
IS_NULLABLE varchar(254),
SS_DATA_TYPE tinyint
)
CREATE TABLE #Results(field sysname, OldValue nvarchar(4000), NewValue
nvarchar(4000))
INSERT INTO #Cols
exec sp_Columns @.Table
DECLARE Cols Cursor
FOR SELECT Colname
FROM #Cols
DECLARE @.Colname sysname
OPEN Cols
FETCH NEXT FROM cols INTO @.COlname
WHILE @.@.FETCH_STATUS = 0
BEGIN
DECLARE @.SQL nvarchar(4000)
SET @.SQL = 'INSERT INTO #Results SELECT ''' + @.Colname + ''', T1.' +
@.Colname + ', T2.' + @.ColName + ' FROM database1.dbo.' + @.tablename + '
as T1 INNER JOIN database2.dbo.' + @.TableName + ' as T2 on T1.IDField =
' + @.IDValue + ' AND T2.IDField = ' + @.IDValue + 'WHERE t1.' + @.Colname
+ ' != T2.' + @.Colname + ' AND NOT (T1.' + @.ColName + ' IS NULL AND
T2.' + @.ColName + ' IS NULL)'
exec sp_executesql @.SQL
FETCH NEXT FROM cols INTO @.COlname
END
CLOSE Cols
DEALLOCATE Cols
DROP TABLE #Cols
SELECT * FROM #REsults
DROP TABLE #Results|||Another soloution would be to use
BINARY_CHECKSUM()
HTH, Jens Suessmeyer.
http://www.sqlserver2005.de
--|||Am 6 Apr 2006 01:47:28 -0700 schrieb Jens:

> Another soloution would be to use
> BINARY_CHECKSUM()
>
> HTH, Jens Suessmeyer.
> --
> http://www.sqlserver2005.de
> --
Not really, at first, BOL says, that binary_checksum() can detect most, but
not all changes. And second, this can be used maybe in the calling function
to detect, if a difference is here. But my problem is the second step -
finding and documenting the changes.
bye, Helmut|||Hi Will,
thanks for this source. What i see at first, i need much more steps to find
the differences, so maybe you solution is faster (i hope).
But the main points are the same, information comes from sysobjects and for
every field i have to build a statement and do a sp_executesql.
But on the wend i take this source and make a benchmark and post the
result on monday.
Do you think, it would be much faster using an external stored proc?
thank you very much,
Helmut|||What are you trying to do Helmut? some kind of a retrospective audit
trail? have you considered putting triggers on your tables to maintain
this data as it changes?|||Am 6 Apr 2006 03:07:00 -0700 schrieb Will:

> What are you trying to do Helmut? some kind of a retrospective audit
> trail? have you considered putting triggers on your tables to maintain
> this data as it changes?
Yes, it should do both. For audit trail i use the data from inserted and
deleted. Working with columns_updated() is no solution, because i only
store changes and this means, if i have a record with 200 fields and only 5
fields are filled with data (and the rest is NULL), then i store only this
5 values. But when you do an insert, then columns_updated() has all bits
set.
bye, Helmut|||Helmut,
I'm afraid I think that your query is just about as fast as you'll get
it (I certainly can't think of any significant ways to improve it).
I've had one idea you could try, but I don't have time to fully
investigate it:
You could rather than performing the difference check on each column,
build up the SQL string as 'select inserted.'+colname+',
deleted.'+colname,+' CAST(CASE when insert.'+colname+' !=
deleted.'+colname+' then 1 else 0 end as bit) as ' + colname +
'ischanged' .
then build up this string for the whole set of columns, only do one
select into a temporary table, then do your inserts into your audit
table based on whether or not the bit field conameischanged has been
set to 1.
I have no idea if that will work, it has the advantage that you only
select from your 2 tables once as opposed to once per column, but it
has the divantage of needing an extra insert into a temporary table.
if you do write it then post the source and the benchmarks, I'd be
interested to know how it performs. If this isn't clear let me know,
I'll try and write some SQL this evening.
Cheers
Will

comparing two integers and returning a third

I am having difficulty trying to figure out how to compare two integers stored in a table to return a third. I have two integer fields in one table and two in another like this:

Table1.SomeNumber1 = 1

Table1.SomeNumber2 = 2

Table2.SomeNumber1 = 2

Table2.SomeNumber2 = 1

I need to be able to compare the first number from the first table to the first number in the second table. If the values are different I need to set a variable or field to 0. If the numbers are the same I need to set my variable or field to 1.

I need to follow the same procedure comparing the second number in the first table to the second number in the second table. In addition, I need to be able to do it in a single select statement.

Does anyone have any ideas on how this could be done? Thank you for any help you may be able to provide.

Gmz

CREATE TABLE [dbo].[num1](
[id] [int] NULL,
[number1] [int] NULL,
[number2] [int] NULL,
[flag1] [int] NULL,
[flag2] [int] NULL
)
CREATE TABLE [dbo].[num2](
[id] [int] NULL,
[number1] [int] NULL,
[number2] [int] NULL
)
--After the comparison, two flag fields in table num1 are updated
UPDATE num1
SET flag1=(SELECT (CASE WHEN a.number1 = b.number1 THEN 1 ELSE 0 END) FROM num1 a INNER JOIN
num2 b ON a.id = b.id and a.id=c.id), flag2=(SELECT (CASE WHEN a.number2 = b.number2 THEN 1 ELSE 0 END) FROM num1 a INNER JOIN
num2 b ON a.id = b.id and a.id=c.id)
FROM num1 c|||

I took what you posted and applied it to just return the values of the comparisons as results of my query which saved me from having to store the extra data in the table. It worked great.

Thank you!!!!

GMZ

sqlsql

comparing the results of two stored procedures.

I wanted to verify the output of two stored procedures I hoped I could
use EXCEPT. But that doesn't work.
I tried
execute usp_myProc @.param=1, @.param=2
except
execute usp_myProc1 @.param=1, @.param=2
so I could see if the results were different. Then I tried:
select * from ( usp_myProc @.param=1, @.param=2) as a
figuring I could then do an into #compareTable one and #compareTable2
and do an except on those. However it doesn't like that either. I
thought a derived table works on the assumption that a from clause
expects a table, so as long as you return it a table it will accept
that as a valid parameter. But this doesn't work. Any SQL genius out
there devised a way to compare the results of two stored procedures
easily?Create temporary tables that match the output format of the two stored
procedures, then populate those tables with the output:
INSERT INTO #output (EXEC usp_myProc @.param1 = 1, @.param2 = 2)
INSERT INTO #output1 (EXEC usp_myProc1 @.param1 = 1, @.param2 = 2)
Now you can compare the ouputs of the procedures to get the difference:
SELECT t1.col1, t1.col2 --more columns
FROM #output t1
WHERE NOT EXISTS
(
SELECT 1 FROM #output1 t2
WHERE t1.col1 = t2.col1 AND t1.col2 = t2.col2 --and so on for more columns
)
"bryanmurtha@.yahoo.com" wrote:

> I wanted to verify the output of two stored procedures I hoped I could
> use EXCEPT. But that doesn't work.
> I tried
> execute usp_myProc @.param=1, @.param=2
> except
> execute usp_myProc1 @.param=1, @.param=2
> so I could see if the results were different. Then I tried:
> select * from ( usp_myProc @.param=1, @.param=2) as a
> figuring I could then do an into #compareTable one and #compareTable2
> and do an except on those. However it doesn't like that either. I
> thought a derived table works on the assumption that a from clause
> expects a table, so as long as you return it a table it will accept
> that as a valid parameter. But this doesn't work. Any SQL genius out
> there devised a way to compare the results of two stored procedures
> easily?
>|||You can insert into a table from a stored procedure with the same column
layout. Once done, you can query the 2 tables for differences.
create table #myProcA (x int, a int, b int, c int)
insert #myProcA exec spProcA
create table #myProcB (x int, a int, b int, c int)
insert #myProcB exec spProcB
select
*
from
#myProcA as A
left join #myProcB as B
on B.x = A.x
where
A.a <> B.a or
A.b <> B.b or
A.c <> B.c
<bryanmurtha@.yahoo.com> wrote in message
news:1140545979.907341.185830@.o13g2000cwo.googlegroups.com...
>I wanted to verify the output of two stored procedures I hoped I could
> use EXCEPT. But that doesn't work.
> I tried
> execute usp_myProc @.param=1, @.param=2
> except
> execute usp_myProc1 @.param=1, @.param=2
> so I could see if the results were different. Then I tried:
> select * from ( usp_myProc @.param=1, @.param=2) as a
> figuring I could then do an into #compareTable one and #compareTable2
> and do an except on those. However it doesn't like that either. I
> thought a derived table works on the assumption that a from clause
> expects a table, so as long as you return it a table it will accept
> that as a valid parameter. But this doesn't work. Any SQL genius out
> there devised a way to compare the results of two stored procedures
> easily?
>|||Thanks both, I have 37 stored procs which I had to upgrade from SQL-89
syntax to SQL-92 and write test cases to verify the output is the same.
I knew you could do it if you defined the temp tables but I don't think
there is any way around that. I tried OpenRowset and all that put the
queries can't have parameters. I didn't want to have to define 37
tables x 2 but I don't think there is anyway around that. But I
appreciate the two of you taking the time to respond.
Regards,
Bryan

Tuesday, March 27, 2012

Comparing stored procedures

Hi!
I've got 2 databases: working one and test one.
I've changed a lot of procedures in test database.
How can I compare all procedures in that databases and select only changed
ones?
Thanks !I recommend that you implement a change control system, where you know which has changed and apply
only those. To do an actual compare, you need to write code or go to 3:rd party product. I haven't
used below myself, but I see it mentioned a lot:
http://www.red-gate.com/SQL_Compare.htm
--
Tibor Karaszi, SQL Server MVP
Archive at: http://groups.google.com/groups?oi=djq&as_ugroup=microsoft.public.sqlserver
"Dmitry Karneyev" <karneyev@.msn.com> wrote in message news:%23f9gVqrnDHA.708@.TK2MSFTNGP10.phx.gbl...
> Hi!
> I've got 2 databases: working one and test one.
> I've changed a lot of procedures in test database.
> How can I compare all procedures in that databases and select only changed
> ones?
> Thanks !
>|||For quick & dirty compare, use free tool QALite from site.
--
-oj
RAC v2.2 & QALite!
http://www.rac4sql.net
"Dmitry Karneyev" <karneyev@.msn.com> wrote in message
news:%23f9gVqrnDHA.708@.TK2MSFTNGP10.phx.gbl...
> Hi!
> I've got 2 databases: working one and test one.
> I've changed a lot of procedures in test database.
> How can I compare all procedures in that databases and select only changed
> ones?
> Thanks !
>|||Hi, Dmitry
I always add some comment in my stored procedures like
--It has been changed by Uri Dimant on some date.
Write script which loop through all strored procedures and looking for some
comments.
"Dmitry Karneyev" <karneyev@.msn.com> wrote in message
news:#f9gVqrnDHA.708@.TK2MSFTNGP10.phx.gbl...
> Hi!
> I've got 2 databases: working one and test one.
> I've changed a lot of procedures in test database.
> How can I compare all procedures in that databases and select only changed
> ones?
> Thanks !
>|||Hi Uri!
Could you post such script?
"Uri Dimant" <urid@.iscar.co.il> ÓÏÏÂÝÉÌ/ÓÏÏÂÝÉÌÁ × ÎÏ×ÏÓÔÑÈ ÓÌÅÄÕÀÝÅÅ:
news:e02Zt6rnDHA.2776@.tk2msftngp13.phx.gbl...
> Hi, Dmitry
> I always add some comment in my stored procedures like
> --It has been changed by Uri Dimant on some date.
> Write script which loop through all strored procedures and looking for
some
> comments.|||Hi
Simple
SELECT SPECIFIC_NAME
FROM INFORMATION_SCHEMA.routines
WHERE ROUTINE_DEFINITION LIKE '%It has been changed%'
"Dmitry Karneyev" <karneyev@.msn.com> wrote in message
news:eXTqz9rnDHA.2776@.tk2msftngp13.phx.gbl...
> Hi Uri!
> Could you post such script?
> "Uri Dimant" <urid@.iscar.co.il> ÓÏÏÂÝÉÌ/ÓÏÏÂÝÉÌÁ × ÎÏ×ÏÓÔÑÈ ÓÌÅÄÕÀÝÅÅ:
> news:e02Zt6rnDHA.2776@.tk2msftngp13.phx.gbl...
> > Hi, Dmitry
> > I always add some comment in my stored procedures like
> > --It has been changed by Uri Dimant on some date.
> > Write script which loop through all strored procedures and looking for
> some
> > comments.
>|||You must to use the MS Visual Source Safe in a future to make a
version-control on of your procedures.
Hope this help,
"Dmitry Karneyev" <karneyev@.msn.com> escreveu na mensagem
news:%23f9gVqrnDHA.708@.TK2MSFTNGP10.phx.gbl...
> Hi!
> I've got 2 databases: working one and test one.
> I've changed a lot of procedures in test database.
> How can I compare all procedures in that databases and select only changed
> ones?
> Thanks !
>|||That may not be robust! What if you forgot to put in a comment in one of the
stored procedures?
--
Linchi Shea
linchi_shea@.NOSPAMml.com
"Uri Dimant" <urid@.iscar.co.il> wrote in message
news:uxw0lCsnDHA.3304@.tk2msftngp13.phx.gbl...
> Hi
> Simple
> SELECT SPECIFIC_NAME
> FROM INFORMATION_SCHEMA.routines
> WHERE ROUTINE_DEFINITION LIKE '%It has been changed%'
>
> "Dmitry Karneyev" <karneyev@.msn.com> wrote in message
> news:eXTqz9rnDHA.2776@.tk2msftngp13.phx.gbl...
> > Hi Uri!
> >
> > Could you post such script?
> >
> > "Uri Dimant" <urid@.iscar.co.il> ÓÏÏÂÝÉÌ/ÓÏÏÂÝÉÌÁ × ÎÏ×ÏÓÔÑÈ ÓÌÅÄÕÀÝÅÅ:
> > news:e02Zt6rnDHA.2776@.tk2msftngp13.phx.gbl...
> > > Hi, Dmitry
> > > I always add some comment in my stored procedures like
> > > --It has been changed by Uri Dimant on some date.
> > > Write script which loop through all strored procedures and looking
for
> > some
> > > comments.
> >
> >
>|||Linchi
Heee, good point.
That will be DBA's privilege and only one person should to do such things
like me in our company.
"Linchi Shea" <linchi_shea@.NOSPAMml.com> wrote in message
news:#S6zLGunDHA.744@.tk2msftngp13.phx.gbl...
> That may not be robust! What if you forgot to put in a comment in one of
the
> stored procedures?
> --
> Linchi Shea
> linchi_shea@.NOSPAMml.com
>
> "Uri Dimant" <urid@.iscar.co.il> wrote in message
> news:uxw0lCsnDHA.3304@.tk2msftngp13.phx.gbl...
> > Hi
> > Simple
> > SELECT SPECIFIC_NAME
> > FROM INFORMATION_SCHEMA.routines
> > WHERE ROUTINE_DEFINITION LIKE '%It has been changed%'
> >
> >
> > "Dmitry Karneyev" <karneyev@.msn.com> wrote in message
> > news:eXTqz9rnDHA.2776@.tk2msftngp13.phx.gbl...
> > > Hi Uri!
> > >
> > > Could you post such script?
> > >
> > > "Uri Dimant" <urid@.iscar.co.il> ÓÏÏÂÝÉÌ/ÓÏÏÂÝÉÌÁ × ÎÏ×ÏÓÔÑÈ ÓÌÅÄÕÀÝÅÅ:
> > > news:e02Zt6rnDHA.2776@.tk2msftngp13.phx.gbl...
> > > > Hi, Dmitry
> > > > I always add some comment in my stored procedures like
> > > > --It has been changed by Uri Dimant on some date.
> > > > Write script which loop through all strored procedures and looking
> for
> > > some
> > > > comments.
> > >
> > >
> >
> >
>|||Thanks Linchi!
"Linchi Shea" <linchi_shea@.NOSPAMml.com> ÓÏÏÂÝÉÌ/ÓÏÏÂÝÉÌÁ × ÎÏ×ÏÓÔÑÈ
ÓÌÅÄÕÀÝÅÅ: news:O2DNNRunDHA.2000@.TK2MSFTNGP12.phx.gbl...
> Here's a Perl script for comparing two stored procedures. You can use it
> compare any number of stored procedures. The first time it runs, it takes
> time to load SQL-DMO. An HTML doc is included in the zip file.
> --
> Linchi Shea
> linchi_shea@.NOSPAMml.com
>
> "Dmitry Karneyev" <karneyev@.msn.com> wrote in message
> news:%23f9gVqrnDHA.708@.TK2MSFTNGP10.phx.gbl...
> > Hi!
> >
> > I've got 2 databases: working one and test one.
> > I've changed a lot of procedures in test database.
> >
> > How can I compare all procedures in that databases and select only
changed
> > ones?
> >
> > Thanks !
> >
> >
>
>|||Hi Linchi,
How to get the perl script you mentioned? I am having the
same problem and want to use your script to give a try.
Thanks in advance,
New Bee
>--Original Message--
>Here's a Perl script for comparing two stored procedures.
You can use it
>compare any number of stored procedures. The first time
it runs, it takes
>time to load SQL-DMO. An HTML doc is included in the zip
file.
>--
>Linchi Shea
>linchi_shea@.NOSPAMml.com
>
>"Dmitry Karneyev" <karneyev@.msn.com> wrote in message
>news:%23f9gVqrnDHA.708@.TK2MSFTNGP10.phx.gbl...
>> Hi!
>> I've got 2 databases: working one and test one.
>> I've changed a lot of procedures in test database.
>> How can I compare all procedures in that databases and
select only changed
>> ones?
>> Thanks !
>>
>
>|||Please check DB Ghost at www.dbghost.com
Thanks,
Darren Fuller MCSE
>--Original Message--
>Hi!
>I've got 2 databases: working one and test one.
>I've changed a lot of procedures in test database.
>How can I compare all procedures in that databases and
select only changed
>ones?
>Thanks !
>
>.
>|||also routine_definition is not a reliable way to check for code.
e.g.
declare @.s1 varchar(8000),@.s2 varchar(8000),@.s3 varchar(8000)
select @.s1='create proc _usp as select ''',
@.s2=replicate('1',8000),
@.s3=replicate('2',8000)
exec(@.s1+@.s2+@.s3+'abc'' as mycol')
go
SELECT *
FROM INFORMATION_SCHEMA.routines
WHERE ROUTINE_DEFINITION LIKE '%abc'
select text
from syscomments
where id=object_id('_usp')
go
drop proc _usp
go
-oj
RAC v2.2 & QALite!
http://www.rac4sql.net
"Uri Dimant" <urid@.iscar.co.il> wrote in message
news:uxw0lCsnDHA.3304@.tk2msftngp13.phx.gbl...
> Hi
> Simple
> SELECT SPECIFIC_NAME
> FROM INFORMATION_SCHEMA.routines
> WHERE ROUTINE_DEFINITION LIKE '%It has been changed%'
>
> "Dmitry Karneyev" <karneyev@.msn.com> wrote in message
> news:eXTqz9rnDHA.2776@.tk2msftngp13.phx.gbl...
> > Hi Uri!
> >
> > Could you post such script?
> >
> > "Uri Dimant" <urid@.iscar.co.il> ÓÏÏÂÝÉÌ/ÓÏÏÂÝÉÌÁ × ÎÏ×ÏÓÔÑÈ ÓÌÅÄÕÀÝÅÅ:
> > news:e02Zt6rnDHA.2776@.tk2msftngp13.phx.gbl...
> > > Hi, Dmitry
> > > I always add some comment in my stored procedures like
> > > --It has been changed by Uri Dimant on some date.
> > > Write script which loop through all strored procedures and looking
for
> > some
> > > comments.
> >
> >
>|||NB;
I attached to my previous post. Are you not able to get the attached file? I can email you offline.
Also, the script requires the Perl module Parse::RecDescent which you can get from www.cpan.org. I use this module to parse T-SQL code to stripe off whitespaces and comments in case you don't want to compare them. You can choose to include them in the comparison if you want.
Linchi
>--Original Message--
>Thanks Linchi!
>"Linchi Shea" <linchi_shea@.NOSPAMml.com> ==D3=CF=CF=C2=DD=C9=CC/=D3=CF=CF=C2=DD=C9=CC=C1 =D7 =CE=CF=D7=CF=D3=D4=D1=C8
>=D3=CC=C5=C4=D5=C0=DD=C5=C5: =news:O2DNNRunDHA.2000@.TK2MSFTNGP12.phx.gbl...
>> Here's a Perl script for comparing two stored procedures. You can use it
>> compare any number of stored procedures. The first time it runs, it takes
>> time to load SQL-DMO. An HTML doc is included in the zip file.
>> -- >> Linchi Shea
>> linchi_shea@.NOSPAMml.com
>>
>> "Dmitry Karneyev" <karneyev@.msn.com> wrote in message
>> news:%23f9gVqrnDHA.708@.TK2MSFTNGP10.phx.gbl...
>> > Hi!
>> >
>> > I've got 2 databases: working one and test one.
>> > I've changed a lot of procedures in test database.
>> >
>> > How can I compare all procedures in that databases and select only
>changed
>> > ones?
>> >
>> > Thanks !
>> >
>> >
>>
>
>.
>|||Even in a single DBA shop, it can end up biting you for DBAs can be
forgetful :-) In a multi-DBA shop, it's not going to work at all.
--
Linchi Shea
linchi_shea@.NOSPAMml.com
"Uri Dimant" <urid@.iscar.co.il> wrote in message
news:OQHYBLunDHA.688@.TK2MSFTNGP10.phx.gbl...
> Linchi
> Heee, good point.
> That will be DBA's privilege and only one person should to do such
things
> like me in our company.
>
> "Linchi Shea" <linchi_shea@.NOSPAMml.com> wrote in message
> news:#S6zLGunDHA.744@.tk2msftngp13.phx.gbl...
> > That may not be robust! What if you forgot to put in a comment in one of
> the
> > stored procedures?
> >
> > --
> > Linchi Shea
> > linchi_shea@.NOSPAMml.com
> >
> >
> > "Uri Dimant" <urid@.iscar.co.il> wrote in message
> > news:uxw0lCsnDHA.3304@.tk2msftngp13.phx.gbl...
> > > Hi
> > > Simple
> > > SELECT SPECIFIC_NAME
> > > FROM INFORMATION_SCHEMA.routines
> > > WHERE ROUTINE_DEFINITION LIKE '%It has been changed%'
> > >
> > >
> > > "Dmitry Karneyev" <karneyev@.msn.com> wrote in message
> > > news:eXTqz9rnDHA.2776@.tk2msftngp13.phx.gbl...
> > > > Hi Uri!
> > > >
> > > > Could you post such script?
> > > >
> > > > "Uri Dimant" <urid@.iscar.co.il> ÓÏÏÂÝÉÌ/ÓÏÏÂÝÉÌÁ × ÎÏ×ÏÓÔÑÈ
ÓÌÅÄÕÀÝÅÅ:
> > > > news:e02Zt6rnDHA.2776@.tk2msftngp13.phx.gbl...
> > > > > Hi, Dmitry
> > > > > I always add some comment in my stored procedures like
> > > > > --It has been changed by Uri Dimant on some date.
> > > > > Write script which loop through all strored procedures and
looking
> > for
> > > > some
> > > > > comments.
> > > >
> > > >
> > >
> > >
> >
> >
>|||NB;
Drop me an email!
--
Linchi Shea
linchi_shea@.NOSPAMml.com
"NB" <anonymous@.discussions.microsoft.com> wrote in message
news:0a6601c39eef$06556d20$a501280a@.phx.gbl...
> Hi Linchi,
> How to get the perl script you mentioned? I am having the
> same problem and want to use your script to give a try.
> Thanks in advance,
> New Bee
> >--Original Message--
> >Here's a Perl script for comparing two stored procedures.
> You can use it
> >compare any number of stored procedures. The first time
> it runs, it takes
> >time to load SQL-DMO. An HTML doc is included in the zip
> file.
> >
> >--
> >Linchi Shea
> >linchi_shea@.NOSPAMml.com
> >
> >
> >"Dmitry Karneyev" <karneyev@.msn.com> wrote in message
> >news:%23f9gVqrnDHA.708@.TK2MSFTNGP10.phx.gbl...
> >> Hi!
> >>
> >> I've got 2 databases: working one and test one.
> >> I've changed a lot of procedures in test database.
> >>
> >> How can I compare all procedures in that databases and
> select only changed
> >> ones?
> >>
> >> Thanks !
> >>
> >>
> >
> >
> >

Comparing Records

Is there a Stored Procedure that compares 2 records and give you the
diffrences between them? Or do I have to manually compare each record?You will have to write one depending on what you want to compare and how you
want to retrieve the differences. For direct data comparison there are
certain 3rd party tools from companies like RedGate which you can buy off
the shelf.
Anith|||I wanted to do this from a trigger. ie see what changes there are from
the old record to the new record.|||You'd have to use the inserted and deleted tables within the trigger to do
this. Check out the topic CREATE TRIGGER in SQL Server Books Online; there
are certain examples which details how you can use them.
If you still have difficulty in coming up with a required solution, pl.
refer to www.aspfaq.com/5006 and post required information for others to
repro your problem.
Anith|||Thanks, I know how to do triggers. But you answered my question so
thanks.

Sunday, March 25, 2012

Comparing Keys

Hi! I Have a Table with composed Primary Key and need to validate in a
stored procedure that new rows from a temporary table that would be inserted does not exist already.
I use to have a code similar to this for many tables, even with composed keys

Delete Det_Order

Where Ltrim(Rtrim(Convert(Char(20),id))) +
Ltrim(Rtrim(Convert(Char(20),renglon)))

In (Select Ltrim(Rtrim(Convert(Char(20),id))) +
Ltrim(Rtrim(Convert(Char(20),renglon)))
From ##TmpDet_Order )


But I just dont now what happen with this case that the process just hold and never ends. Both fields that I have in as keys are integer. Would you have any idea of what happens? or maybe you can tell me another way to make the same. Please ...

I have also tried this..
Delete from Det_Order
Where [id] + renglon

In (Select [id] + renglon
From ##Det_Order )

Rather than use the IN condition, try the TSQL DELETE extension; something like:

Delete Det_Order
from ##TmpDet_Order a
join Det_Order b
on a.[id] = b.[id]
and a.renglon = b.renglon

In general, I try to use the TSQL extensions sparingly, but this seems like a good spot for use.

|||I have also tried Kent, but have the same problem |||

Try running this query and let us know record count returned; have you tried limiting the number of rows being deleted in a single batch?

select count(*)
from ##TmpDet_Order (nolock) a
join Det_Order (nolock) b
on a.[id] = b.[id]
and a.renglon = b.renglon

|||

ok, my rowcount is 4677

The purpose of this process is to run every day and getting data from a day before.

|||

Well, that isn't nominally enough to grieve anything. My knee-jerk reaction is to run profiler to see what is going on; you also might be able to get at this by running SP_LOCK while your delete query is hung because it sounds like you might be blocked. If you will perform a search on this site you will find posts that discuss diagnosis of performance problems.

More importantly, I'd like to recruit opinions from others that are more experienced.

Kent

|||I could be a resource contention issue. I would also check the indexing on the key.|||

How long does it take for a similar SELECT query to execute?

select

b.*

from ##TmpDet_Order a
join Det_Order b
on a.[id] = b.[id]
and a.renglon = b.renglon

I have occasionally encountered problems with DELETE statements that are deleting from large tables.

How many rows are in Det_Order?

How many indexes are associated with Det_Order?

Are any of the indexes on Det_Order CLUSTERED indexes? Maintaining clustered indexes has a performance penalty -- but I would not have expected it to be substantial when deleting only 4700 rows.

|||

Ok, I have a clusterd index on the field last_date_change and have anotherone with id + renglon.

Could it afect the order?

|||

If your table is large, my understanding is that considerable effort must be expended to adjust the data to conform to the clustered index. Such maintenance is required merely as a result of deleting records -- it does not depend on the columns you used to determine which records to delete.

But you cannot have TWO clustered indexes on a single table.

You never told us how large your table is (rows, as well as megabytes), only that you were deleting 4700 rows, or so.

Dan

|||Oh yes, my table has 5,917,688 rows.. and it has a cluster index by the field of date.|||

That sounds like a lot of data to move about, to maintain the clustered index.

In any case, I would like to suggest that you make a copy of your table and change the CLUSTERED index to a NON-CLUSTERED index. Test your query against this copy of the table. (Unfortunately this change will increase the size of your indexes (by approx. 50 MB, if a DATETIME column is the only column of the CLUSTERED index), but I am expecting that it will improve the performance of any INSERT, UPDATE, and DELETE actions you perform on this table.)

If you frequently perform millions of INSERT, UPDATE, and DELETE actions on this table, you may want to consider using FILLFACTOR = 50, or maybe 80, depending on the quantity of such actions. (For some of my processing, where I have only 100,000 rows in a table when I create the index, but at later stages of processing I add another 200,000 rows that will be intermingled with these others, I set the FILLFACTOR = 30 to leave room in the index for the new rows. Some of my INSERT actions that formerly took 7-10 minutes then took only a few seconds.)

|||Thanks everyobody : )

Thursday, March 22, 2012

Comparing Date to SQL Server Date

Hey everyone...I need to create a job which occurs once monthly that is based on a stored procedure that contains as a rough example:

CREATE PROCEDURE CompareDate
@.CurrentDate datetime

AS

SELECT * FROM Contracts WHERE EndDate LIKE (CURRENT SERVER DATE)
GO

How do I declare a parameter to automatically get the current server date in the stored procedure? Also, once it is declared how can I add Months to it? For example this job is executed monthly and is supposed to select contracts that expire 2 months from the current month. So once I get the current server date, how do I add 2 months to the date in the stored procedure? Thanks very much in advance!!!Use getdate() function to get the current server date.

Monday, March 19, 2012

Compare two queries to see if their results are identical

Scenario - I would like to compare two queries to find out if their results
are identical. The first query returns all the values stored in an invoice
table for a given invoice no. The second query returns all the values
stored in a table holding booking information.
E.g.
SELECT Quantity, [Description], UnitPrice, TaxPercentage, Tax, Price FROM
InvoiceDetails WHERE InvoiceNo = 12345
SELECT Quantity, [Description], UnitPrice, TaxPercentage, Tax, Price FROM
BookingDetails WHERE BookingNo = 20
I need to know whether the results from the two queries are identical. One
way I can think of doing this is to perform two EXISTS queries, the first
one finding a row that does not exist in InvoiceDetails that does exist in
BookingDetails and a second query that finds a row that does not exist in
BookingDetails that does in InvoiceDetails. Then if one or the other tests
finds a row the answer is they are different otherwise they are the same.
But is there a better way to perform this test - can be be done is one test?
Thanks.One way is to do a full join and then look for NULLs on either side.
Another method is to UNION the two queries and in the result GROUP BY
<all columns> HAVING COUNT(*)=1 to show any mismatches. This second
method has the advantage that you can compare on the basis of NULL=NULL
if you wish.
David Portas
SQL Server MVP
--|||The first way is to create a cursor with your first query and within to
compare it with your second result, as you specify it with IF EXISTS.
You should also do the opposite operation with the second resultset.
But you should consider that cursor are not efiiciency for large table. So
you could also create tempory table from you resulstet and compare them
trough join operation,
Laurent
"Chris" <cw@.community.nospam> a crit dans le message de news:
eli7vkbyFHA.3720@.TK2MSFTNGP14.phx.gbl...
> Scenario - I would like to compare two queries to find out if their
> results are identical. The first query returns all the values stored in
> an invoice table for a given invoice no. The second query returns all the
> values stored in a table holding booking information.
> E.g.
> SELECT Quantity, [Description], UnitPrice, TaxPercentage, Tax, Price FROM
> InvoiceDetails WHERE InvoiceNo = 12345
> SELECT Quantity, [Description], UnitPrice, TaxPercentage, Tax, Price FROM
> BookingDetails WHERE BookingNo = 20
> I need to know whether the results from the two queries are identical.
> One way I can think of doing this is to perform two EXISTS queries, the
> first one finding a row that does not exist in InvoiceDetails that does
> exist in BookingDetails and a second query that finds a row that does not
> exist in BookingDetails that does in InvoiceDetails. Then if one or the
> other tests finds a row the answer is they are different otherwise they
> are the same.
> But is there a better way to perform this test - can be be done is one
> test?
> Thanks.
>|||Try:
if exists (
select *
from InvoiceDetails as a inner join BookingDetails as b
on a.InvoiceNo = 12345 and b.BookingNo = 20
and a.Quantity = b.Quantity
and a.[Description] = b.[Description]
and a.UnitPrice = b.UnitPrice
and a.TaxPercentage = b.TaxPercentage
and a.Tax = b.Tax
and a.Price = b.Price
)
print 'identical'
else
print 'not identical'
go
AMB
"Chris" wrote:

> Scenario - I would like to compare two queries to find out if their result
s
> are identical. The first query returns all the values stored in an invoic
e
> table for a given invoice no. The second query returns all the values
> stored in a table holding booking information.
> E.g.
> SELECT Quantity, [Description], UnitPrice, TaxPercentage, Tax, Price FROM
> InvoiceDetails WHERE InvoiceNo = 12345
> SELECT Quantity, [Description], UnitPrice, TaxPercentage, Tax, Price FROM
> BookingDetails WHERE BookingNo = 20
> I need to know whether the results from the two queries are identical. On
e
> way I can think of doing this is to perform two EXISTS queries, the first
> one finding a row that does not exist in InvoiceDetails that does exist in
> BookingDetails and a second query that finds a row that does not exist in
> BookingDetails that does in InvoiceDetails. Then if one or the other test
s
> finds a row the answer is they are different otherwise they are the same.
> But is there a better way to perform this test - can be be done is one tes
t?
> Thanks.
>
>|||Can't you do a FULL OUTER JOIN and see if either side is NULL?
"Chris" <cw@.community.nospam> wrote in message
news:eli7vkbyFHA.3720@.TK2MSFTNGP14.phx.gbl...
> Scenario - I would like to compare two queries to find out if their
> results are identical. The first query returns all the values stored in
> an invoice table for a given invoice no. The second query returns all the
> values stored in a table holding booking information.
> E.g.
> SELECT Quantity, [Description], UnitPrice, TaxPercentage, Tax, Price FROM
> InvoiceDetails WHERE InvoiceNo = 12345
> SELECT Quantity, [Description], UnitPrice, TaxPercentage, Tax, Price FROM
> BookingDetails WHERE BookingNo = 20
> I need to know whether the results from the two queries are identical.
> One way I can think of doing this is to perform two EXISTS queries, the
> first one finding a row that does not exist in InvoiceDetails that does
> exist in BookingDetails and a second query that finds a row that does not
> exist in BookingDetails that does in InvoiceDetails. Then if one or the
> other tests finds a row the answer is they are different otherwise they
> are the same.
> But is there a better way to perform this test - can be be done is one
> test?
> Thanks.
>|||CREATE TABLE #T1(i int, j int)
CREATE TABLE #T2(i int, j int)
insert into #t1 values(1,2)
insert into #t2 values(1,2)
select count(*) from(
select * from #t1
union
select * from #t2
) t
-- identical
--
1
update #t2 set j=3
select count(*) from(
select * from #t1
union
select * from #t2
) t
-- different
--
2
drop table #t1
drop table #t2|||USE LRUKUVL
IF OBJECT_ID('tempdb..#Table1') IS NOT NULL DROP TABLE #Table1
IF OBJECT_ID('tempdb..#Table2') IS NOT NULL DROP TABLE #Table2
CREATE TABLE
#Table1
(
ID INT PRIMARY KEY CLUSTERED
, Data1 TINYINT NULL
, Data2 CHAR(1) NULL
)
CREATE TABLE
#Table2
(
ID INT PRIMARY KEY CLUSTERED
, Data1 TINYINT NULL
, Data2 CHAR(1) NULL
)
INSERT INTO #Table1
SELECT 1 , 4 , 'A'
UNION ALL SELECT 2 , 3 , 'B'
UNION ALL SELECT 3 , NULL , 'C'
UNION ALL SELECT 4 , 1 , 'D'
UNION ALL SELECT 5 , 1 , 'D'
UNION ALL SELECT 7 , 5 , NULL
INSERT INTO #Table2
SELECT 2 , 3 , 'B'
UNION ALL SELECT 3 , 2 , 'C'
UNION ALL SELECT 4 , 1 , NULL
UNION ALL SELECT 5 , 1 , 'E'
UNION ALL SELECT 6 , 1 , 'F'
UNION ALL SELECT 7 , 5 , NULL
/* return records that are different */
/* only id=2 and id=7 are equal - others are returned */
/* write a UDF to compaire a.data = b.data checking for equality, and is
nulls differences */
SELECT
*
FROM
#Table1 a
FULL OUTER JOIN
#Table2 b
ON
a.id = b.id
WHERE
a.id IS NULL
OR
b.id IS NULL
OR
( a.data1 IS NULL AND b.data1 IS NOT NULL )
OR
( a.data1 IS NOT NULL AND b.data1 IS NULL )
OR
( a.data1 != b.data1 )
OR
( a.data2 IS NULL AND b.data2 IS NOT NULL )
OR
( a.data2 IS NOT NULL AND b.data2 IS NULL )
OR
( a.data2 != b.data2 )
"Chris" <cw@.community.nospam> wrote in message
news:eli7vkbyFHA.3720@.TK2MSFTNGP14.phx.gbl...
> Scenario - I would like to compare two queries to find out if their
results
> are identical. The first query returns all the values stored in an
invoice
> table for a given invoice no. The second query returns all the values
> stored in a table holding booking information.
> E.g.
> SELECT Quantity, [Description], UnitPrice, TaxPercentage, Tax, Price FROM
> InvoiceDetails WHERE InvoiceNo = 12345
> SELECT Quantity, [Description], UnitPrice, TaxPercentage, Tax, Price FROM
> BookingDetails WHERE BookingNo = 20
> I need to know whether the results from the two queries are identical.
One
> way I can think of doing this is to perform two EXISTS queries, the first
> one finding a row that does not exist in InvoiceDetails that does exist in
> BookingDetails and a second query that finds a row that does not exist in
> BookingDetails that does in InvoiceDetails. Then if one or the other
tests
> finds a row the answer is they are different otherwise they are the same.|||Thanks to everyone for the replies
Chris
"Chris" <cw@.community.nospam> wrote in message
news:eli7vkbyFHA.3720@.TK2MSFTNGP14.phx.gbl...
> Scenario - I would like to compare two queries to find out if their
> results are identical. The first query returns all the values stored in
> an invoice table for a given invoice no. The second query returns all the
> values stored in a table holding booking information.
> E.g.
> SELECT Quantity, [Description], UnitPrice, TaxPercentage, Tax, Price FROM
> InvoiceDetails WHERE InvoiceNo = 12345
> SELECT Quantity, [Description], UnitPrice, TaxPercentage, Tax, Price FROM
> BookingDetails WHERE BookingNo = 20
> I need to know whether the results from the two queries are identical.
> One way I can think of doing this is to perform two EXISTS queries, the
> first one finding a row that does not exist in InvoiceDetails that does
> exist in BookingDetails and a second query that finds a row that does not
> exist in BookingDetails that does in InvoiceDetails. Then if one or the
> other tests finds a row the answer is they are different otherwise they
> are the same.
> But is there a better way to perform this test - can be be done is one
> test?
> Thanks.
>

Compare timestamps then delete

What I am trying to do is create a stored procedure that compares a the current datetime to a datetime field already added to a table. I also want it to compare the two and if the old data that is collected in the table is over 6 months old I want it deleted.

Someone please help

Quote:

Originally Posted by JReneau35

What I am trying to do is create a stored procedure that compares a the current datetime to a datetime field already added to a table. I also want it to compare the two and if the old data that is collected in the table is over 6 months old I want it deleted.

Someone please help


delete ... where datediff(mm,datefield,getdate()) > 6|||

Quote:

Originally Posted by ck9663

delete ... where datediff(mm,datefield,getdate()) > 6


Will this function automatically change with each month. So I don't have to plug in the month everytime it changes.|||

Quote:

Originally Posted by JReneau35

Will this function automatically change with each month. So I don't have to plug in the month everytime it changes.


datediff() gets the difference between the start data and end date. the "mm" signifies you're trying to get the difference expressed in number of months. getdate() is a function that returns the system date.

essentially, you're deleting the record if the difference between the datefield (content of your field) and the system date is more then 6 months ... if you need to include 6 months and older, do a "=>" instead

Compare Stored Procedures

Is there a way to compare Stored procedure definitions
in different databases?
Eg. I have database A with Stored procedure Sp1
and database B with Stored procedure Sp1
how can I compare the definitions of Sp1 in two databases?
Thank you in advance-
-Asok
Check out SQL Compare by Red-Gate at www.red-gate.com
----
Need SQL Server Examples check out my website at
http://www.geocities.com/sqlserverexamples
"Asok" <anonymous@.discussions.microsoft.com> wrote in message
news:fca701c43e95$7d34d480$a101280a@.phx.gbl...
> Is there a way to compare Stored procedure definitions
> in different databases?
> Eg. I have database A with Stored procedure Sp1
> and database B with Stored procedure Sp1
> how can I compare the definitions of Sp1 in two databases?
> Thank you in advance-
> -Asok
|||Several tools listed here:
http://www.aspfaq.com/2209
In addition, you could script your stored procedures to a file and use
WinDiff (which ships with Visual Studio).
Aaron Bertrand
SQL Server MVP
http://www.aspfaq.com/
"Asok" <anonymous@.discussions.microsoft.com> wrote in message
news:fca701c43e95$7d34d480$a101280a@.phx.gbl...
> Is there a way to compare Stored procedure definitions
> in different databases?
> Eg. I have database A with Stored procedure Sp1
> and database B with Stored procedure Sp1
> how can I compare the definitions of Sp1 in two databases?
> Thank you in advance-
> -Asok
|||Hi,
Try dbMaestro. It's a product that allows comparison, migration and archiving of database schema and data.
You can find it here:
http://www.extreme.co.il

Compare Stored Procedures

Is there a way to compare Stored procedure definitions
in different databases?
Eg. I have database A with Stored procedure Sp1
and database B with Stored procedure Sp1
how can I compare the definitions of Sp1 in two databases?
Thank you in advance-
-Asokcheck out www.dbghost.com
>--Original Message--
>Is there a way to compare Stored procedure definitions
>in different databases?
>Eg. I have database A with Stored procedure Sp1
>and database B with Stored procedure Sp1
>how can I compare the definitions of Sp1 in two
databases?
>Thank you in advance-
>-Asok
>.
>|||Check out SQL Compare by Red-Gate at www.red-gate.com
--
----
----
--
Need SQL Server Examples check out my website at
http://www.geocities.com/sqlserverexamples
"Asok" <anonymous@.discussions.microsoft.com> wrote in message
news:fca701c43e95$7d34d480$a101280a@.phx.gbl...
> Is there a way to compare Stored procedure definitions
> in different databases?
> Eg. I have database A with Stored procedure Sp1
> and database B with Stored procedure Sp1
> how can I compare the definitions of Sp1 in two databases?
> Thank you in advance-
> -Asok|||Several tools listed here:
http://www.aspfaq.com/2209
In addition, you could script your stored procedures to a file and use
WinDiff (which ships with Visual Studio).
--
Aaron Bertrand
SQL Server MVP
http://www.aspfaq.com/
"Asok" <anonymous@.discussions.microsoft.com> wrote in message
news:fca701c43e95$7d34d480$a101280a@.phx.gbl...
> Is there a way to compare Stored procedure definitions
> in different databases?
> Eg. I have database A with Stored procedure Sp1
> and database B with Stored procedure Sp1
> how can I compare the definitions of Sp1 in two databases?
> Thank you in advance-
> -Asok|||Hi
Try dbMaestro. It's a product that allows comparison, migration and archiving of database schema and data
You can find it here
http://www.extreme.co.i

Compare Stored Procedures

Is there a way to compare Stored procedure definitions
in different databases?
Eg. I have database A with Stored procedure Sp1
and database B with Stored procedure Sp1
how can I compare the definitions of Sp1 in two databases?
Thank you in advance-
-AsokCheck out SQL Compare by Red-Gate at www.red-gate.com
----
----
--
Need SQL Server Examples check out my website at
http://www.geocities.com/sqlserverexamples
"Asok" <anonymous@.discussions.microsoft.com> wrote in message
news:fca701c43e95$7d34d480$a101280a@.phx.gbl...
> Is there a way to compare Stored procedure definitions
> in different databases?
> Eg. I have database A with Stored procedure Sp1
> and database B with Stored procedure Sp1
> how can I compare the definitions of Sp1 in two databases?
> Thank you in advance-
> -Asok|||Several tools listed here:
http://www.aspfaq.com/2209
In addition, you could script your stored procedures to a file and use
WinDiff (which ships with Visual Studio).
Aaron Bertrand
SQL Server MVP
http://www.aspfaq.com/
"Asok" <anonymous@.discussions.microsoft.com> wrote in message
news:fca701c43e95$7d34d480$a101280a@.phx.gbl...
> Is there a way to compare Stored procedure definitions
> in different databases?
> Eg. I have database A with Stored procedure Sp1
> and database B with Stored procedure Sp1
> how can I compare the definitions of Sp1 in two databases?
> Thank you in advance-
> -Asok|||Hi,
Try dbMaestro. It's a product that allows comparison, migration and archivin
g of database schema and data.
You can find it here:
http://www.extreme.co.il

Compare SQL objects

Is there a stored procedure to allow me to compare two
SQL objects? In my case for example I want to compare
two stored procedures on two different databases?

If there is no SP that does comparison, would there be
any code in SQL DMO that does this?

How does someone learn SQL DMO? Does SQL Server
2000 have by default DMO learning material or I have to
search for books?

Thank youHi

You can try scripting them using DMO and then doing a file compare on the
two files.

Other options are Redgate compare:
http://www.red-gate.com/sql/summary.htm

OR QALite:
http://www.rac4sql.net/qalite_main.asp

John

"serge" <sergea@.nospam.ehmail.com> wrote in message
news:AtHje.74139$JU3.1442129@.wagner.videotron.net. ..
> Is there a stored procedure to allow me to compare two
> SQL objects? In my case for example I want to compare
> two stored procedures on two different databases?
> If there is no SP that does comparison, would there be
> any code in SQL DMO that does this?
> How does someone learn SQL DMO? Does SQL Server
> 2000 have by default DMO learning material or I have to
> search for books?
>
> Thank you|||"serge" <sergea@.nospam.ehmail.com> wrote in message
news:AtHje.74139$JU3.1442129@.wagner.videotron.net. ..
> Is there a stored procedure to allow me to compare two
> SQL objects? In my case for example I want to compare
> two stored procedures on two different databases?
> If there is no SP that does comparison, would there be
> any code in SQL DMO that does this?
> How does someone learn SQL DMO? Does SQL Server
> 2000 have by default DMO learning material or I have to
> search for books?
>
> Thank you

As John suggested, you can use the DMO Script method and compare the output.
This should be fine for procs, but it can be a problem for tables, because
you may have constraints which have been assigned a name by the system - the
constraint definition is identical, but it will show up as a difference in
your diff. You may or may not regard this as a problem, but tools such as
the Red Gate one allow you to configure your comparison to take this into
account, as well as whether or not to compare indexes, if a comparison
should be case-sensitive etc.

As for learning SQL-DMO - Books Online and practice. If you're already
familiar with COM programming, that would be useful, but it's far from
essential. Unfortunately the Books Online documentation doesn't provide many
examples - it tends to describe the steps to follow for a certain task, but
doesn't also give an actual code sample. Even if you want to use SQL-DMO
from a compiled language like VB or C#, I suggest you consider also using a
language such as Perl or Python - it's usually much faster for quick tests
and ad hoc experiments.

Simon|||There is another software tool that compares and synchronises databases
called DB Ghost (www.dbghost.com)
and it does data as well as schema. It is also the foundation for a
SQL Server change management process that works in harmony with any
source control/configuration management system to provide a completely
scalable solution for any size development team that has to work on the
same schema at the same time.

I highly recommend you check it out.

Sunday, March 11, 2012

Compare Permissions Between Databases

I need to compare the permissions for a specific user between two databases
for views, tables, and stored procedures, to make sure that they are the
same.
If I could just figure out how to extract the data from each database, I
don't mind a certain level of manual comparison in Excel.
I have been digging around the syspermissions table, but can't find the
access level that has been granted/denied.
Any suggestions?
Thanks!Look up the PERMISSIONS function in SQL Server Books Online. It returns a
bitmap which can be massaged in t-SQL to retreive the object/statement
permissions.
Anith

Wednesday, March 7, 2012

Compare 2 database schemas?

We're using Sql Server 2000. The one database contained tables and stored procedures which were possibly updated with some script information. Is there an application(commercial or free) or script I can use to compare the base database against this updated database to confirm there schema information is the same.Thanks

You can use the tool provide by Microsoft "Visual Studio Team Edition for Database Professionals"

This will give you Comparison Tools (Schema & Data Compare) allow comparisons & synchronization of schema and data with design/test/production databases

Have a look into the webcast at following url

http://msevents.microsoft.com/CUI/WebCastEventDetails.aspx?culture=en-US&EventID=1032300980

This will give you a good idea

Compact Database

Is there a stored procedure that allow the compact database programmatically
in SQL Server?"Claudio Di Flumeri" <claudioNOSPAM@.mtgc.net> wrote in message
news:c0conk$15i74v$1@.ID-198343.news.uni-berlin.de...
> Is there a stored procedure that allow the compact database
programmatically
> in SQL Server?

Check documentation for
DBCC SHRINKDATABASE|||"Claudio Di Flumeri" <claudioNOSPAM@.mtgc.net> wrote in message news:<c0conk$15i74v$1@.ID-198343.news.uni-berlin.de>...
> Is there a stored procedure that allow the compact database programmatically
> in SQL Server?

I believe compacting is an Access concept - it doesn't exist in MSSQL.
If you want to check the integrity of a database, then you can look at
DBCC CHECKDB; if you want to physically reduce the size of a database,
then DBCC SHRINKDATABASE and DBCC SHRINKFILE would help.

Simon

Friday, February 24, 2012

communicate between two servers

I have two sql servers, A and B. each one has one database, A and B. I am trying to write a stored porcedure in database A to retrieve the data in database B. how do I do it? can you give me a simple example. (like "select")Check Books on Line for info on Linked Servers. Set that up and then you use the fully qualified names

From server A:

select field1, field2 from serverb.databasename.ownername.tablename
where ...|||When I use
servera.database...... in server A it works
but when I use
serverb.database...... in server A it doesnt work.|||what's the error message?

it's supposed to be.. [ [ [ server. ] [ database ] . ] [ owner_name ] . ] object_name|||first, I link two servers. then I run a select in view.
the error msg is
"Access to the remote server is denied because no login-mapping exists"
how do I do?|||It's BOL on how to do it. Linking the servers opens a channel between them. You have to map logins so that you then have the proper access. Basically, you say "If I'm logged in as Joe on server A, when I connect to server B from server A, I want to act like server B's user named Fred." Right click the linked server, Properties, Security tab.

common temp tables in procedures

I have 3 jobs each consists of set of stored procedures.The stored procedures have lots of temp tables. And all the jobs run at the same time.

job1:

EXEc sp1
EXEC sp2
EXEC sp3

Job2

EXEC abc1
EXEC abc2
EXEC abc3
EXEC abc4
EXEC abc5

Job3

EXEC xyz1
EXEC xyz2
EXEC xyz3
EXEC xyz4

But the issue is that the stored procedures in the job1 has temp tables with the same name as stored procedures in the job 2 have.

Eg:

procedure abc1 and procedure sp2 have the temp table #temp1.
procedure abc4 and procedure xyz2 have the temp table #temp3.

Like this i have some more common temp tables. So my question is that can I use the temp tables like that.If so does it degrade the perforamnce of the sps.You can and there is no performance penalty. You might get a performance increase by using table variables though, depending on how small the data is. Temp tables are local to a procedure, so having them named the same in two procs that call each other isn't a problem.

Common Table Expressions!

Hi all
I've checked the CTE's in SQL server 2005 beta 2 it is really a very useful feature but I want to use it with the output of a stored procedure. Is this available?

Thanks in advanceHi,

Can you please be more specific about what you want?

I understood you to say that you wanted to use the result set of a stored procedure as the operand to a relational JOIN operator inside a CTE. AFAIK, that is not allowed. AFAIK, the only place where you can use a stored proceure in a relational (table-valued) expression is the INSERT INTO table.. EXEC proc syntax.

However - I believe you should be able to use a table-valued function.

Regards,
Clifford Dibble

Sunday, February 19, 2012

Committing a Stored Procedure

hi there,

I am connecting to a sql server express 2005 database which is located on another developers machine in the company. he has given me the username and password and i can read and write to this db using vs2005 no problems.

i can also added new tables and everything through the management studio, but when i add stored procedures, it does not seem to commit to the database, when i click save it asks for a local destination but i want it to save onto the sql server.

i can add stored procedures through vs 2005 no problems! this does not make sense?

Hi,

yes it sure does. You don′t have to save the procs you have to execute the DDL rather than saving the code. That should work.

HTH, Jens Suessmeyer.

http://www.sqlserver2005.de

|||Can you please explain how to execute the DDL step by step, because I have pressed EXECUTE and it just runs the query and displays the results|||OK, due to he fact that I don′t have your code right here and you didn′t pasted it in your previous post I assume that you don′t have any DDL code right now.

DDL code (especially for procs) begin with

CREATE PROCEDURE (...)

If you don′t have such DDL code, you just have a query. What code are you executing ?|||

Hi Jens,

I sorted it out...I clicked Stored Procedures>New stored procedure and from the Query Menu>Specify values for template> and then fill that form out and then it commits it to the database NO PROBLEMS!