[{"data":1,"prerenderedAt":325},["ShallowReactive",2],{"article-sql-server-comparing-tables-merge-except-intersect":3},{"article":4,"tags":146,"previous":161,"next":219},{"id":5,"title":6,"author":7,"body":8,"createdAt":134,"description":135,"extension":136,"img":137,"meta":138,"navigation":139,"path":140,"seo":141,"stem":142,"tags":143,"updatedAt":134,"__hash__":145},"articles\u002Farticles\u002Fsql-server-comparing-tables-merge-except-intersect.md","SQL Server Comparing Tables","[object Object]",{"type":9,"value":10,"toc":132},"minimark",[11,15,48,60,72,75,81,84,125,128],[12,13,14],"p",{},"I had a need to compare two SQL Server table for differences between them. \nI started using .NET dataset features (merge, acceptchanges, getchanges) as follows: ",[16,17,19,20,25,26,29,30,32,33,36,37,39,40,43,44,47],"div",{"style":18},"font-size: 9pt; background: white; color: black; font-family: consolas","\n        ",[21,22,24],"span",{"style":23},"color: blue","Dim"," data1 DataSet = ",[21,27,28],{"style":23},"GetData1()","          ",[21,31,24],{"style":23}," data2 DataSet = ",[21,34,35],{"style":23},"GetData2()","            ",[21,38,24],{"style":23}," ds ",[21,41,42],{"style":23},"As"," ",[21,45,46],{"style":23},"New"," DataSet         ds.Merge(data1)         ds.AcceptChanges()         ds.Merge(data2)         ds.GetChanges(DataRowState.Modified)",[12,49,50,51,55,59],{},"There are a few gotcha's with the above code.  The primary problem was that\nboth tables must have primary keys defined.  I figured ok,\nI could create primary keys through code for the related DataTables however\nI soon realized that there were duplicate rows within the tables. SQL Server\n2005 has Except and Intersect functions (",[52,53],"a",{"title":54,"href":54},"http:\u002F\u002Fmsdn.microsoft.com\u002Fen-us\u002Flibrary\u002Fms188055(SQL.90).aspx",[52,56,54],{"href":54,"rel":57},[58],"nofollow",") that return distinct values by comparing the results of two queries.  The entire row is compared against another row from another table.",[12,61,62,63,67,68,71],{},"Except returns any distinct values from the left query that are not found on the right query.\nIntersect returns any distinct values that are returned by ",[64,65,66],"strong",{},"both"," the query on the left and right sides. In order to use the number and order\nof the columns must be the same in the queries and also the data types must be comparable.   To return all rows in table1 that do not match exactly the rows\nin table2, you can use Except ...\nselect * from table1 ",[64,69,70],{},"except"," select * from table2",[12,73,74],{},"(likewise to find the opposite just reverse the table names above)",[12,76,77,78,71],{},"To return all rows in table1 that match exactly what is in table2, using Intersect...\nselect * from table1 ",[64,79,80],{},"intersect",[12,82,83],{},"Combining the above two... (the following will return the differences)",[85,86,91],"pre",{"className":87,"code":88,"language":89,"meta":90,"style":90},"language-sql shiki shiki-themes github-light github-dark","select 'table1' as tblName, *  from\n  (select * from Table1 except select * from Table2) x\nunion all\nselect 'table2' as tblName, *  from\n  (select * from Table2 except select *  from Table1 ) x\n","sql","",[92,93,94,101,107,113,119],"code",{"__ignoreMap":90},[21,95,98],{"class":96,"line":97},"line",1,[21,99,100],{},"select 'table1' as tblName, *  from\n",[21,102,104],{"class":96,"line":103},2,[21,105,106],{},"  (select * from Table1 except select * from Table2) x\n",[21,108,110],{"class":96,"line":109},3,[21,111,112],{},"union all\n",[21,114,116],{"class":96,"line":115},4,[21,117,118],{},"select 'table2' as tblName, *  from\n",[21,120,122],{"class":96,"line":121},5,[21,123,124],{},"  (select * from Table2 except select *  from Table1 ) x\n",[12,126,127],{},"If you are fortunate to have primary keys you can of course still use IN\u002FNOT IN type queries however it seems that\nperformance is much improved with the Except\u002FIntersect approach.",[129,130,131],"style",{},"html .default .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}html.dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}",{"title":90,"searchDepth":103,"depth":103,"links":133},[],"2015-04-20T08:07:16.8200000-04:00","Learn how to compare two SQL Server tables","md",null,{},true,"\u002Farticles\u002Fsql-server-comparing-tables-merge-except-intersect",{"title":6,"description":135},"articles\u002Fsql-server-comparing-tables-merge-except-intersect",[144],"sqlserver","a3XLSKncpyYY6AaLiNGJj9hTlH1eTB877PjeGfHig8M",[147],{"id":148,"title":149,"body":150,"description":154,"extension":136,"img":155,"meta":156,"name":144,"navigation":139,"path":157,"seo":158,"stem":159,"__hash__":160},"tags\u002Ftags\u002Fsqlserver.md","Sqlserver",{"type":9,"value":151,"toc":152},[],{"title":90,"searchDepth":103,"depth":103,"links":153},[],"SQL Server is a relational database management system, or RDBMS, developed and marketed by Microsoft.","https:\u002F\u002Fimages.unsplash.com\u002Fphoto-1598313183973-4effcded8d5e?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=675&q=80",{},"\u002Ftags\u002Fsqlserver",{"description":154},"tags\u002Fsqlserver","pSzcNnE-XyUgq8RlgK2xBpbJV7_7o5NLS2XlwBxFyAg",{"id":162,"title":163,"author":7,"body":164,"createdAt":210,"description":211,"extension":136,"img":212,"meta":213,"navigation":139,"path":214,"seo":215,"stem":216,"tags":217,"updatedAt":210,"__hash__":218},"articles\u002Farticles\u002Fsql-server-and-find-all-columns-in-a-database.md","SQL Server and Find all Columns in a Database",{"type":9,"value":165,"toc":208},[166,169,199,206],[12,167,168],{},"Where the column name matches exactly…",[85,170,172],{"className":87,"code":171,"language":89,"meta":90,"style":90},"SELECT name FROM sysobjects WHERE id IN ( SELECT id FROM syscolumns\nWHERE name = '{text}' )\nWhere the column name is like…\nSELECT name FROM sysobjects WHERE id IN \n    ( SELECT id FROM syscolumns WHERE name like '%{text}%' )  \n",[92,173,174,179,184,189,194],{"__ignoreMap":90},[21,175,176],{"class":96,"line":97},[21,177,178],{},"SELECT name FROM sysobjects WHERE id IN ( SELECT id FROM syscolumns\n",[21,180,181],{"class":96,"line":103},[21,182,183],{},"WHERE name = '{text}' )\n",[21,185,186],{"class":96,"line":109},[21,187,188],{},"Where the column name is like…\n",[21,190,191],{"class":96,"line":115},[21,192,193],{},"SELECT name FROM sysobjects WHERE id IN \n",[21,195,196],{"class":96,"line":121},[21,197,198],{},"    ( SELECT id FROM syscolumns WHERE name like '%{text}%' )\n",[12,200,201,202,205],{},"The following will show all occurrences of the column in any object",[203,204],"br",{},"\nSELECT * FROM INFORMATION_SCHEMA.COLUMNS WHERE COLUMN_NAME LIKE '%doctorid%'",[129,207,131],{},{"title":90,"searchDepth":103,"depth":103,"links":209},[],"2015-04-20T08:07:16.9200000-04:00","Find all occurrences of the column in any object.","\u002Farticles\u002Fimages\u002F01dQC8VR9Q.png",{},"\u002Farticles\u002Fsql-server-and-find-all-columns-in-a-database",{"title":163,"description":211},"articles\u002Fsql-server-and-find-all-columns-in-a-database",[89],"7j7MoIgvvTBgGhiyTLQS8O1mSrOntcrI4ggv0hVclEs",{"id":220,"title":221,"author":7,"body":222,"createdAt":315,"description":316,"extension":136,"img":317,"meta":318,"navigation":139,"path":319,"seo":320,"stem":321,"tags":322,"updatedAt":315,"__hash__":324},"articles\u002Farticles\u002Fasp-net-2-0-compilation-again.md","ASPNET 2 Compilation Again",{"type":9,"value":223,"toc":313},[224,227,240],[12,225,226],{},"There are a few ways of deploying a .NET 2.0 ASP.NET application",[228,229,230,234,237],"ul",{},[231,232,233],"li",{},"using Web Site Deployment Project",[231,235,236],{},"using VS.NET Publish Command",[231,238,239],{},"using VS.NET Build Command",[12,241,242,243,245,246,249,250,252,253,255,256,258,259,262,263,266,267,269,281,283,284,286,287,252,289,291,295,297,300,301,303,306,307,309,312],{},"1.) Using VS.NET Build",[203,244],{},"\nASP.NET not Visual Studio performs the build.  ASP.NET builds everything, including .cs and .vb code files and places all resulting assemblies in folder structure under Temporary ASP.NET files directory.  As ASP.NET does all of the compilation, the debug setting in the compilation section of the ",[64,247,248],{},"web.config controls debug or release mode",".  Compile with debug=true and you'll find the .pdb debugging symbol files alongside each assembly.  In this scenario the Configuration Manager is obsolete (not used) and as such the only option is 'Debug'.",[203,251],{},"\n ",[203,254],{},"\n2.) Using VS.NET Publish",[203,257],{},"\nThis option is available when you are ready to publish to production.  The Publish command will precompile a web application and place the results into a director of your choosing (IIS\u002FFTP\u002FDirectory).  Options are available on the Publish dialog box that map to aspnet_compiler switches.  The aspnet_compiler tool has option to create pdb files however this is not available on the dialog box (within vs.net).  Publish always builds in ",[64,260,261],{},"release ","mode without pdb files.  The Publish command does ",[64,264,265],{},"not change the debug setting in the web.config"," SO if you precompile and updateable (option 'allow this precompiled site to be updateable') web site and then update the web site in place (which will result in a dynamic compilation) those dynamic compilations will produce debug code and pdb files.",[203,268],{},[52,270,272],{"href":271},"\u002Farticles\u002Fimages\u002FWindowsLiveWriter\u002FASP.NET2.0CompilationAgain_A80B\u002Fimage_2.png",[273,274],"img",{"style":275,"src":276,"border":277,"alt":278,"width":279,"height":280},"border-width: 0px;","\u002Farticles\u002Fimages\u002FWindowsLiveWriter\u002FASP.NET2.0CompilationAgain_A80B\u002Fimage_thumb.png",0,"image",244,176,[203,282],{},"\n3.) Using Web Site Deployment Project (WSD)",[203,285],{},"\nThis project allows VS.NET to use MSBUILD files provided by WSD to ask for debug and release builds.  This tool uses the aspnet_compiler similar to above with the Publish option however the WSD option will change the debug setting in the web.config to false for release builds (different than the Publish option)  By default the built files will be in respective debug or release directories.",[203,288],{},[203,290],{},[21,292,294],{"style":293},"text-decoration: underline;","Conclusion",[203,296],{},[64,298,299],{},"VS.NET Build"," - builds web site to Temporary ASP.NET files directory with options specified in web.config",[203,302],{},[64,304,305],{},"VS.NET Publish"," - builds to release mode (always) however does not change the compilation mode in web.config file (which can lead to less than optimum performance if site is dynamically recompiled)",[203,308],{},[64,310,311],{},"Web Deployment Project"," - Builds based on Configuration Manager mode (debug\u002Frelease) AND updates the web.config with additional options for creating debug symbols and swapping out web.config sections based on release mode",{"title":90,"searchDepth":103,"depth":103,"links":314},[],"2015-04-20T08:07:16.6100000-04:00","few ways of deploying a .NET 2.0 ASP.NET application.","\u002Farticles\u002Fimages\u002Fimage_thumb.png",{},"\u002Farticles\u002Fasp-net-2-0-compilation-again",{"title":221,"description":316},"articles\u002Fasp-net-2-0-compilation-again",[323],"aspnet","Q7K6EcEId9aFUHSq2rTPkmqg7nFfMagSzSQpOK5YPu4",1781574768437]