Wednesday, March 7, 2012

Compairing updated data base.

I do not know SQL but learning fast and furious.

I am programming an agent and working with a group of existing databases.
I would like to able to compare the database before and after an update.
The testing databases are relatively small.
I have no problem programming some compare but how do I go about it.

Should I do this in SQL duplicating the database.
I would be happy to write some SQL and dump the databases and do the compare
externally.

I would appreciate any suggestion.

AndreIf you just want to compare data between similar tables you can do so
with a JOIN:

SELECT COALESCE(A.key_col, B.key_col),
COALESCE(A.col1, B.col1), COALESCE(A.col2, B.col2), ...
FROM TableA AS A
FULL JOIN TableB AS B
ON A.key_col = B.key_col
WHERE COALESCE(A.col1,'')<>COALESCE(A.col1,'')
AND COALESCE(A.col2,'')<>COALESCE(A.col2,'')

assuming key_col is the primary key in both tables.

--
David Portas
SQL Server MVP
--|||What I would like to do is probably
1) back up the data base
2) restore it under a different name
-- run my agent
3) create a difference database ( a new database with any table which is
different)

Step 1 and 2 are easy so can be ignored
now step 3
I can create a new temporary database but how can I fill the tables in this
database using SQL

"David Portas" <REMOVE_BEFORE_REPLYING_dportas@.acm.org> wrote in message
news:1111586542.235632.69940@.o13g2000cwo.googlegro ups.com...
> If you just want to compare data between similar tables you can do so
> with a JOIN:
> SELECT COALESCE(A.key_col, B.key_col),
> COALESCE(A.col1, B.col1), COALESCE(A.col2, B.col2), ...
> FROM TableA AS A
> FULL JOIN TableB AS B
> ON A.key_col = B.key_col
> WHERE COALESCE(A.col1,'')<>COALESCE(A.col1,'')
> AND COALESCE(A.col2,'')<>COALESCE(A.col2,'')
> assuming key_col is the primary key in both tables.
> --
> David Portas
> SQL Server MVP
> --|||Andre Arpin (arpin@.kingston.net) writes:
> What I would like to do is probably
> 1) back up the data base
> 2) restore it under a different name
> -- run my agent
> 3) create a difference database ( a new database with any table which is
> different)
> Step 1 and 2 are easy so can be ignored
> now step 3
> I can create a new temporary database but how can I fill the tables in
> this database using SQL

Red Gate has products for this, check out http://www.red-gate.com/.

If you would like to roll your own, you would have to write a query
like the one that David showed you for each table.

--
Erland Sommarskog, SQL Server MVP, esquel@.sommarskog.se

Books Online for SQL Server SP3 at
http://www.microsoft.com/sql/techin.../2000/books.asp|||You can easily populate a table from another in a different database:

INSERT INTO DatabaseA.dbo.TableA (col1, col2, ...)
SELECT col1, col2, ...
FROM DatabaseB.dbo.TableB
WHERE ... ?

--
David Portas
SQL Server MVP
--

Compairing Data From 2 Tables

Table A

ID Product_code
1 aa
2 bb
3 cc
3 dd

Table B

ID Product_code
1 aa
2 bb
3 cc
3 dd
3 ee
4 aa

I need to compair both tables and return a list ID and Product_code
which is not in both tables ie

Result set

3 ee
4 aa

Thanks

Richard

Here it is,

Code Snippet

Create Table tablea (

[ID] int ,

[Product_code] Varchar(100)

);

Insert Into tablea Values('1','aa');

Insert Into tablea Values('2','bb');

Insert Into tablea Values('3','cc');

Insert Into tablea Values('3','dd');

Create Table tableb (

[ID] int ,

[Product_code] Varchar(100)

);

Insert Into tableb Values('1','aa');

Insert Into tableb Values('2','bb');

Insert Into tableb Values('3','cc');

Insert Into tableb Values('3','dd');

Insert Into tableb Values('3','ee');

Insert Into tableb Values('4','aa');

Code Snippet

select

isnull(a.id,b.id) id,

isnull(a.product_code, b.product_code) product_code

from

tablea a

full outer join tableb b

on a.id=b.id and a.product_code = b.product_code

where

a.id is nullor b.id is null

or

a.product_code is null or b.product_code is null

|||

SELECT * FROM TableA A
WHERE NOT EXISTS
(
Select * from TableB B WHERE A.Id = B.Id AND A.Product_code = B.ProductCode
)
UNION

SELECT * FROM TableB A
WHERE NOT EXISTS
(
Select * from TableB B WHERE A.Id = B.Id AND A.Product_code = B.ProductCode
)

otherwise you could also use INTERSECT / EXCEPT if you are using SQL Server 2005.

Jens K. Suessmeyer

http://www.sqlserver2005.de

compacting LOG file

how can you compact .log file ?
they can be > 20 gigas ! ...
can you delete it ?do you mean the log files that the server itself writes? Those have no file extension normally, usuall called something like ERRORLOG. when the server restarts it renames it to ERRORLOG.1 and starts a new one. I would be very surprised if you have a 20gb one though. that's pretty large. maybe you have a lot of failed login attempts (which are logged as I recall).

Or perhaps you mean a ldf file? These are transaction log files for a database - it's common for these to get large. You can shrink the size of the ldf using DBCC SHRINKFILE. You should not delete an ldf file unless you want to delete the database it's associated with.

Note that if you care about recoverability, you should be making regular backups of both your database and transaction log.|||thank you Jezemine

yes of course I mean transaction log files
DBCC SHRINKFILE ? i musyt look how to use it ? do you run it as a stored procedure ?

EXECUTE DBCC SHRINKFILE

thank you for helping|||it's not a sproc.

read about DBCC SHRINKFILE in bol.

Compacting a db via T-SQL

Hello dbForumers,

I was wondering if there is a way (MUST be) to instruct SQL server to compact a chosen database's files. I have a batch that runs every night who generate a huge amount to log lines that I get rid of with a backup log xxx with truncate_only, but still the logfile is several GB big afterwards with a lotsa empty space... I wanna get a clean small file everyday =)

Thank you!Its not ideal to shrink the Transaction log every day, rather define a set of size by testing the activity on the database.

During that batch overnight take before and after sizes for Tlog and set the higher level.

Also maintain regular backups of Tlogs which will reduce the size of logical file and helps to fillup the Tlog quickly. If RECOVERY MODEL Is set to SIMPLE then ensure full database backups are carried in regular intervals.|||try DBCC SHRINKFILE

USE UserDB
GO
DBCC SHRINKFILE (logical file name,Target_size)
GO

Target_size is how much free size is left over after you shrink
if you leave this off, you will get the default.

also
you may have to switch the VLogs internally before you can shrink to a size that you desire...
all of his should be done after a tlog backup.
look up "Shrinking the Transaction Log" AND DBCC Shrinkfile in [BOL]

Compacting a database MS SQL

Hi
for mS SQL 2000-2500
LDF and MDF files can be very very big, if I import the datas into a new database they can become 10 time smaller
is there a way to compact (reduce the MB) of a database ?
thank youLook up DBCC SHRINKDATABASE and DBCC SHRINKFILE in BOL.|||thank you !|||Do not shrink your databases. It can impair performance. SQL Server databases are not like Microsoft Access databases, and do not need to be regularly compacted.|||if I import the datas into a new database they can become 10 time smaller.

is there a way to compact (reduce the MB) of a database ?

Yeah, you can transfer required data in the new database - using DTS.

Accordingly, make changes in your application for accessing old data too.

Note : Before any action you need to deeply analyze pros & cons for the current issues as well as upcoming issues.

compacting / to repair base of data sql, using the msde

I am developing a project of the access for a friend, more I am with the
following doubts:
Does some exist it sorts things out of compacting / to repair base of data
sql, using the msde or the adp.?
MSDE databases do not require compacting. When updates or other changes are
made, the space freed when a row is deleted is reused automatically. For the
most part, MSDE/SQL Server databases are not subject to the file corruption
problems that are associated (from time-to-time ) with JET databases. There
are utilities (DBCC for one) that can be used to perform maintenance on the
database, but it's unusual to have to resort to these for smaller databases
as typically implemented with MSDE.
____________________________________
William (Bill) Vaughn
Author, Mentor, Consultant
Microsoft MVP
www.betav.com
Please reply only to the newsgroup so that others can benefit.
This posting is provided "AS IS" with no warranties, and confers no rights.
__________________________________
"Frank Dulk" <fdulk@.bol.com.br> wrote in message
news:%23ZUa0OKMEHA.2456@.TK2MSFTNGP12.phx.gbl...
> I am developing a project of the access for a friend, more I am with the
> following doubts:
> Does some exist it sorts things out of compacting / to repair base of data
> sql, using the msde or the adp.?
>

CompactDatabase in ASP with SQL Server Microsoft SQL Server Compact

I've been playing around with Microsoft SQL Server Compact Edition
v3.1 as a posible replacement for the SQL Server CE 2.0 (can't
remember exactly what the called it). Its working pretty well. I
was able to connect to the database using the same recordset object,
ADODB.RecordSet and connection object, ADOCE.Connection.3.1. However
where I've run into trouble is when I try to compact the database.
This code works on 2.0.

srcConn = "Provider=Microsoft." & "SQLServer" & ".OLEDB.CE.2.0;Data
Source=\myDB.sdf"
destConn = "Provider=Microsoft." & "SQLServer" & ".OLEDB.CE.2.0;Data
Source=\myDB.sdf"

Set DBEngine = CreateObject("SSCE.Engine.2.0")

DBEngine.CompactDatabase srcConn, destConn

But now when I try to run it vor v3.1

srcConn = "provider=microsoft.sqlserver.mobile.oledb.3.0;data
source=\myDB.sdf"
destConn = "provider=microsoft.sqlserver.mobile.oledb.3.0;data
source=\mDB1.sdf"

Set DBEngine = CreateObject("SSCE.Engine.3.0")

DBEngine.CompactDatabase srcConn, destConn

I get this error message:

Info: Object required: 'DBEngine'

As I understand it SSCE.Engine.3.0 is still an ActiveX
object. Is it no longer posible to run this directly from
asp?

Using SQL CE under asp.net has been blocked in SQL CE 3.1, see http://msdn2.microsoft.com/en-us/library/system.data.sqlserverce.sqlceengine.aspx. Maybe this is what you are facing with asp as well. Have no idea how to do a

Code Snippet

AppDomain.CurrentDomain.SetData(

under asp classic.