Compare Schema Between Tables

Oct 6, 2006

In the process of purging data to history tables,
we wanted to make sure that no schema changes have been done
to the main or the history table.
So to ensure identical schemas, we use this function:


ALTER FUNCTION dbo.fnCompareTableSchema
(
@t1Name NVARCHAR(257)
,@t2Name NVARCHAR(257)
)
RETURNS BIT
AS
/*
Compares the schema of 2 tables
If the schema is different RETURNS 0
If the schema is identical between the two table, RETURNS 1
NOTE: system tables or non-existant tables that are NOT in INFORMATION_SCHEMA views will compare equal (RETURNS 1)
==================================================================================================================
SAMPLE USAGE:
DECLARE @schemaOK BIT
SELECT @schemaOK = dbo.fnCompareTableSchema('dbo.table1','dbo.table2')

IF @schemaOK = 1
PRINT 'TABLE SCHEMA IDENTICAL'
ELSE
PRINT 'TABLE SCHEMA DIFFERENT'
==================================================================================================================
*/
BEGIN
IF @t1Name = @t2Name
RETURN 1

-- check if schema is different
IF EXISTS
(
SELECT*
FROM
(
SELECTCOLUMN_NAME, ORDINAL_POSITION, DATA_TYPE
, COLUMN_DEFAULT, IS_NULLABLE
, CHARACTER_MAXIMUM_LENGTH, NUMERIC_PRECISION, NUMERIC_SCALE
, COLLATION_NAME
FROMINFORMATION_SCHEMA.COLUMNS
WHERETABLE_SCHEMA = COALESCE(PARSENAME(@t1Name,2),'dbo') AND TABLE_NAME = PARSENAME(@t1Name,1)
UNION ALL
SELECTCOLUMN_NAME, ORDINAL_POSITION, DATA_TYPE
, COLUMN_DEFAULT, IS_NULLABLE
, CHARACTER_MAXIMUM_LENGTH, NUMERIC_PRECISION, NUMERIC_SCALE
, COLLATION_NAME
FROMINFORMATION_SCHEMA.COLUMNS
WHERETABLE_SCHEMA = COALESCE(PARSENAME(@t2Name,2),'dbo') AND TABLE_NAME = PARSENAME(@t2Name,1)
) U
GROUP BY
COLUMN_NAME, ORDINAL_POSITION, DATA_TYPE
HAVING COUNT(*) <> 2
)
RETURN 0

-- schema identical
RETURN 1
END

View 6 Replies


ADVERTISEMENT

SQL 2012 :: Database Project Schema Compare Fails To Pull In CDC Tables

Jul 11, 2014

I have a database project where objects have been pulled in from the database using schema compare.

Unfortunately CDC tables which are referenced in stored procedures on the database have not been pulled in by the schema compare & hence I cannot build the project and deploy changes back to the database.

How to get these tables included in the project .

View 1 Replies View Related

Compare Schema's...XSD

Jul 20, 2005

Hey all,I am currently researching ways to compare databases via an XSD schema.I wrote a small app that creates a dataset from a database and exportsthat dataset to XSD. This gives me an XSD file with tables andrelationships representing the entire database.At this point, I am trying to find ways to compare these schemas. Doesanybody know of a way to do this easily and to record differences ifthere are any?Also, any information on comparing databases using any method would begreatly appreciated.Thanks,--Shock

View 3 Replies View Related

Schema And SP Compare Recommendations

Dec 3, 1999

I've searched quite a bit, and have found several leads on schema, stored procedure, and database contents comparison scripts and tools.

I'm now looking for recommendations on which ones are best, easiest:

ObjCompare.exe
sb_ABCompareDb.sql
sp_db_comp.sql

There's a mythical script from Andrew Z <mumble> that Mike Hotek talks about...

There's a DBCompare on the Back Office Resource Kit 2 CD, which of course is not in the umpteen MSDN CDs :-(

There's some *other* command line dbcompare, or maybe db_compare.

There's a DBA Compare.

I need to be able to compare divergent schemas from two developers to integrate their changes, so need schema and stored procedures compared only, and would also like to have something to compare staging servers and production servers.

Leads on other choices also welcome. I'd be happy to summarize and post, if warranted.

View 1 Replies View Related

SQL 2012 :: DB Schema Compare Scripts

Apr 16, 2015

I am looking for some SQL Scripts/tool to compare the two sql database and generate the difference results into Excel file. I am not looking for Sync/change scripts.

Example:

Result Type Desc
-----------------------
Col1 Column Added
Table1 Table Removed

View 9 Replies View Related

SQL 2012 :: Schema Compare Tools

Jun 30, 2015

Following an upgrade to SQL Server 2012, our shop's Schema Compare tool (Redgate SQL Compare) is no longer supporting our environment.We are starting to evaluate various 3rd party products to find a possible replacement, and would be interested in what products are favored by other IT shops who do a lot of database work.

Our shop is split about 75% SQL Server, 20% Oracle, and 5% I'll call other. Ideally a product would support SQL Server and Oracle, but our focus is on SQL server right now. On that platform we have ~50 servers spread across DevUATProd environments.In basic terms, we need a tool that can identify schema differences between DBs and generate synchronization scripts to support deploys between environments. Real-time synchronization is not a requirement (nor desirable), as deploys are a gated DBA function in our shop.

View 2 Replies View Related

Needs A SQL 2005 Data And Schema Compare Tool

Mar 12, 2008

Just wondering if there are any tools available for SQL Server 2005 which allow the comparison and scripting of data and schema between two databases. This is so that I can migrate between Dev, QA, and Live easily.

A free tool would be best please..

Thanks in advance.
Gaj

View 11 Replies View Related

VS2013 SSDT Crash On Schema Compare?

Aug 25, 2014

We are getting regular SSDT/VS crashes when doing schema compares (source: project, target: server). Sometimes the compare succeeds but around 80% of the time we get a crash.

We are using VS2013 Update 3 and the latest version of SSDT.

Application : devenv.exe
Version du Framework : v4.0.30319
Description : le processus a été arrêté en raison d'une exception non gérée.
Informations sur l'exception : System.Runtime.InteropServices.COMException
Pile :
   à System.Runtime.InteropServices.Marshal.ThrowExceptionForHRInternal(Int32, IntPtr)

[code]....

View 5 Replies View Related

Export Schema Compare To HTML Report

Jan 3, 2013

I've downloaded and installed the latest SQL Server Data Tools for VS 2012.  Is there anyway to export the results of the schema comparison into a report in CSV/Html format?  I understand that it can generate the sql diff script, but I want a readable report that I can use to show to people.

View 5 Replies View Related

Schema Compare Is Dropping User Membership By Itself

Jul 8, 2015

I just recently updated to SSDT 12.0.50512.0 using Visual Studio 2013 Ultimate. I typically use SSDT Schema Compare to synchronize my schema across multiple databases and different environments. After updating i encountered a major bug while updating our production schema.Typically during schema compare, the compare will prompt me to drop users and user roles from the database as they are not present in the project. I will exclude these so they database users and their roles aren't affected. After the update to SSDT I noticed that schema compare was only prompting me to drop the User, but didn't show anything about the user's roles. Not thinking much of it I went through my usual task of updating all the production databases. I soon found out that this did in fact remove the user roles even though it showed NOTHING in the schema compare UI indicating it would do so.

GO
PRINT N'Dropping <unnamed>...';

GO
EXECUTE sp_droprolemember @rolename = N'db_datareader', @membername = N'dbuser';

GO
PRINT N'Dropping <unnamed>...';

GO
EXECUTE sp_droprolemember @rolename = N'db_datawriter', @membername = N'dbuser';

You could say this is partially my fault for not checking the generated script before running it, but after months of this routine task I've never had an issue until this update.i'm not seeing the changes that will happen to my user roles in the schema compare UI? 

View 2 Replies View Related

Scripting Variables With Schema Compare Via Msbuild?

Jun 12, 2015

I'm trying to automate comparing the dacpacs we're generating from out builds against our production server to monitor drift.However, we use scripting variables to define cross database references.  The schema compare is showing up all the objects which reference the other database via scripting variable as being different to what is on the server i.e. it reports a change between a table referenced as  [$(db)].dbo.Table in the dacpac  and db.dbo.Table in the target database.

When I do a comparison in Visual studio between the project and the target database the variables seem to be appropriately replaced and the differences don't show.  Obviously this is using a project instead of a dacpac but I'm hoping I can get the dacpac/db compare to behave similarly to the project/db comparison.

Is there a way to define what the scripting variables should resolve to when I run the comparison via msbuild?

Edit:  I would prefer not to deploy the dacpac and diff the deployed db against the target database but if that's the only way....

View 5 Replies View Related

Schema Compare Cannot Exclude Items With Dependencies

Nov 22, 2012

I've made a comparison between a database project (sqlproj) and a database.

I can't exclude some items because they are dependent items on them. So they are implicitly included in the update script.

Unfortunately when I have unchecked all the items, some of them are still implicitly included.

It seems that there are circular dependency or some thing like that.

View 5 Replies View Related

Schema Compare Errors Using Three Part Naming

Jul 28, 2015

I am importing an existing database into a Visual Studio SQL Server Database project using Schema Compare.  The Schema Compare works fine and I updated my project successfully.  However, the project won't build because of the existence of 3-part names in some objects:

E.g. I import the database MyDB into a new project MyDB using Schema Compare.  The database contains views with queries like this:

SELECT col1, col2. col3
FROM MyDB.dbo.MyTable

When trying to build this project I get errors like:

Error 39
SQL71561: View: [dbo].[vw_MyView] has an unresolved reference to object [MyDB].[dbo].[MyTable].
C:UsersRedirectionrittg2DocumentsVisual Studio 2012ProjectsMySolutionMyDBdboViewsvw_MyView_1.sql

but of course this is a bogus message since the view can clearly read from an object in the same database whether using 2-, 3-part naming (or 4-part naming for that matter).

How can I resolve these errors without editing the objects before running Schema Compare? (there are hundreds of them).

View 5 Replies View Related

VS 2013 - Schema Compare Is Not Applying Changes To Target Database Project

Aug 11, 2015

I have created Database projects in VS 2013 using SSDT. I have been mostly successful in creating and building the projects without any errors/warnings.

However for one of the databases in the project, when i do schema compare to apply the changes from a SQL Server Database to a Database Project in VS, code changes are not applied to the database project.

After i select the Update option in Schema compare window, I'm getting the following message

"Target update complete. Press Compere to refresh the comparison."

Even tough the message implies that target database is updated successfully, I do not see the objects i selected in schema compare being added to the target database project.

I see the following warning

"Target update: Could not update script for element 'dbo'"

I have 9 Database projects in the Solution and I'm able to apply changes to 8 of the database projects through schema compare successfully. I get the same warning after schema compare for all database projects.

I have same project level setting for all database projects in the solution. I'm using Visual Studio 2013 Premium Update 5 SQL Server Data Tools 12.0.41012.0

View 3 Replies View Related

When Have 4 Tables How To Compare Table With 4nd Table? ( Need To Join And Compare With Datatime)

Jul 22, 2007

Table MediaImportLog
column ↘ImportIndex     ImportFileTime            ImportSource
value    ↘80507             20060506001100          815
              80511             20061109120011           CRD                       ã€? P.S the values type of ImportFileTime 20060506001100 → 2006 -year 05-month 06-day 00-HH 11-minute 00-second】
Table  BillerChain
column↘BillerInfoCode       ChainCode
value   ↘750                      815
value   ↘81162                  CRD
Table   Biller
column↘CompanyCode         BillerCode
value   ↘999                     750
value   ↘81162                  516
TAble DataBackup
column↘CompanyCode         Keepmonth
value   ↘999                     6
value   ↘81162                 12
 
---------------------------------------------------
 
when I'm in MediaImportLog , I want use column ImportSource to compare with column ChainCode in table BillerChain ( so I get BillerInfoCode) and then use the BillerInfoCode I got to compare with column BillerCode in Table Bill ( I get CompanyCode) finally I use CompanyCode to compare with column CompanyCode in table DataBackup so I can get the company's keepmonth
How can I get the keepmonth? can I use parameters ? 
 
thank you very much 

View 3 Replies View Related

Compare Two Tables

Dec 8, 2000

I need to compare two identical tables and return the rows that are different,they are not having any primary key. Anyone to help with the query?
Thanks.

View 1 Replies View Related

Can I Compare Two Tables

Jan 14, 2000

Is it possible (easily) to compare two identical tables (one from server1 'SQL7', one a download from an Oracle DB into SQL7) to see if the Oracle table has changed, what is the changed row and place said row into another table to do some other process on those changed rows?

Thanks,
Bill

View 2 Replies View Related

How To Compare 2 Tables ??

Jul 1, 2004

Hi,

Need help with the structuring of the following query:
I've got 2 tables nl :tableA, tableB
I need to do a query to determine wat DISTINCT values of a column(cIdNo) in tableA is not present in column (bIdNo) in tableB.

tableA contains Id numbers of people who still has to pay their bills, and tableB contains Id numbers of people who already paid. So I want a query to determine who still needs to pay.

I've tried the following but doesn't work, not to sure if it's the right wayto do it:


PHP Code:




 SELECT  distinct(cIdno) as IdNumber 
FROM tableA 
LEFT JOIN tableB
ON tableA.cIdNo != tableB.bIdNo 






PLEASE HELP !! Thanks in advance !!!

View 3 Replies View Related

How To Compare Each Row In Two Tables

Jul 10, 2012

I have two the same structure tables. One is the source table (table1), another one is the destination table (table2).

Now I want to compare these two table row by row.

For example,

If table1 row1 is the same as table2 row1, go to next
If table1 row2 is not the same as table2 row2, update table2 row2 to make it the same as table1 row2.
If table1 row3 is not existed in table2 row3, insert table1 row3 into table2 blank new row.

How to create this script?

View 3 Replies View Related

Compare 2 Tables

Jun 8, 2006

I have 2 tables that are exactally the same.

Table 1 - Is named LIVE
Table 2 - Is name EOM (End of Month)

The 2 tables have these fields
MEMBER
STREET

I want to build a query that will return any member who has changed their address (ex: member's eom address is "123 main st", and now their live address is "345 apple st")

But I do not want to display any addresses that are different because that member wasn't a member last month (not in the eom table)

Note: Member Numbers Never Change, only addresses will.

Thanks in advance for any help/suggestions.

View 2 Replies View Related

How To Compare 2 Tables

Dec 17, 2007

need to know how to check both table data and return only data that doesn't match the other table data


select distinct dept_name
from bb_guide_party_dept d, binbox_dept e where d.dept_id = e.dept_id
and e.active_Flag = 1

union
select distinct dept_name
from bb_guide_party_dept a, binbox_dept b where a.dept_id = b.dept_id
and e.dept_name not the same as b.dept_name

View 3 Replies View Related

How To Compare Different Tables

Jan 31, 2008

hi, I'm pretty new to ssis so this may be an absolute beginner question but i couldn't find a solution yet. the task is to compare data from tow tables which are of the same structure. table1 contains data before some operations and table2 contains the results. now i have to find out which datasets have been changed, which one are new and which one are gone.

i've done some googlin and found this TableDifference http://www.sqlbi.eu/Projects/TableDifference/tabid/74/Default.aspx component, but to me it seems to be kind of buggy, so I had the idea of trying to set an sql statement on both ole db sources where i tried to select only the datasets that are not contained in the other table. so i tried something like this:

select * from lib.table_1 except select * from lib.table_2

but this doesn't work either. so i would be really thankful if someone could help me.

View 1 Replies View Related

How To Compare Data In Tables

Sep 13, 2001

I know this sounds simple, but I haven't seen it in bol. I need to compare two tables, and list what rows are unique to each table. Thanks for the help!

rb

View 2 Replies View Related

Compare Two Tables...URGENT!

Dec 7, 2000

Can anyone give me the query that I can use to to compare the data between two similar tables.Data from col1,col2,col3,col4 needs to be compared. Col1 is primary key in both the tables.It should return with zero rows if they are same.
Thanks for any help.

View 1 Replies View Related

Compare/filter 2 Tables...help!!!

May 13, 2004

Would appreciate if someone could help!

I have 2 tables , table 1 and table 2. Exact copies of some records from table 1 also exist in table 2. What i need to do is display records that exist in table 1 but do not exist in table 2.

Thanks for your help!

View 3 Replies View Related

Query To Compare Two Tables

Aug 4, 1999

Hi,

I am trying to write a query to compare the same column in each table with "not equal" expression.

My query is like this:

select tableOne.empl_ser_no from tableOne, tableTwo
where tableOnel.empl_ser_no <>(select empl_ser_no from tableTwo)

I am getting the following message from SQL Server:

Msg 512, Level 16, State 1
Subquery returned more than 1 value. This is illegal when the subquery follows =, !=, <, <= , >, >=, or when the subquery is used as an expression.
Command has been aborted.

View 1 Replies View Related

How Do You Compare The Data In Two Tables

Sep 29, 2005

I have two tables and I want to know if every record from the first table is in the second one and if its data mathes exactly?

Any suggestion for a short way to do this?

Thank you!

View 10 Replies View Related

Compare Each Rows In Two Tables?

Nov 16, 2011

I need to compare two tables in each row. the tables are as follows:-

Table a:

Code:
IDFirst_Name Last_name Birthdate
1Shradha Deshkmukh 1981-12-25 00:00:00
2Shradha Verma 1981-05-11 00:00:00
3Divya Dutta 1982-07-21 00:00:00
4Matthew Palmer 1983-12-28 00:00:00

table d:-

Code:
idfnlndob
1ShradhaTiwari1981-12-25 00:00:00
2DivyaDutta1983-07-21 00:00:00
3SulabhManesar1975-09-11 00:00:00
4MatthewPalmer1983-12-28 00:00:00
5SamuelMaxwell1984-05-22 00:00:00

I want to compare the tables using first name, and I have a log variable which I want to have the value as per the differences in the table that is if the first name matches and second name and dob dont match it shows log value for that FN as 'LN and DOB dont match'.

similarly if First name matches and dob matches then @log is 'LN not match'.

And in case all three match it should show 'match'as log value.The query I use is a s follows:-

Code:
USE testing
GO
DECLARE @NR int
DECLARE @log varchar(200)
SELECT @NR = COUNT(*) FROM a
WHILE @NR>0

[code]...

the result I am getting is :-

Code:
fnlndob (No column name)
ShradhaTiwari1981-12-25 00:00:00match
ShradhaTiwari1981-12-25 00:00:00match
DivyaDutta1983-07-21 00:00:00match
MatthewPalmer1983-12-28 00:00:00match

I have tried using CASE but that doesnt work either.

View 3 Replies View Related

How To Compare Two Huge Tables

Aug 15, 2012

I need to compare if two developers did the job correctly and created identical tables.

The problem is more complex, but I will try to solve it somehow if I solve the problem of comparing two tables (let them be in different SQL Server 2008 databases) and their properties. No data needs to be compared.

View 6 Replies View Related

Compare Amounts Between 2 Tables

Sep 21, 2012

I have two tables. One is Invoice_tbl, with one account per customer.

This table has 3 fields; CustomerID, InvoiceAmount, InvoiceID.

Then second table is, Payment_tbl, with 2 fields; InvoiceID and PaymentAmount. The Payment table can have multiple payments from each customer.

With Access, i would run a QUERY(call it PaymentTotal) against Payment_tbl, then do a "GroupBy" on InvoiceID and SUM on the "Amount" field.

I then would create a NEW query against Invoice_tbl and INNER JOIN on Payment Total.

How would i do this with SQL?

View 6 Replies View Related

Compare Update On Two Tables?

Feb 27, 2014

I have 2 tables. They both have the same fields [OFO_Code] and [Description]

Table 1 is Called Qualification and Table 2 OFO_Code. The second table is a lookup table. The info in Table 1 's description column in some places does not match that of Table 2.

I am trying to loop through these tables to Update the info in Table 1's description to match the correct description in Table 2.

Their are 1417 items in Table 2 and 77000 items in table 1.

There are NO errors when executing, just no update

Here is my code so far:

Code:
Update Qualification SET [Description] = B.Description FROM Qualification A INNER JOIN OFO_code B ON A.OFO_CODE = B.OFO_CODE WHERE A.OFO_Code IN ('" & OFO & "' )"

View 7 Replies View Related

How To Compare 3 Columns From 2 Tables

Jul 26, 2013

I have requirement like this

1 st column 'A1Ctest' 2 nd column 'diagnoising heart disease' and my 3 rd column is combination of both columns
'A1Ctest for diagnoising heart disease'.Here i need to comapre 'A1Ctest' from 1st column and 'diagnoising heart disease' from 2 nd column

View 5 Replies View Related

Query To Compare Two Tables

Dec 26, 2013

I am new to writing the queries in SQL.I want to write a query which will compare the data of two tables which are resides in DEV server and PROD Server.For the conncetivity purpose we are creating the DB link between DEV and PROD server.query to compare the data of table in DEV and table in PROD

View 2 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved