[{"data":1,"prerenderedAt":2066},["ShallowReactive",2],{"tag-sqlserver":3},{"tag":4,"articles":24},{"id":5,"title":6,"body":7,"description":14,"extension":15,"img":16,"meta":17,"name":18,"navigation":19,"path":20,"seo":21,"stem":22,"__hash__":23},"tags\u002Ftags\u002Fsqlserver.md","Sqlserver",{"type":8,"value":9,"toc":10},"minimark",[],{"title":11,"searchDepth":12,"depth":12,"links":13},"",2,[],"SQL Server is a relational database management system, or RDBMS, developed and marketed by Microsoft.","md","https:\u002F\u002Fimages.unsplash.com\u002Fphoto-1598313183973-4effcded8d5e?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=675&q=80",{},"sqlserver",true,"\u002Ftags\u002Fsqlserver",{"description":14},"tags\u002Fsqlserver","pSzcNnE-XyUgq8RlgK2xBpbJV7_7o5NLS2XlwBxFyAg",[25,167,213,250,358,397,727,819,877,935,1020,1173,1213,1251,1370,1551,2000],{"id":26,"title":27,"author":28,"body":29,"createdAt":157,"description":158,"extension":15,"img":159,"meta":160,"navigation":19,"path":161,"seo":162,"stem":163,"tags":164,"updatedAt":157,"__hash__":166},"articles\u002Farticles\u002Fmicrosoft-sqlserver-types-getting-it-done.md","Microsoft.SqlServer.Types–Getting it done.","[object Object]",{"type":8,"value":30,"toc":155},[31,40,54,120,126,129,134,137,140,151],[32,33,34,35,39],"p",{},"Recently, started working with SQL Server GeoSpatial types. Specifically I am using column type ",[36,37,38],"strong",{},"geography. ","\nAll was working fine when using on localhost web site however after deployment to a test environment, I go the following exception.",[32,41,42,43,46,47,50,53],{},"Initially, I thought something was not installed on the server (could still be) however the following is the exception and the resolution. Exception:",[44,45],"br",{},"\nSystem.InvalidOperationException: Spatial types and functions are not available for this provider because the assembly ",[36,48,49],{},"'Microsoft.SqlServer.Types'",[36,51,52],{},"version 10 or higher could not be found",".",[55,56,60],"pre",{"className":57,"code":58,"language":59,"meta":11,"style":11},"language-html shiki shiki-themes github-light github-dark","at System.Data.Entity.SqlServer.SqlTypesAssemblyLoader.GetSqlTypesAssembly() \nat System.Data.Entity.SqlServer.SqlSpatialDataReader.\u003C.cctor>b__0() at System.Lazy`1.CreateValue() \n--- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Lazy`1.get_Value()\nat System.Data.Entity.SqlServer.SqlSpatialDataReader.GetGeography(Int32 ordinal) at\nSystem.Data.Entity.Core.Common.Internal.Materialization.Shaper.ErrorHandlingValueReader`1.GetValue(DbDataReader reader, Int32 ordinal) at\nSystem.Data.Entity.Core.Common.Internal.Materialization.Shaper.GetSpatialPropertyValueWithErrorHandling[TProperty](Int32 ordinal, String propertyName, String \ntypeName, PrimitiveTypeKind spatialTypeKind) at lambda_method(Closure , Shaper ) Resolution: To include in your project for deployment purposes, \nuse nuget to get Microsoft.SqlServer.Types package. \n","html",[61,62,63,72,84,90,96,102,108,114],"code",{"__ignoreMap":11},[64,65,68],"span",{"class":66,"line":67},"line",1,[64,69,71],{"class":70},"sVt8B","at System.Data.Entity.SqlServer.SqlTypesAssemblyLoader.GetSqlTypesAssembly() \n",[64,73,74,77,81],{"class":66,"line":12},[64,75,76],{"class":70},"at System.Data.Entity.SqlServer.SqlSpatialDataReader.",[64,78,80],{"class":79},"s7hpK","\u003C",[64,82,83],{"class":70},".cctor>b__0() at System.Lazy`1.CreateValue() \n",[64,85,87],{"class":66,"line":86},3,[64,88,89],{"class":70},"--- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Lazy`1.get_Value()\n",[64,91,93],{"class":66,"line":92},4,[64,94,95],{"class":70},"at System.Data.Entity.SqlServer.SqlSpatialDataReader.GetGeography(Int32 ordinal) at\n",[64,97,99],{"class":66,"line":98},5,[64,100,101],{"class":70},"System.Data.Entity.Core.Common.Internal.Materialization.Shaper.ErrorHandlingValueReader`1.GetValue(DbDataReader reader, Int32 ordinal) at\n",[64,103,105],{"class":66,"line":104},6,[64,106,107],{"class":70},"System.Data.Entity.Core.Common.Internal.Materialization.Shaper.GetSpatialPropertyValueWithErrorHandling[TProperty](Int32 ordinal, String propertyName, String \n",[64,109,111],{"class":66,"line":110},7,[64,112,113],{"class":70},"typeName, PrimitiveTypeKind spatialTypeKind) at lambda_method(Closure , Shaper ) Resolution: To include in your project for deployment purposes, \n",[64,115,117],{"class":66,"line":116},8,[64,118,119],{"class":70},"use nuget to get Microsoft.SqlServer.Types package.\n",[32,121,122],{},[123,124],"img",{"alt":11,"src":125},"\u002Farticles\u002Fimages\u002Fwindows-live-writer-spatial-types-and-functions-are-not-avai_a814-sqlservertypenuget_2.jpg",[32,127,128],{},"After the package is installed, the following readme will give you details for both ASP.NET and Desktop applications.",[32,130,131],{},[123,132],{"alt":11,"src":133},"\u002Farticles\u002Fimages\u002Fwindows-live-writer-spatial-types-and-functions-are-not-avai_a814-actionrequired_2.jpg",[32,135,136],{},"To deploy an application that uses spatial data types to a machine that does not have 'System CLR Types\nfor SQL Server' installed you also need to deploy the native assembly SqlServerSpatial110.dll.Both x86 (32 bit) and x64 (64 bit) versions of this assembly have been added to your project under the SqlServerTypes\\x86 and SqlServerTypes\\x64 subdirectories.",[32,138,139],{},"The native assembly msvcr100.dll is also included  in case the C++runtime is not installed.  Adding the following to the Global.asax.cs Application_Start()",[55,141,145],{"className":142,"code":143,"language":144,"meta":11,"style":11},"language-csharp shiki shiki-themes github-light github-dark","SqlServerTypes.Utilities.LoadNativeAssemblies(Server.MapPath(\"~\u002Fbin\"));\n","csharp",[61,146,147],{"__ignoreMap":11},[64,148,149],{"class":66,"line":67},[64,150,143],{},[152,153,154],"style",{},"html pre.shiki code .sVt8B, html code.shiki .sVt8B{--shiki-default:#24292E;--shiki-dark:#E1E4E8}html pre.shiki code .s7hpK, html code.shiki .s7hpK{--shiki-default:#B31D28;--shiki-default-font-style:italic;--shiki-dark:#FDAEB7;--shiki-dark-font-style:italic}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":11,"searchDepth":12,"depth":12,"links":156},[],"2020-06-11T20:28:49.852Z","SQL Server GeoSpatial types","\u002Farticles\u002Fimages\u002Fwindows-live-writer-spatial-types-and-functions-are-not-avai_a814-sqlservertypenuget_thumb.jpg",{},"\u002Farticles\u002Fmicrosoft-sqlserver-types-getting-it-done",{"title":27,"description":158},"articles\u002Fmicrosoft-sqlserver-types-getting-it-done",[165,18],"mvc","1dmx9etHvwEb9Xf4khJPeF6FdCgWY2eXe5VWYxfvRO4",{"id":168,"title":169,"author":170,"body":171,"createdAt":204,"description":205,"extension":15,"img":170,"meta":206,"navigation":19,"path":207,"seo":208,"stem":209,"tags":210,"updatedAt":204,"__hash__":212},"articles\u002Farticles\u002Fsql-server-reporting-services-ssrs-how-to-open-ssrs-project.md","SQL Server Reporting Services (SSRS)–How to open SSRS Project",null,{"type":8,"value":172,"toc":202},[173,176,179],[32,174,175],{},"When you're trying to open your SSIS or SSRS solution, you will get a message that the migration has failed or\n'The application which this project type is based on was not found.'",[32,177,178],{},"You can open rptproj files with Visual Studio 2017 with an extension.  Follow the following steps to get going.",[180,181,182,186,189,196,199],"ul",{},[183,184,185],"li",{},"Open ‘Microsoft Visual Studio 2017‘.",[183,187,188],{},"In the menu bar, expand ‘Tools‘, then choose ‘Extensions & Updates‘. to install an extension.",[183,190,191,192,195],{},"Search for ‘",[36,193,194],{},"Microsoft Reporting Services Projects","‘, and install this extension.",[183,197,198],{},"To complete the installation, shut down all windows and instances of Microsoft Visual Studio 2017. Then the installer will start.",[183,200,201],{},"Try to open your solution or projects (*.rptproj) again.",{"title":11,"searchDepth":12,"depth":12,"links":203},[],"2019-03-03T21:18:35.918Z","Ever try to open an older SQL Server Reporting Services (SSRS) project and do not know what product it opens with?  SSRS and how to add\u002Fmanage reports always seems to be a problem.  Well, Visual Studio 2017 has an extension that you can use to open the older rptproj files.  Give it a go.",{},"\u002Farticles\u002Fsql-server-reporting-services-ssrs-how-to-open-ssrs-project",{"title":169,"description":205},"articles\u002Fsql-server-reporting-services-ssrs-how-to-open-ssrs-project",[18,211],"aspnet","mikQhQ-Cqxon8GSkXwjPOgBtZoZDTnq6qSx9SMWr80o",{"id":214,"title":215,"author":170,"body":216,"createdAt":242,"description":243,"extension":15,"img":236,"meta":244,"navigation":19,"path":245,"seo":246,"stem":247,"tags":248,"updatedAt":242,"__hash__":249},"articles\u002Farticles\u002Fcannot-execute-as-the-database-principle.md","Cannot execute as the database principle",{"type":8,"value":217,"toc":240},[218,221,226],[32,219,220],{},"I resolved this issue by setting database owner. My database did not have had any owner before this issue. Execute this command in your database to set owner to sysadmin account",[55,222,223],{},[61,224,225],{},"use [YourDatabaseName] EXEC sp_changedbowner 'sa'\n",[32,227,228],{},[229,230,232],"a",{"href":231},"\u002Farticles\u002Fimages\u002Fimage_636694161252157189.png",[123,233],{"style":234,"title":235,"src":236,"alt":235,"width":237,"height":238,"border":239},"border: 0px currentcolor; display: inline; background-image: none;","image","\u002Farticles\u002Fimages\u002Fimage_thumb_636694161255987537.png",416,97,0,{"title":11,"searchDepth":12,"depth":12,"links":241},[],"2018-08-09T16:55:25.000Z","My database did not have had any owner before this issue. Execute this command in your database to set owner to sysadmin account",{},"\u002Farticles\u002Fcannot-execute-as-the-database-principle",{"title":215,"description":243},"articles\u002Fcannot-execute-as-the-database-principle",[18],"PbylAI9ZBnAUp_zBnJXlFXGO3ZSZlRYI-Inwu0l9OrU",{"id":251,"title":252,"author":28,"body":253,"createdAt":351,"description":257,"extension":15,"img":269,"meta":352,"navigation":19,"path":353,"seo":354,"stem":355,"tags":356,"updatedAt":351,"__hash__":357},"articles\u002Farticles\u002Fsql-server-profiler-trace-for-your-application.md","SQL Server Profiler - Trace for your Application",{"type":8,"value":254,"toc":349},[255,258,261,272,275,285,296,299,309,312,322,341],[32,256,257],{},"I want to watch the queries made by my application during development efforts.",[32,259,260],{},"Here is what I do… from SQL Server Management Studio, select SQL Server Profiler",[32,262,263],{},[229,264,266],{"href":265},"\u002Farticles\u002Fimages\u002Fwindows-live-writer-cdd803dd36c3_860d-image_2.png",[123,267],{"style":268,"src":269,"border":239,"alt":235,"title":235,"width":270,"height":271},"background-image: none; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border-width: 0px;","\u002Farticles\u002Fimages\u002Fwindows-live-writer-cdd803dd36c3_860d-image_thumb.png",240,147,[32,273,274],{},"Start a new trace, providing the trace name (here I entered My Trace).  Select ‘Tuning’ for the ‘Use the Template’.  The Tuning template only watches the key events from SQL (RPC:Completed, SP:StmtCompleted, SQL:BatchCompleted).  Many of the other events while important just are not important to me at this point.",[32,276,277],{},[229,278,280],{"href":279},"\u002Farticles\u002Fimages\u002Fwindows-live-writer-cdd803dd36c3_860d-image_4.png",[123,281],{"style":268,"src":282,"border":239,"alt":235,"title":235,"width":283,"height":284},"\u002Farticles\u002Fimages\u002Fwindows-live-writer-cdd803dd36c3_860d-image_thumb_1.png",326,208,[32,286,287,288],{},"Select the columns of value to you, including ApplicationName, HostName, LoginName and DatabaseName.  I also like to add columns StartTime, EndTime and RowCounts\n",[229,289,291],{"href":290},"\u002Farticles\u002Fimages\u002Fwindows-live-writer-cdd803dd36c3_860d-image_8.png",[123,292],{"style":268,"src":293,"border":239,"alt":235,"title":235,"width":294,"height":295},"\u002Farticles\u002Fimages\u002Fwindows-live-writer-cdd803dd36c3_860d-image_thumb_3.png",324,99,[32,297,298],{},"Select Column Filters.  Here we will only show the events from my Application.  The ApplicationName can be specified on your connection string and if you provide you can use here as a filter.  As shown I have provided the Like = ODOT and also I want to exclude (checkbox) all other applications but this one.  Note; You can use wildcards with the like filters i.e. % for wildcard",[32,300,301],{},[229,302,304],{"href":303},"\u002Farticles\u002Fimages\u002Fwindows-live-writer-cdd803dd36c3_860d-image_10.png",[123,305],{"style":268,"src":306,"border":239,"alt":235,"title":235,"width":307,"height":308},"\u002Farticles\u002Fimages\u002Fwindows-live-writer-cdd803dd36c3_860d-image_thumb_4.png",319,251,[32,310,311],{},"Select ‘Ok’ and execute some SQL.  You will see in the trace ONLY your sql queries from your application.  Invaluable.  I often have profiler running while I am performing unit testing in order to see the generated sql execution.",[32,313,314],{},[229,315,317],{"href":316},"\u002Farticles\u002Fimages\u002Fwindows-live-writer-cdd803dd36c3_860d-image_12.png",[123,318],{"style":268,"src":319,"border":239,"alt":235,"title":235,"width":320,"height":321},"\u002Farticles\u002Fimages\u002Fwindows-live-writer-cdd803dd36c3_860d-image_thumb_5.png",430,77,[32,323,324,325,327,328,330,331,333],{},"Above we are showing the Duration (Amount of elapsed time (in milliseconds) taken by the event.). ",[44,326],{},"\n ",[44,329],{},"\nTip: when complete you can use File Save As to save the newly created profile as a Template, then when you want to re-use for another application it will be there and available (the only modification would be changing the application name variable in the filter).",[44,332],{},[229,334,336],{"href":335},"\u002Farticles\u002Fimages\u002Fwindows-live-writer-cdd803dd36c3_860d-image_6.png",[123,337],{"style":268,"src":338,"border":239,"alt":235,"title":235,"width":339,"height":340},"\u002Farticles\u002Fimages\u002Fwindows-live-writer-cdd803dd36c3_860d-image_thumb_2.png",322,205,[32,342,343,344],{},"Reference: ",[229,345,348],{"href":346,"target":347},"https:\u002F\u002Fmsdn.microsoft.com\u002Fen-us\u002Flibrary\u002Fms190176.aspx","_blank","SQL Server Profiler Templates MSDN",{"title":11,"searchDepth":12,"depth":12,"links":350},[],"2017-05-29T20:59:16.0698525Z",{},"\u002Farticles\u002Fsql-server-profiler-trace-for-your-application",{"title":252,"description":257},"articles\u002Fsql-server-profiler-trace-for-your-application",[18],"HTBk5k_jTh3xjo-5-NdIUQxyV-IPi6QAU0VhquYLg8g",{"id":359,"title":360,"author":28,"body":361,"createdAt":387,"description":388,"extension":15,"img":389,"meta":390,"navigation":19,"path":391,"seo":392,"stem":393,"tags":394,"updatedAt":387,"__hash__":396},"articles\u002Farticles\u002Fsql-server-2008-installation-ndash-not-so-quick.md","SQL Server 2008 Installation, not so quick",{"type":8,"value":362,"toc":385},[363,371,374,382],[32,364,365,366,370],{},"Before you rush to download SQL 2008 you may want to read the following KB article which warns that Visual Studio 2008 SP1 ‘may be required’ for SQL Server 2008 installations KB956139 (found ",[229,367,369],{"href":368,"target":347},"http:\u002F\u002Fsupport.microsoft.com\u002Fkb\u002F956139","here",")",[32,372,373],{},"”Because certain SQL Server 2008 features install components that are also part of the release version of Visual Studio 2008 SP1, SQL Server 2008 requires Visual Studio 2008 with SP1. If Visual Studio 2008 without a service pack is installed instead, it may not work correctly after you install SQL Server 2008.“",[32,375,376,377,381],{},"Currently, ",[229,378,380],{"href":379,"target":347},"http:\u002F\u002Fmsdn.microsoft.com\u002Fen-us\u002Fvstudio\u002Fcc533448.aspx","Visual Studio 2008 Service Pack 1"," (SP1) is in beta at the current time.",[32,383,384],{},"I do not know the expected delivery of SP1 but should be soon (hang tight).",{"title":11,"searchDepth":12,"depth":12,"links":386},[],"2017-05-29T20:59:15.8643544Z","Before you rush to download SQL 2008 you may want to read the following KB article contained within this blog.","\u002Farticles\u002Fimages\u002Fl2oWZnThPG.png",{},"\u002Farticles\u002Fsql-server-2008-installation-ndash-not-so-quick",{"title":360,"description":388},"articles\u002Fsql-server-2008-installation-ndash-not-so-quick",[18,395],"sql","uUgrYz6hVSOWfcqo-ApYDrtjGpXT3uL0jd9PBGOi3E8",{"id":398,"title":399,"author":28,"body":400,"createdAt":718,"description":719,"extension":15,"img":720,"meta":721,"navigation":19,"path":722,"seo":723,"stem":724,"tags":725,"updatedAt":718,"__hash__":726},"articles\u002Farticles\u002Fsql-server-triggers-to-mirror-a-table.md","SQL Server Triggers To Mirror a Table",{"type":8,"value":401,"toc":716},[402,408,472,475,702,705,713],[32,403,404,405,407],{},"I had a need to mirror any changes to one Sql Server table to another Sql Server table of a different name. Both tables had similar columns and types. In this sample my table is called Dave_Test and my mirror table was Dave_Test_Audit.",[44,406],{},"\nI will provide the create table structures in the event you want to replicate my code.",[55,409,412],{"className":410,"code":411,"language":395,"meta":11,"style":11},"language-sql shiki shiki-themes github-light github-dark","CREATE TABLE [Dave_Test]( \n    [Emp_ID] [int] IDENTITY(1,1) NOT NULL, \n    [Emp_name] [varchar](100) NULL, \n    [Emp_Sal] [decimal](10, 2) NULL ) ON [PRIMARY]  \n   \nCREATE TABLE [Dave_Test_Audit](\n    [Emp_ID] [int] NULL,\n    [Emp_name] [varchar](100) NULL,\n    [Emp_Sal] [decimal](18, 0) NULL\n) ON [PRIMARY]  \nGO  \n",[61,413,414,419,424,429,434,439,444,449,454,460,466],{"__ignoreMap":11},[64,415,416],{"class":66,"line":67},[64,417,418],{},"CREATE TABLE [Dave_Test]( \n",[64,420,421],{"class":66,"line":12},[64,422,423],{},"    [Emp_ID] [int] IDENTITY(1,1) NOT NULL, \n",[64,425,426],{"class":66,"line":86},[64,427,428],{},"    [Emp_name] [varchar](100) NULL, \n",[64,430,431],{"class":66,"line":92},[64,432,433],{},"    [Emp_Sal] [decimal](10, 2) NULL ) ON [PRIMARY]  \n",[64,435,436],{"class":66,"line":98},[64,437,438],{},"   \n",[64,440,441],{"class":66,"line":104},[64,442,443],{},"CREATE TABLE [Dave_Test_Audit](\n",[64,445,446],{"class":66,"line":110},[64,447,448],{},"    [Emp_ID] [int] NULL,\n",[64,450,451],{"class":66,"line":116},[64,452,453],{},"    [Emp_name] [varchar](100) NULL,\n",[64,455,457],{"class":66,"line":456},9,[64,458,459],{},"    [Emp_Sal] [decimal](18, 0) NULL\n",[64,461,463],{"class":66,"line":462},10,[64,464,465],{},") ON [PRIMARY]  \n",[64,467,469],{"class":66,"line":468},11,[64,470,471],{},"GO\n",[32,473,474],{},"Here are my insert, update and delete triggers.",[55,476,478],{"className":410,"code":477,"language":395,"meta":11,"style":11},"Create TRIGGER [Dave_Test_Trigger_Delete]   \n   ON  [Dave_Test]   \n   AFTER DELETE  \nAS  \nBEGIN  \n     SET NOCOUNT ON;  \n     DELETE FROM Dave_Test_Audit   \n            WHERE emp_id IN (SELECT emp_id FROM deleted)  \nEND  \n  \nCreate TRIGGER [Dave_Test_Trigger_Insert]   \n   ON  [Dave_Test]   \n   AFTER INSERT  \nAS  \nBEGIN     SET NOCOUNT ON;  \n        INSERT INTO Dave_Test_Audit   \n         SELECT * FROM inserted END  \nEND  \n  \nCREATE TRIGGER [[Dave_Test_Trigger_Update]   \n   ON  [Dave_Test]   \n   AFTER UPDATE  \nAS  \nBEGIN  \n        SET NOCOUNT ON;  \n        IF EXISTS(SELECT * FROM Dave_Test_Audit a JOIN inserted AS i ON a.emp_id=i.emp_id)          \n        BEGIN  \n              UPDATE  Dave_Test_Audit   \n                SET emp_id = i.emp_id,  \n                emp_name = i.emp_name,  \n                emp_sal =  i.emp_sal  \n                FROM inserted i WHERE Dave_Test_Audit.emp_id=i.emp_id           \n              \n        END  \n        ELSE  \n             BEGIN  \n             INSERT INTO Dave_Test_Audit   \n                SELECT * FROM inserted   \n        END        \nEND\n",[61,479,480,485,490,495,500,505,510,515,520,525,530,535,540,546,551,557,563,569,574,579,585,590,596,601,606,612,618,624,630,636,642,648,654,660,666,672,678,684,690,696],{"__ignoreMap":11},[64,481,482],{"class":66,"line":67},[64,483,484],{},"Create TRIGGER [Dave_Test_Trigger_Delete]   \n",[64,486,487],{"class":66,"line":12},[64,488,489],{},"   ON  [Dave_Test]   \n",[64,491,492],{"class":66,"line":86},[64,493,494],{},"   AFTER DELETE  \n",[64,496,497],{"class":66,"line":92},[64,498,499],{},"AS  \n",[64,501,502],{"class":66,"line":98},[64,503,504],{},"BEGIN  \n",[64,506,507],{"class":66,"line":104},[64,508,509],{},"     SET NOCOUNT ON;  \n",[64,511,512],{"class":66,"line":110},[64,513,514],{},"     DELETE FROM Dave_Test_Audit   \n",[64,516,517],{"class":66,"line":116},[64,518,519],{},"            WHERE emp_id IN (SELECT emp_id FROM deleted)  \n",[64,521,522],{"class":66,"line":456},[64,523,524],{},"END  \n",[64,526,527],{"class":66,"line":462},[64,528,529],{},"  \n",[64,531,532],{"class":66,"line":468},[64,533,534],{},"Create TRIGGER [Dave_Test_Trigger_Insert]   \n",[64,536,538],{"class":66,"line":537},12,[64,539,489],{},[64,541,543],{"class":66,"line":542},13,[64,544,545],{},"   AFTER INSERT  \n",[64,547,549],{"class":66,"line":548},14,[64,550,499],{},[64,552,554],{"class":66,"line":553},15,[64,555,556],{},"BEGIN     SET NOCOUNT ON;  \n",[64,558,560],{"class":66,"line":559},16,[64,561,562],{},"        INSERT INTO Dave_Test_Audit   \n",[64,564,566],{"class":66,"line":565},17,[64,567,568],{},"         SELECT * FROM inserted END  \n",[64,570,572],{"class":66,"line":571},18,[64,573,524],{},[64,575,577],{"class":66,"line":576},19,[64,578,529],{},[64,580,582],{"class":66,"line":581},20,[64,583,584],{},"CREATE TRIGGER [[Dave_Test_Trigger_Update]   \n",[64,586,588],{"class":66,"line":587},21,[64,589,489],{},[64,591,593],{"class":66,"line":592},22,[64,594,595],{},"   AFTER UPDATE  \n",[64,597,599],{"class":66,"line":598},23,[64,600,499],{},[64,602,604],{"class":66,"line":603},24,[64,605,504],{},[64,607,609],{"class":66,"line":608},25,[64,610,611],{},"        SET NOCOUNT ON;  \n",[64,613,615],{"class":66,"line":614},26,[64,616,617],{},"        IF EXISTS(SELECT * FROM Dave_Test_Audit a JOIN inserted AS i ON a.emp_id=i.emp_id)          \n",[64,619,621],{"class":66,"line":620},27,[64,622,623],{},"        BEGIN  \n",[64,625,627],{"class":66,"line":626},28,[64,628,629],{},"              UPDATE  Dave_Test_Audit   \n",[64,631,633],{"class":66,"line":632},29,[64,634,635],{},"                SET emp_id = i.emp_id,  \n",[64,637,639],{"class":66,"line":638},30,[64,640,641],{},"                emp_name = i.emp_name,  \n",[64,643,645],{"class":66,"line":644},31,[64,646,647],{},"                emp_sal =  i.emp_sal  \n",[64,649,651],{"class":66,"line":650},32,[64,652,653],{},"                FROM inserted i WHERE Dave_Test_Audit.emp_id=i.emp_id           \n",[64,655,657],{"class":66,"line":656},33,[64,658,659],{},"              \n",[64,661,663],{"class":66,"line":662},34,[64,664,665],{},"        END  \n",[64,667,669],{"class":66,"line":668},35,[64,670,671],{},"        ELSE  \n",[64,673,675],{"class":66,"line":674},36,[64,676,677],{},"             BEGIN  \n",[64,679,681],{"class":66,"line":680},37,[64,682,683],{},"             INSERT INTO Dave_Test_Audit   \n",[64,685,687],{"class":66,"line":686},38,[64,688,689],{},"                SELECT * FROM inserted   \n",[64,691,693],{"class":66,"line":692},39,[64,694,695],{},"        END        \n",[64,697,699],{"class":66,"line":698},40,[64,700,701],{},"END\n",[32,703,704],{},"So why does my Update trigger deal with inserts?  The master table (Dave_Test) already had rows existing before the triggers were created.  With the update trigger managing inserting and updating records if the record is updated and does yet belong in the master audit table then the recently updated row will be inserted into the audit table for us.",[32,706,707,708,712],{},"For those old enough – this is ",[229,709,711],{"href":710,"target":347},"http:\u002F\u002Fwww.happytrails.org\u002Ftrigger.html","Trigger"," (the smartest horse in the movies)",[152,714,715],{},"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":11,"searchDepth":12,"depth":12,"links":717},[],"2016-02-13T07:02:53.5100000-05:00","I had a need to mirror any changes to one Sql Server table to another Sql Server table of a different name.  Read on.","\u002Farticles\u002Fimages\u002FXp0SJTsB7n.png",{},"\u002Farticles\u002Fsql-server-triggers-to-mirror-a-table",{"title":399,"description":719},"articles\u002Fsql-server-triggers-to-mirror-a-table",[395,18],"oG-qazOpjUVf0yb-VL3IN5WX57TFCezPsA53rRrA00k",{"id":728,"title":729,"author":28,"body":730,"createdAt":811,"description":812,"extension":15,"img":806,"meta":813,"navigation":19,"path":814,"seo":815,"stem":816,"tags":817,"updatedAt":811,"__hash__":818},"articles\u002Farticles\u002Fvarchar-vs-nvarchar.md","Varchar vs NVarchar",{"type":8,"value":731,"toc":809},[732,749,758,780],[32,733,734,735,737,738,741,742,745,746,748],{},"So let’s talk about this to better understand some differences and benefits of using each of these data types.",[44,736],{},"\nNVarchar – the ‘N’ in varchar means u",[36,739,740],{},"N","icode",[36,743,744],{},".  ","The column can store any Unicode data.  The column is a varchar that supports two-byte\ncharacters.  The most common use for this sort of thing is to store character data that is a mixture of English and non-English symbols.",[44,747],{},"\nVarchar – is an abbreviation for variable-length character string. ",[32,750,751,752,754,757],{},"It’s a string of text characters that can be as large as the page size for the database table holding the column.  The size for a table page is 8,196 bytes, and no one\nrow in a table can be more than 8060 characters.  This in turn limits the maximum size of a varchar to 8000 bytes.",[44,753],{},[36,755,756],{},"So we used the term unicode data",".  What does this mean?  Computers store letters and other characters by assigning a number for each one. ",[32,759,760,761,764,765,767,770,771,773,776,777,779],{},"Before unicode was invented there were hundreds of different encoding systems for assigning these numbers. No single encoding could contain enough characters: for example,\nthe European Union alone requires several different encodings to cover all its languages. Even for a single language like English no single encoding was adequate for all the\nletters, punctuation, and technical symbols in common use. These encoding systems also conflict with another, for instance two encodings could use the same number for two\ndifferent characters. ",[36,762,763],{},"Unicode ","to the rescue.  Unicode provides a unique number for every character, no matter what the platform, no matter what the program,\nno matter what the language.  The unicode standard has widespread adoption across systems, platforms, languages etc.  It solves most of the encoding issues.",[44,766],{},[36,768,769],{},"The primary difference between these two column types is how they are stored.","  Varchar is stored as 8-bit data.  Nvarchar strings are stored in the\ndatabase as UTF-16, 16 bits or two bytes per character, and converted on output (typically UTF-8).  That said, Nvarchar strings have the same length restrictions as varchar\n8000 bytes.  Since Nvarchar use two bytes instead of one nvarchar can only hold 4000 characters maximum.",[44,772],{},[36,774,775],{},"What is UTF-8 and UTF-16?","   UTF stands for Unicode Transformation Format.  It is a family of standards for encoding the Unicode character set into\nits equivalent binary value.  UTF was developed so that users have a standardized means of encoding the characters with the minimal amount of space.UTF-8 and UTF 16 are\nonly two of the established standards for encoding.  The main advantage of UTF-8 is that it is backwards compatible with ASCII. The ASCII character set is fixed width and\nonly uses one byte.  When encoding a file that uses only ASCII characters with UTF-8, the resulting file would be identical to a file encoded with ASCII. This is not\npossible when using UTF-16 as each character would be two bytes long.",[44,778],{},"\nOkay, we have covered a few technical topics here. ",[32,781,782,783,786,787,790,791,793,794,797,798,800],{},"So in the end you can store more string data in a varchar than nvarchar fields, however if you are working with multiple cultures, languages etc.\nyou will ",[36,784,785],{},"NEED ","to store those character sets in fields that are of type ",[36,788,789],{},"NVARCHAR",".  Due to the widespread usage of web applications\naround the globe I believe you will rarely go wrong by selecting\u002Fusing nvarchar over varchar. If you are concerned about storage space you can use a combination of field\ntypes (using nvarchar for user-entered data and varchar for system generated) but this may just add complexity and one day just be a limitation\u002Fhurdle you will need to\novercome in the future when globalizing your application.",[44,792],{},"\nJust use ",[36,795,796],{},"nvarchar"," and you will be safe.",[44,799],{},[229,801,803],{"href":802},"\u002Farticles\u002Fimages\u002Fwindows-live-writer-varchar-vs-nvarchar_11973-choice2_4.png",[123,804],{"style":805,"src":806,"border":239,"alt":807,"title":807,"width":270,"height":808},"background-image: none; padding-top: 0px; padding-left: 0px; \ndisplay: inline; padding-right: 0px; border: 0px;","\u002Farticles\u002Fimages\u002Fwindows-live-writer-varchar-vs-nvarchar_11973-choice2_thumb_1.png","choice2",143,{"title":11,"searchDepth":12,"depth":12,"links":810},[],"2015-06-26T09:36:26.9300000-04:00","Let’s talk about this to better understand some differences and benefits of using each.",{},"\u002Farticles\u002Fvarchar-vs-nvarchar",{"title":729,"description":812},"articles\u002Fvarchar-vs-nvarchar",[18],"SXeJ9MvXofV764d8HuiIQXhx1ejjfpqsDzHGIdBnfls",{"id":820,"title":821,"author":28,"body":822,"createdAt":870,"description":170,"extension":15,"img":170,"meta":871,"navigation":19,"path":872,"seo":873,"stem":874,"tags":875,"updatedAt":870,"__hash__":876},"articles\u002Farticles\u002Fsql-templates-in-sql-server-management-studio.md","SQL Templates (in SQL Server Management Studio)",{"type":8,"value":823,"toc":868},[824,842,856],[32,825,826,827,831,832,836,837,839],{},"Credit goes to the ",[229,828,830],{"target":347,"href":829},"http:\u002F\u002Fcincysql.org\u002Fdefault.aspx","Cincinnati SQL Server User’s Group","\u002F",[229,833,835],{"target":347,"href":834},"http:\u002F\u002Fjapikse.blogspot.com","Phil Japikse"," for the following tip.  Two things of interest in this post.  Ability to create Sql Templates within SQL Server Management Studio and SQL to find objects named like ‘%here%’ across all objects in a database.",[44,838],{},[840,841],"em",{},[840,843,844,847,850,853],{},[32,845,846],{},"USE \u003Cdatabasename,string,@p1>",[32,848,849],{},"GO",[32,851,852],{},"SELECT OBJECT_NAME(OBJECT_ID)",[32,854,855],{},"FROM sys.sql_modules",[32,857,858,861,862,864,865,867],{},[840,859,860],{},"WHERE definition like '%\u003Cstring_to_find,string,@p2>%'"," ",[44,863],{},"\nNow that you have the SQL it is possible to create a SQL Template (View – SQL Templates) whereby you can simply select and push Ctrl-Shift-M for variable substitution.  Within the Template Window create a new folder to store your custom templates, create a new template, paste the above SQL and Save.  To use simply click on the template and Ctrl-Shift-M to be prompted for the variables and values.",[44,866],{},"\nGreat stuff.  Thanks guys for the tip.",{"title":11,"searchDepth":12,"depth":12,"links":869},[],"2015-04-20T08:07:20.1800000-04:00",{},"\u002Farticles\u002Fsql-templates-in-sql-server-management-studio",{"title":821,"description":170},"articles\u002Fsql-templates-in-sql-server-management-studio",[18],"xLkaxTvrpsg5-vSPzWpJsrPkpM6cQ_XYQ7P2nrTpJS8",{"id":878,"title":879,"author":28,"body":880,"createdAt":928,"description":170,"extension":15,"img":918,"meta":929,"navigation":19,"path":930,"seo":931,"stem":932,"tags":933,"updatedAt":928,"__hash__":934},"articles\u002Farticles\u002Fssms-tools-pack.md","SSMS Tools Pack",{"type":8,"value":881,"toc":926},[882,885,888,891,894,897,900,903,906,909,920],[32,883,884],{},"This is a free (please donate) SQL Server Management Studio add-on that is small, easy to install and is packed with some great features.",[32,886,887],{},"Query Execution History – every sql statement that you run is automatically logged and available at a later time",[32,889,890],{},"Search Database Data – search through all non-binary columns in every table of the database for a search term.",[32,892,893],{},"Uppercase\u002FLowercase Keywords",[32,895,896],{},"Run one Script on multiple databases",[32,898,899],{},"Copy execution plan bitmaps to clipboard",[32,901,902],{},"Generate Insert statements for a single table, the whole database or current result sets",[32,904,905],{},"Create, Read, Update and Delete stored procedure generation",[32,907,908],{},"plus more!",[32,910,911],{},[229,912,914],{"href":913},"\u002Farticles\u002Fimages\u002Fimage_2.png",[123,915],{"title":235,"style":916,"height":917,"alt":235,"src":918,"width":919,"border":239},"border-right: 0px; border-top: 0px; display: inline; border-left: 0px; border-bottom: 0px",114,"\u002Farticles\u002Fimages\u002Fimage_thumb.png",244,[32,921,922,923],{},"Check it out ",[229,924,879],{"href":925,"target":347},"http:\u002F\u002Fwww.ssmstoolspack.com\u002FFeatures.aspx",{"title":11,"searchDepth":12,"depth":12,"links":927},[],"2015-04-20T08:07:18.7000000-04:00",{},"\u002Farticles\u002Fssms-tools-pack",{"title":879,"description":170},"articles\u002Fssms-tools-pack",[18],"B5bcM4AVCzbinRhCXW3lHv8jMYWeSI5bqFkI5LF3sBM",{"id":936,"title":937,"author":28,"body":938,"createdAt":1012,"description":1013,"extension":15,"img":170,"meta":1014,"navigation":19,"path":1015,"seo":1016,"stem":1017,"tags":1018,"updatedAt":1012,"__hash__":1019},"articles\u002Farticles\u002Fsql-execution-enterprise-manager-qa-vs-net-execution.md","SQL Execution (Enterprise Manager-QA) VS. .NET Execution",{"type":8,"value":939,"toc":1010},[940,962,984],[32,941,942,943,945,946,948,949,951,952,954,955,957,958,961],{},"I have been chasing an issue for quite a while where the query would timeout when executed from an ASP.NET interface.  If I ran that exact same query through Query Analyzer the results would be returned in less than 2 seconds.    I have for a while been struggling with why it is different between those two interfaces.  I thought about connection pooling issues, command time outs and connection timeouts and was focused on that for a while.  Even after extending those values from the default the query would still time out.  It was often I would see an exception similar to   ---------------------------  SQL Exception Information:",[44,944],{},"\nErrorId: -2",[44,947],{},"\nMessage: Timeout expired. The timeout period elapsed prior to completion of the operation or the server is not responding.",[44,950],{},"\nLine Number: 0",[44,953],{},"\nProcedure:",[44,956],{},"\n---------------------------  To put this post in the proper context think about one of your application search stored procedures.  The interface shows a dozen or more optional textboxes for user entry to narrow down the results.  The stored procedure in this case often has many parameters that could be used with the actual query.  This is the case for the query that I am discussing herein.  When you execute a stored procedure for the first time the query processor constructs a query plan based on the the state of the statistics and the input parameters.  So, the query plan is created upon first execution and is cached in case some other invocation of the same stored procedure comes along before the cache is cleared.  So, when executing through the web interface SQL Server is using the same execution plan that was created by the prior user.  This can look significantly different between users and what parameters they provide before they run the search.  So, to have SQL Server generate a new query plan upon each execution the \"",[36,959,960],{},"WITH RECOMPILE","\" can be used.  By adding this parameter SQL Server regardless of the parameters passed in it will create a new optimal plan.  ",[963,964,965,966,968,969,971,972,974,975,977,978,980,981],"blockquote",{},"   i.e.",[44,967],{},"\nCreate Procedure dbo.GetCustomers",[44,970],{},"\n            @LastName varchar(200),",[44,973],{},"\n            @FirstName varchar(200),",[44,976],{},"\n            .... \nWITH RECOMPILE AS",[44,979],{},"\n  BEGIN",[32,982,983],{},"  END ",[963,985,986,987,968,989,971,991,974,993,995,996,980,998,1000,1001,1003,1004,1006,1007,1009],{},"   i.e. SQL 2005 option",[44,988],{},[44,990],{},[44,992],{},[44,994],{},"\n            .... \nAS",[44,997],{},[44,999],{},"\n      Query 1",[44,1002],{},"\n      Query 2 OPTION(RECOMPILE)",[44,1005],{},"\n      Query 3 OPTION(RECOMPILE)",[44,1008],{},"\n      Query 4 \n  END ",{"title":11,"searchDepth":12,"depth":12,"links":1011},[],"2015-04-20T08:07:18.1100000-04:00","I have been chasing an issue for quite a while where the query would timeout when executed from an ASP.NET interface.  If I ran that exact same query through Query Analyzer the results would be returned in less than 2 seconds.    I have for a while been struggling with why it is different between those two interfaces.  I thought about connection pooling issues, command time outs and connection timeouts and was focused on that for a while.  Even after extending those values from the default the query would still time out.  It was often I would see an exception similar to   ---------------------------  SQL Exception Information:\nErrorId: -2\nMessage: Timeout expired. The timeout period elapsed prior to completion of the operation or the server is not responding.\nLine Number: 0\nProcedure:\n---------------------------  To put this post in the proper context think about one of your application search stored procedures.  The interface shows a dozen or more optional textboxes for user entry to narrow down the results.  The stored procedure in this case often has many parameters that could be used with the actual query.  This is the case for the query that I am discussing herein.  When you execute a stored procedure for the first time the query processor constructs a query plan based on the the state of the statistics and the input parameters.  So, the query plan is created upon first execution and is cached in case some other invocation of the same stored procedure comes along before the cache is cleared.  So, when executing through the web interface SQL Server is using the same execution plan that was created by the prior user.  This can look significantly different between users and what parameters they provide before they run the search.  So, to have SQL Server generate a new query plan upon each execution the \"WITH RECOMPILE\" can be used.  By adding this parameter SQL Server regardless of the parameters passed in it will create a new optimal plan.  ",{},"\u002Farticles\u002Fsql-execution-enterprise-manager-qa-vs-net-execution",{"title":937,"description":1013},"articles\u002Fsql-execution-enterprise-manager-qa-vs-net-execution",[18],"B2ug2YjmetZNfsPVc-Gc3dmawycSNaf-YqYAdz1IpqQ",{"id":1021,"title":1022,"author":28,"body":1023,"createdAt":1165,"description":1166,"extension":15,"img":170,"meta":1167,"navigation":19,"path":1168,"seo":1169,"stem":1170,"tags":1171,"updatedAt":1165,"__hash__":1172},"articles\u002Farticles\u002Fsql-server-ndash-find-field-value-in-database.md","SQL Server Find Field Value in Database",{"type":8,"value":1024,"toc":1163},[1025,1028,1031,1161],[32,1026,1027],{},"The following is a SQL Script that can be run in a database to return all tables and columns where a particular value is present. \nThis can be used for strings or values with a small modification.  This type of thing is great when moving applications\u002Fproducts between servers. ",[32,1029,1030],{},"This is certainly a good script to include in your master table to be used over and over.",[55,1032,1034],{"className":410,"code":1033,"language":395,"meta":11,"style":11},"DECLARE @value VARCHAR(64)\nDECLARE @sql VARCHAR(1024)\nDECLARE @table VARCHAR(64)\nDECLARE @column VARCHAR(64)\nSET @value = 'valuehere'\nCREATE TABLE #t (\n    tablename VARCHAR(64),\n    columnname VARCHAR(64)\n)\nDECLARE TABLES CURSOR FOR \nSELECT o.name, c.name FROM syscolumns c \nINNER JOIN sysobjects o ON c.id = o.id \nWHERE o.type = 'U' AND c.xtype IN (167, 175, 231, 239)\nORDER BY o.name, c.name\nOPEN TABLES\nFETCH NEXT FROM TABLES\nINTO @table, @column WHILE @@FETCH_STATUS = 0 BEGIN SET @sql = 'IF EXISTS(SELECT NULL FROM [' + @table + '] '  \n--SET @sql = @sql + 'WHERE RTRIM(LTRIM([' + @column + '])) = ''' + @value + ''') \n'SET @sql = @sql + 'WHERE RTRIM(LTRIM([' + @column + '])) LIKE ''%' + @value + '%'') \n'SET @sql = @sql + 'INSERT INTO #t VALUES (''' + @table + ''', '''\nSET @sql = @sql + @column + ''')'\nEXEC(@sql)\nFETCH NEXT FROM TABLES INTO @table, @column END CLOSE TABLES DEALLOCATE TABLES SELECT * \nFROM #t \nDROP TABLE #t \n",[61,1035,1036,1041,1046,1051,1056,1061,1066,1071,1076,1081,1086,1091,1096,1101,1106,1111,1116,1121,1126,1131,1136,1141,1146,1151,1156],{"__ignoreMap":11},[64,1037,1038],{"class":66,"line":67},[64,1039,1040],{},"DECLARE @value VARCHAR(64)\n",[64,1042,1043],{"class":66,"line":12},[64,1044,1045],{},"DECLARE @sql VARCHAR(1024)\n",[64,1047,1048],{"class":66,"line":86},[64,1049,1050],{},"DECLARE @table VARCHAR(64)\n",[64,1052,1053],{"class":66,"line":92},[64,1054,1055],{},"DECLARE @column VARCHAR(64)\n",[64,1057,1058],{"class":66,"line":98},[64,1059,1060],{},"SET @value = 'valuehere'\n",[64,1062,1063],{"class":66,"line":104},[64,1064,1065],{},"CREATE TABLE #t (\n",[64,1067,1068],{"class":66,"line":110},[64,1069,1070],{},"    tablename VARCHAR(64),\n",[64,1072,1073],{"class":66,"line":116},[64,1074,1075],{},"    columnname VARCHAR(64)\n",[64,1077,1078],{"class":66,"line":456},[64,1079,1080],{},")\n",[64,1082,1083],{"class":66,"line":462},[64,1084,1085],{},"DECLARE TABLES CURSOR FOR \n",[64,1087,1088],{"class":66,"line":468},[64,1089,1090],{},"SELECT o.name, c.name FROM syscolumns c \n",[64,1092,1093],{"class":66,"line":537},[64,1094,1095],{},"INNER JOIN sysobjects o ON c.id = o.id \n",[64,1097,1098],{"class":66,"line":542},[64,1099,1100],{},"WHERE o.type = 'U' AND c.xtype IN (167, 175, 231, 239)\n",[64,1102,1103],{"class":66,"line":548},[64,1104,1105],{},"ORDER BY o.name, c.name\n",[64,1107,1108],{"class":66,"line":553},[64,1109,1110],{},"OPEN TABLES\n",[64,1112,1113],{"class":66,"line":559},[64,1114,1115],{},"FETCH NEXT FROM TABLES\n",[64,1117,1118],{"class":66,"line":565},[64,1119,1120],{},"INTO @table, @column WHILE @@FETCH_STATUS = 0 BEGIN SET @sql = 'IF EXISTS(SELECT NULL FROM [' + @table + '] '  \n",[64,1122,1123],{"class":66,"line":571},[64,1124,1125],{},"--SET @sql = @sql + 'WHERE RTRIM(LTRIM([' + @column + '])) = ''' + @value + ''') \n",[64,1127,1128],{"class":66,"line":576},[64,1129,1130],{},"'SET @sql = @sql + 'WHERE RTRIM(LTRIM([' + @column + '])) LIKE ''%' + @value + '%'') \n",[64,1132,1133],{"class":66,"line":581},[64,1134,1135],{},"'SET @sql = @sql + 'INSERT INTO #t VALUES (''' + @table + ''', '''\n",[64,1137,1138],{"class":66,"line":587},[64,1139,1140],{},"SET @sql = @sql + @column + ''')'\n",[64,1142,1143],{"class":66,"line":592},[64,1144,1145],{},"EXEC(@sql)\n",[64,1147,1148],{"class":66,"line":598},[64,1149,1150],{},"FETCH NEXT FROM TABLES INTO @table, @column END CLOSE TABLES DEALLOCATE TABLES SELECT * \n",[64,1152,1153],{"class":66,"line":603},[64,1154,1155],{},"FROM #t \n",[64,1157,1158],{"class":66,"line":608},[64,1159,1160],{},"DROP TABLE #t\n",[152,1162,715],{},{"title":11,"searchDepth":12,"depth":12,"links":1164},[],"2015-04-20T08:07:17.3700000-04:00","SQL Script that can be run in a database to return all tables and columns where...",{},"\u002Farticles\u002Fsql-server-ndash-find-field-value-in-database",{"title":1022,"description":1166},"articles\u002Fsql-server-ndash-find-field-value-in-database",[18],"9WL54maowA8aY8EDRpBT04V-F_6eINuHpi58uWVJ_i8",{"id":1174,"title":1175,"author":28,"body":1176,"createdAt":1205,"description":1206,"extension":15,"img":170,"meta":1207,"navigation":19,"path":1208,"seo":1209,"stem":1210,"tags":1211,"updatedAt":1205,"__hash__":1212},"articles\u002Farticles\u002Fsql-server-find-sql-object-names-within-a-database.md","SQL Server Find SQL Object Names within a Database",{"type":8,"value":1177,"toc":1203},[1178,1181,1201],[32,1179,1180],{},"I was returning to an old database, and I wanted to find all instances of a particular column name.  The following SQL is a very fast way to output the object name (with additional data) for locating the item of interest.  Of course you can make more elaborate by filtering query.",[55,1182,1184],{"className":410,"code":1183,"language":395,"meta":11,"style":11},"SELECT sc.[name] AS column_name, so.[name] , \n    FROM syscolumns sc INNER JOIN sysobjects so ON sc.id=so.id \n    WHERE sc.[name] LIKE '%TestColumnName%'\n",[61,1185,1186,1191,1196],{"__ignoreMap":11},[64,1187,1188],{"class":66,"line":67},[64,1189,1190],{},"SELECT sc.[name] AS column_name, so.[name] , \n",[64,1192,1193],{"class":66,"line":12},[64,1194,1195],{},"    FROM syscolumns sc INNER JOIN sysobjects so ON sc.id=so.id \n",[64,1197,1198],{"class":66,"line":86},[64,1199,1200],{},"    WHERE sc.[name] LIKE '%TestColumnName%'\n",[152,1202,715],{},{"title":11,"searchDepth":12,"depth":12,"links":1204},[],"2015-04-20T08:07:17.2600000-04:00","Find SQL Object Names within a database.",{},"\u002Farticles\u002Fsql-server-find-sql-object-names-within-a-database",{"title":1175,"description":1206},"articles\u002Fsql-server-find-sql-object-names-within-a-database",[18],"QEpNxETpmOeE4y_rIm0Sg2CxcqEoanKMzug024sdRHg",{"id":1214,"title":1215,"author":28,"body":1216,"createdAt":1244,"description":170,"extension":15,"img":170,"meta":1245,"navigation":19,"path":1246,"seo":1247,"stem":1248,"tags":1249,"updatedAt":1244,"__hash__":1250},"articles\u002Farticles\u002Fcannot-resolve-collation-conflict.md","Cannot Resolve Collation Conflict",{"type":8,"value":1217,"toc":1242},[1218,1221,1224,1227,1230,1236,1239],[32,1219,1220],{},"“Cannot resolve collation conflict for equal to operation” – huh?",[32,1222,1223],{},"When joining fields in different collated databases you can see the above error message. ",[32,1225,1226],{},"In my particular case I had two databases with different collations and I was doing a join across the databases on the fields.",[32,1228,1229],{},"The resolution was to add the keywords",[32,1231,1232,1233,1235],{},"“COLLATE DATABASE_DEFAULT” near the equal ‘=’ signs.  For example:                          SELECT p1.BEEF_1 FROM dbo.PHEN p1 INNER JOIN \nDatabase2.dbo.PHEN p2 ON p1.BEEF_1 COLLATE DATABASE_DEFAULT =p2.BEEF_1 COLLATE DATABASE_DEFAULT AND",[44,1234],{},"\np1.BEEF_2 COLLATE DATABASE_DEFAULT=p2.BEEF_2 COLLATE DATABASE_DEFAULT            Collation can affect where clauses, join predicates, functions and databases.",[32,1237,1238],{},"More about Collation  A Collation encodes the rules governing the proper use of characters for either a language,\nsuch as Greek or Polish or an alphabet such as Latin1_General (the Latin alphabet used by western European languages).",[32,1240,1241],{},"Each SQL Server collation specifies three properties: sort order for Unicode data types (nchar, nvarchar, ntext), the sort order for non-Unicode character types\n(char, varchar and text) and finally the code page used to store non-Unicode character data.  A SQL Server collation defines how the database engine stores and\noperates on character and Unicode data.",{"title":11,"searchDepth":12,"depth":12,"links":1243},[],"2015-04-20T08:07:16.9200000-04:00",{},"\u002Farticles\u002Fcannot-resolve-collation-conflict",{"title":1215,"description":170},"articles\u002Fcannot-resolve-collation-conflict",[18],"18hrmGHKYf7WtDSCubhBbJSReXrd9i7CyaWJs-LwY0Q",{"id":1252,"title":1253,"author":28,"body":1254,"createdAt":1362,"description":1363,"extension":15,"img":170,"meta":1364,"navigation":19,"path":1365,"seo":1366,"stem":1367,"tags":1368,"updatedAt":1362,"__hash__":1369},"articles\u002Farticles\u002Fsql-server-comparing-tables-merge-except-intersect.md","SQL Server Comparing Tables",{"type":8,"value":1255,"toc":1360},[1256,1259,1291,1302,1313,1316,1322,1325,1355,1358],[32,1257,1258],{},"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: ",[1260,1261,1263,1264,1268,1269,1272,1273,1275,1276,1279,1280,1282,1283,1286,1287,1290],"div",{"style":1262},"font-size: 9pt; background: white; color: black; font-family: consolas","\n        ",[64,1265,1267],{"style":1266},"color: blue","Dim"," data1 DataSet = ",[64,1270,1271],{"style":1266},"GetData1()","          ",[64,1274,1267],{"style":1266}," data2 DataSet = ",[64,1277,1278],{"style":1266},"GetData2()","            ",[64,1281,1267],{"style":1266}," ds ",[64,1284,1285],{"style":1266},"As"," ",[64,1288,1289],{"style":1266},"New"," DataSet         ds.Merge(data1)         ds.AcceptChanges()         ds.Merge(data2)         ds.GetChanges(DataRowState.Modified)",[32,1292,1293,1294,1297,1301],{},"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 (",[229,1295],{"title":1296,"href":1296},"http:\u002F\u002Fmsdn.microsoft.com\u002Fen-us\u002Flibrary\u002Fms188055(SQL.90).aspx",[229,1298,1296],{"href":1296,"rel":1299},[1300],"nofollow",") that return distinct values by comparing the results of two queries.  The entire row is compared against another row from another table.",[32,1303,1304,1305,1308,1309,1312],{},"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 ",[36,1306,1307],{},"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 ",[36,1310,1311],{},"except"," select * from table2",[32,1314,1315],{},"(likewise to find the opposite just reverse the table names above)",[32,1317,1318,1319,1312],{},"To return all rows in table1 that match exactly what is in table2, using Intersect...\nselect * from table1 ",[36,1320,1321],{},"intersect",[32,1323,1324],{},"Combining the above two... (the following will return the differences)",[55,1326,1328],{"className":410,"code":1327,"language":395,"meta":11,"style":11},"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",[61,1329,1330,1335,1340,1345,1350],{"__ignoreMap":11},[64,1331,1332],{"class":66,"line":67},[64,1333,1334],{},"select 'table1' as tblName, *  from\n",[64,1336,1337],{"class":66,"line":12},[64,1338,1339],{},"  (select * from Table1 except select * from Table2) x\n",[64,1341,1342],{"class":66,"line":86},[64,1343,1344],{},"union all\n",[64,1346,1347],{"class":66,"line":92},[64,1348,1349],{},"select 'table2' as tblName, *  from\n",[64,1351,1352],{"class":66,"line":98},[64,1353,1354],{},"  (select * from Table2 except select *  from Table1 ) x\n",[32,1356,1357],{},"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.",[152,1359,715],{},{"title":11,"searchDepth":12,"depth":12,"links":1361},[],"2015-04-20T08:07:16.8200000-04:00","Learn how to compare two SQL Server tables",{},"\u002Farticles\u002Fsql-server-comparing-tables-merge-except-intersect",{"title":1253,"description":1363},"articles\u002Fsql-server-comparing-tables-merge-except-intersect",[18],"a3XLSKncpyYY6AaLiNGJj9hTlH1eTB877PjeGfHig8M",{"id":1371,"title":1372,"author":28,"body":1373,"createdAt":1544,"description":170,"extension":15,"img":1540,"meta":1545,"navigation":19,"path":1546,"seo":1547,"stem":1548,"tags":1549,"updatedAt":1544,"__hash__":1550},"articles\u002Farticles\u002Flist-indexes-in-sql-server.md","List Indexes in SQL Server",{"type":8,"value":1374,"toc":1542},[1375,1386,1530,1534,1536,1538],[32,1376,1377,1378,1381,1382,1385],{},"The following SQL will list all indexes in within the database that you run the sql script.  I was looking for the option within Visual Studio - Data Dude add-on that displayed index differences between two databases.  I eventually discovered the line by line index comparison by exploding the Table-Indexes ",[36,1379,1380],{},"however"," I was unable to create the newly added script index in the 2nd database.  ",[36,1383,1384],{},"Is this possible? ","  In lieu of the shortcomings within Data-Dude I used the following script to manually compare and script the indexes in both databases.",[55,1387,1390,1395,1396,1400,1401,1403,1407,1409,1413,1414,1416,1420,1421,1423,1427,1428,1433,1435,1439,1440,1444,1445,1458,1518],{"className":1388},[1389],"csharpcode",[64,1391,1394],{"className":1392},[1393],"kwrd","DECLARE"," GetTables ",[64,1397,1399],{"className":1398},[1393],"CURSOR"," READ_ONLY",[44,1402],{},[64,1404,1406],{"className":1405},[1393],"FOR",[44,1408],{},[64,1410,1412],{"className":1411},[1393],"  SELECT"," TABLE_NAME",[44,1415],{},[64,1417,1419],{"className":1418},[1393],"  FROM"," INFORMATION_SCHEMA.TABLES",[44,1422],{},[64,1424,1426],{"className":1425},[1393],"  WHERE"," TABLE_TYPE = ",[64,1429,1432],{"className":1430},[1431],"str","'BASE TABLE'",[44,1434],{},[64,1436,1438],{"className":1437},[1393],"  AND"," OBJECTPROPERTY (OBJECT_ID(TABLE_NAME), ",[64,1441,1443],{"className":1442},[1431],"'IsMSShipped'",") = 0",[32,1446,1447,1450,1451,1453,1457],{},[64,1448,1394],{"className":1449},[1393]," @TableName sysname",[44,1452],{},[64,1454,1456],{"className":1455},[1393],"OPEN"," GetTables",[32,1459,1460,1286,1464,1286,1468,1395,1472,1476,1477,1479,1483,1484,1486,1490,1492,1496,1497,1499,1286,1503,1286,1506,1395,1509,1476,1512,1514],{},[64,1461,1463],{"className":1462},[1393],"FETCH",[64,1465,1467],{"className":1466},[1393],"NEXT",[64,1469,1471],{"className":1470},[1393],"FROM",[64,1473,1475],{"className":1474},[1393],"INTO"," @TableName",[44,1478],{},[64,1480,1482],{"className":1481},[1393],"WHILE"," (@@fetch_status = 0)",[44,1485],{},[64,1487,1489],{"className":1488},[1393],"BEGIN",[44,1491],{},[64,1493,1495],{"className":1494},[1393],"  EXEC"," sp_helpindex @TableName",[44,1498],{},[64,1500,1502],{"className":1501},[1393],"  FETCH",[64,1504,1467],{"className":1505},[1393],[64,1507,1471],{"className":1508},[1393],[64,1510,1475],{"className":1511},[1393],[44,1513],{},[64,1515,1517],{"className":1516},[1393],"END",[32,1519,1520,1457,1524,1526,1457],{},[64,1521,1523],{"className":1522},[1393],"CLOSE",[44,1525],{},[64,1527,1529],{"className":1528},[1393],"DEALLOCATE",[152,1531,1533],{"type":1532},"text\u002Fcss","\u003C![CDATA[csharpcode, .csharpcode pre  \n{  \n    font-size: small;  \n    color: black;  \n    font-family: consolas, \"Courier New\", courier, monospace;  \n    background-color: #ffffff;  \n    \u002F*white-space: pre;*\u002F  \n}  \n.csharpcode pre { margin: 0em; }  \n.csharpcode .rem { color: #008000; }  \n.csharpcode .kwrd { color: #0000ff; }  \n.csharpcode .str { color: #006080; }  \n.csharpcode .op { color: #0000c0; }  \n.csharpcode .preproc { color: #cc6633; }  \n.csharpcode .asp { background-color: #ffff00; }  \n.csharpcode .html { color: #800000; }  \n.csharpcode .attr { color: #ff0000; }  \n.csharpcode .alt   \n{  \n    background-color: #f4f4f4;  \n    width: 100%;  \n    margin: 0em;  \n}  \n.csharpcode .lnum { color: #606060; }  \n]]>",[152,1535,1533],{"type":1532},[152,1537,1533],{"type":1532},[123,1539],{"src":1540,"alt":11,"style":1541},"\u002Farticles\u002Fimages\u002Fsql2.gif","display:none;",{"title":11,"searchDepth":12,"depth":12,"links":1543},[],"2015-04-20T08:07:16.3900000-04:00",{},"\u002Farticles\u002Flist-indexes-in-sql-server",{"title":1372,"description":170},"articles\u002Flist-indexes-in-sql-server",[18],"PGhMpQ4KuNvCDC6fMPyQW3tunnAqa0GtOS8pvrjfWbo",{"id":1552,"title":1553,"author":28,"body":1554,"createdAt":1992,"description":170,"extension":15,"img":1993,"meta":1994,"navigation":19,"path":1995,"seo":1996,"stem":1997,"tags":1998,"updatedAt":1992,"__hash__":1999},"articles\u002Farticles\u002Fsql-server-and-drop-all-objects-tables-views-stored-procedures-etc.md","SQL Server and Drop all Objects (Tables\u002FViews\u002FStored Procedures etc.)",{"type":8,"value":1555,"toc":1990},[1556,1559,1988],[32,1557,1558],{},"The following SQL will drop all SQL Server objects within a database.",[55,1560,1562],{"className":410,"code":1561,"language":395,"meta":11,"style":11},"\u002F* Drop all non-system stored procs *\u002F \nDECLARE @name VARCHAR(128)    \nDECLARE @SQL VARCHAR(254)    \nSELECT @name = (SELECT TOP 1 [name] FROM sysobjects WHERE [type] = 'P' AND category = 0 ORDER BY [name])    \nWHILE @name is not null    \nBEGIN    \n    SELECT @SQL = 'DROP PROCEDURE [dbo].[' + RTRIM(@name) +']'    \n    EXEC (@SQL)    \n    PRINT 'Dropped Procedure: ' + @name    \n    SELECT @name = (SELECT TOP 1 [name] FROM sysobjects WHERE [type] = 'P' AND category = 0 AND [name] &gt; @name ORDER BY [name])    \nEND    \nGO  \n\u002F* Drop all views *\u002F     \nDECLARE @name VARCHAR(128)    \nDECLARE @SQL VARCHAR(254)    \nSELECT @name = (SELECT TOP 1 [name] FROM sysobjects WHERE [type] = 'V' AND category = 0 ORDER BY [name])    \nWHILE @name IS NOT NULL    \nBEGIN    \n    SELECT @SQL = 'DROP VIEW [dbo].[' + RTRIM(@name) +']'    \n    EXEC (@SQL)    \n    PRINT 'Dropped View: ' + @name    \n    SELECT @name = (SELECT TOP 1 [name] FROM sysobjects WHERE [type] = 'V' AND category = 0 AND [name] &gt; @name ORDER BY [name])    \nEND    \nGO  \n\u002F* Drop all functions *\u002F     \nDECLARE @name VARCHAR(128)    \nDECLARE @SQL VARCHAR(254)    \nSELECT @name = (SELECT TOP 1 [name] FROM sysobjects WHERE [type] IN (N'FN', N'IF', N'TF', N'FS', N'FT') AND category = 0 ORDER BY [name])    \nWHILE @name IS NOT NULL    \nBEGIN    \n    SELECT @SQL = 'DROP FUNCTION [dbo].[' + RTRIM(@name) +']'    \n    EXEC (@SQL)    \n    PRINT 'Dropped Function: ' + @name    \n    SELECT @name = (SELECT TOP 1 [name] FROM sysobjects WHERE [type] IN (N'FN', N'IF', N'TF', N'FS', N'FT') AND category = 0 AND [name] &gt; @name ORDER BY [name])    \nEND    \nGO  \n\u002F* Drop all Foreign Key constraints *\u002F     \nDECLARE @name VARCHAR(128)    \nDECLARE @constraint VARCHAR(254)    \nDECLARE @SQL VARCHAR(254)    \nSELECT @name = (SELECT TOP 1 TABLE_NAME FROM INFORMATION_SCHEMA.TABLE_CONSTRAINTS WHERE constraint_catalog=DB_NAME() AND CONSTRAINT_TYPE = 'FOREIGN KEY' ORDER BY TABLE_NAME)    \nWHILE @name is not null    \nBEGIN    \n    SELECT @constraint = (SELECT TOP 1 CONSTRAINT_NAME FROM INFORMATION_SCHEMA.TABLE_CONSTRAINTS WHERE constraint_catalog=DB_NAME() AND CONSTRAINT_TYPE = 'FOREIGN KEY' AND TABLE_NAME = @name ORDER BY CONSTRAINT_NAME)    \n    WHILE @constraint IS NOT NULL    \n    BEGIN    \n        SELECT @SQL = 'ALTER TABLE [dbo].[' + RTRIM(@name) +'] DROP CONSTRAINT ' + RTRIM(@constraint)    \n        EXEC (@SQL)    \n        PRINT 'Dropped FK Constraint: ' + @constraint + ' on ' + @name    \n        SELECT @constraint = (SELECT TOP 1 CONSTRAINT_NAME FROM INFORMATION_SCHEMA.TABLE_CONSTRAINTS WHERE constraint_catalog=DB_NAME() AND CONSTRAINT_TYPE = 'FOREIGN KEY' AND CONSTRAINT_NAME &lt;&gt; @constraint AND TABLE_NAME = @name ORDER BY CONSTRAINT_NAME)    \n    END    \nSELECT @name = (SELECT TOP 1 TABLE_NAME FROM INFORMATION_SCHEMA.TABLE_CONSTRAINTS WHERE constraint_catalog=DB_NAME() AND CONSTRAINT_TYPE = 'FOREIGN KEY' ORDER BY TABLE_NAME)    \nEND    \nGO  \n\u002F* Drop all Primary Key constraints *\u002F     \nDECLARE @name VARCHAR(128)    \nDECLARE @constraint VARCHAR(254)    \nDECLARE @SQL VARCHAR(254)    \nSELECT @name = (SELECT TOP 1 TABLE_NAME FROM INFORMATION_SCHEMA.TABLE_CONSTRAINTS WHERE constraint_catalog=DB_NAME() AND CONSTRAINT_TYPE = 'PRIMARY KEY' ORDER BY TABLE_NAME)    \nWHILE @name IS NOT NULL    \nBEGIN    \n    SELECT @constraint = (SELECT TOP 1 CONSTRAINT_NAME FROM INFORMATION_SCHEMA.TABLE_CONSTRAINTS WHERE constraint_catalog=DB_NAME() AND CONSTRAINT_TYPE = 'PRIMARY KEY' AND TABLE_NAME = @name ORDER BY CONSTRAINT_NAME)    \n    WHILE @constraint is not null    \n    BEGIN    \n        SELECT @SQL = 'ALTER TABLE [dbo].[' + RTRIM(@name) +'] DROP CONSTRAINT ' + RTRIM(@constraint)    \n        EXEC (@SQL)    \n        PRINT 'Dropped PK Constraint: ' + @constraint + ' on ' + @name    \n        SELECT @constraint = (SELECT TOP 1 CONSTRAINT_NAME FROM INFORMATION_SCHEMA.TABLE_CONSTRAINTS WHERE constraint_catalog=DB_NAME() AND CONSTRAINT_TYPE = 'PRIMARY KEY' AND CONSTRAINT_NAME &lt;&gt; @constraint AND TABLE_NAME = @name ORDER BY CONSTRAINT_NAME)    \n    END    \nSELECT @name = (SELECT TOP 1 TABLE_NAME FROM INFORMATION_SCHEMA.TABLE_CONSTRAINTS WHERE constraint_catalog=DB_NAME() AND CONSTRAINT_TYPE = 'PRIMARY KEY' ORDER BY TABLE_NAME)    \nEND    \nGO  \n\u002F* Drop all tables *\u002F     \nDECLARE @name VARCHAR(128)    \nDECLARE @SQL VARCHAR(254)    \nSELECT @name = (SELECT TOP 1 [name] FROM sysobjects WHERE [type] = 'U' AND category = 0 ORDER BY [name])    \nWHILE @name IS NOT NULL    \nBEGIN    \n    SELECT @SQL = 'DROP TABLE [dbo].[' + RTRIM(@name) +']'    \n    EXEC (@SQL)    \n    PRINT 'Dropped Table: ' + @name    \nSELECT @name = (SELECT TOP 1 [name] FROM sysobjects WHERE [type] = 'U' AND category = 0 AND [name] &gt; @name ORDER BY [name])    \nEND    \nGO\n",[61,1563,1564,1569,1574,1579,1584,1589,1594,1599,1604,1609,1614,1619,1624,1629,1633,1637,1642,1647,1651,1656,1660,1665,1670,1674,1678,1683,1687,1691,1696,1700,1704,1709,1713,1718,1723,1727,1731,1736,1740,1745,1749,1755,1760,1765,1771,1777,1783,1789,1795,1801,1807,1813,1818,1823,1828,1834,1839,1844,1849,1855,1860,1865,1871,1877,1882,1887,1892,1898,1904,1909,1914,1919,1924,1930,1935,1940,1946,1950,1955,1961,1966,1972,1978,1983],{"__ignoreMap":11},[64,1565,1566],{"class":66,"line":67},[64,1567,1568],{},"\u002F* Drop all non-system stored procs *\u002F \n",[64,1570,1571],{"class":66,"line":12},[64,1572,1573],{},"DECLARE @name VARCHAR(128)    \n",[64,1575,1576],{"class":66,"line":86},[64,1577,1578],{},"DECLARE @SQL VARCHAR(254)    \n",[64,1580,1581],{"class":66,"line":92},[64,1582,1583],{},"SELECT @name = (SELECT TOP 1 [name] FROM sysobjects WHERE [type] = 'P' AND category = 0 ORDER BY [name])    \n",[64,1585,1586],{"class":66,"line":98},[64,1587,1588],{},"WHILE @name is not null    \n",[64,1590,1591],{"class":66,"line":104},[64,1592,1593],{},"BEGIN    \n",[64,1595,1596],{"class":66,"line":110},[64,1597,1598],{},"    SELECT @SQL = 'DROP PROCEDURE [dbo].[' + RTRIM(@name) +']'    \n",[64,1600,1601],{"class":66,"line":116},[64,1602,1603],{},"    EXEC (@SQL)    \n",[64,1605,1606],{"class":66,"line":456},[64,1607,1608],{},"    PRINT 'Dropped Procedure: ' + @name    \n",[64,1610,1611],{"class":66,"line":462},[64,1612,1613],{},"    SELECT @name = (SELECT TOP 1 [name] FROM sysobjects WHERE [type] = 'P' AND category = 0 AND [name] &gt; @name ORDER BY [name])    \n",[64,1615,1616],{"class":66,"line":468},[64,1617,1618],{},"END    \n",[64,1620,1621],{"class":66,"line":537},[64,1622,1623],{},"GO  \n",[64,1625,1626],{"class":66,"line":542},[64,1627,1628],{},"\u002F* Drop all views *\u002F     \n",[64,1630,1631],{"class":66,"line":548},[64,1632,1573],{},[64,1634,1635],{"class":66,"line":553},[64,1636,1578],{},[64,1638,1639],{"class":66,"line":559},[64,1640,1641],{},"SELECT @name = (SELECT TOP 1 [name] FROM sysobjects WHERE [type] = 'V' AND category = 0 ORDER BY [name])    \n",[64,1643,1644],{"class":66,"line":565},[64,1645,1646],{},"WHILE @name IS NOT NULL    \n",[64,1648,1649],{"class":66,"line":571},[64,1650,1593],{},[64,1652,1653],{"class":66,"line":576},[64,1654,1655],{},"    SELECT @SQL = 'DROP VIEW [dbo].[' + RTRIM(@name) +']'    \n",[64,1657,1658],{"class":66,"line":581},[64,1659,1603],{},[64,1661,1662],{"class":66,"line":587},[64,1663,1664],{},"    PRINT 'Dropped View: ' + @name    \n",[64,1666,1667],{"class":66,"line":592},[64,1668,1669],{},"    SELECT @name = (SELECT TOP 1 [name] FROM sysobjects WHERE [type] = 'V' AND category = 0 AND [name] &gt; @name ORDER BY [name])    \n",[64,1671,1672],{"class":66,"line":598},[64,1673,1618],{},[64,1675,1676],{"class":66,"line":603},[64,1677,1623],{},[64,1679,1680],{"class":66,"line":608},[64,1681,1682],{},"\u002F* Drop all functions *\u002F     \n",[64,1684,1685],{"class":66,"line":614},[64,1686,1573],{},[64,1688,1689],{"class":66,"line":620},[64,1690,1578],{},[64,1692,1693],{"class":66,"line":626},[64,1694,1695],{},"SELECT @name = (SELECT TOP 1 [name] FROM sysobjects WHERE [type] IN (N'FN', N'IF', N'TF', N'FS', N'FT') AND category = 0 ORDER BY [name])    \n",[64,1697,1698],{"class":66,"line":632},[64,1699,1646],{},[64,1701,1702],{"class":66,"line":638},[64,1703,1593],{},[64,1705,1706],{"class":66,"line":644},[64,1707,1708],{},"    SELECT @SQL = 'DROP FUNCTION [dbo].[' + RTRIM(@name) +']'    \n",[64,1710,1711],{"class":66,"line":650},[64,1712,1603],{},[64,1714,1715],{"class":66,"line":656},[64,1716,1717],{},"    PRINT 'Dropped Function: ' + @name    \n",[64,1719,1720],{"class":66,"line":662},[64,1721,1722],{},"    SELECT @name = (SELECT TOP 1 [name] FROM sysobjects WHERE [type] IN (N'FN', N'IF', N'TF', N'FS', N'FT') AND category = 0 AND [name] &gt; @name ORDER BY [name])    \n",[64,1724,1725],{"class":66,"line":668},[64,1726,1618],{},[64,1728,1729],{"class":66,"line":674},[64,1730,1623],{},[64,1732,1733],{"class":66,"line":680},[64,1734,1735],{},"\u002F* Drop all Foreign Key constraints *\u002F     \n",[64,1737,1738],{"class":66,"line":686},[64,1739,1573],{},[64,1741,1742],{"class":66,"line":692},[64,1743,1744],{},"DECLARE @constraint VARCHAR(254)    \n",[64,1746,1747],{"class":66,"line":698},[64,1748,1578],{},[64,1750,1752],{"class":66,"line":1751},41,[64,1753,1754],{},"SELECT @name = (SELECT TOP 1 TABLE_NAME FROM INFORMATION_SCHEMA.TABLE_CONSTRAINTS WHERE constraint_catalog=DB_NAME() AND CONSTRAINT_TYPE = 'FOREIGN KEY' ORDER BY TABLE_NAME)    \n",[64,1756,1758],{"class":66,"line":1757},42,[64,1759,1588],{},[64,1761,1763],{"class":66,"line":1762},43,[64,1764,1593],{},[64,1766,1768],{"class":66,"line":1767},44,[64,1769,1770],{},"    SELECT @constraint = (SELECT TOP 1 CONSTRAINT_NAME FROM INFORMATION_SCHEMA.TABLE_CONSTRAINTS WHERE constraint_catalog=DB_NAME() AND CONSTRAINT_TYPE = 'FOREIGN KEY' AND TABLE_NAME = @name ORDER BY CONSTRAINT_NAME)    \n",[64,1772,1774],{"class":66,"line":1773},45,[64,1775,1776],{},"    WHILE @constraint IS NOT NULL    \n",[64,1778,1780],{"class":66,"line":1779},46,[64,1781,1782],{},"    BEGIN    \n",[64,1784,1786],{"class":66,"line":1785},47,[64,1787,1788],{},"        SELECT @SQL = 'ALTER TABLE [dbo].[' + RTRIM(@name) +'] DROP CONSTRAINT ' + RTRIM(@constraint)    \n",[64,1790,1792],{"class":66,"line":1791},48,[64,1793,1794],{},"        EXEC (@SQL)    \n",[64,1796,1798],{"class":66,"line":1797},49,[64,1799,1800],{},"        PRINT 'Dropped FK Constraint: ' + @constraint + ' on ' + @name    \n",[64,1802,1804],{"class":66,"line":1803},50,[64,1805,1806],{},"        SELECT @constraint = (SELECT TOP 1 CONSTRAINT_NAME FROM INFORMATION_SCHEMA.TABLE_CONSTRAINTS WHERE constraint_catalog=DB_NAME() AND CONSTRAINT_TYPE = 'FOREIGN KEY' AND CONSTRAINT_NAME &lt;&gt; @constraint AND TABLE_NAME = @name ORDER BY CONSTRAINT_NAME)    \n",[64,1808,1810],{"class":66,"line":1809},51,[64,1811,1812],{},"    END    \n",[64,1814,1816],{"class":66,"line":1815},52,[64,1817,1754],{},[64,1819,1821],{"class":66,"line":1820},53,[64,1822,1618],{},[64,1824,1826],{"class":66,"line":1825},54,[64,1827,1623],{},[64,1829,1831],{"class":66,"line":1830},55,[64,1832,1833],{},"\u002F* Drop all Primary Key constraints *\u002F     \n",[64,1835,1837],{"class":66,"line":1836},56,[64,1838,1573],{},[64,1840,1842],{"class":66,"line":1841},57,[64,1843,1744],{},[64,1845,1847],{"class":66,"line":1846},58,[64,1848,1578],{},[64,1850,1852],{"class":66,"line":1851},59,[64,1853,1854],{},"SELECT @name = (SELECT TOP 1 TABLE_NAME FROM INFORMATION_SCHEMA.TABLE_CONSTRAINTS WHERE constraint_catalog=DB_NAME() AND CONSTRAINT_TYPE = 'PRIMARY KEY' ORDER BY TABLE_NAME)    \n",[64,1856,1858],{"class":66,"line":1857},60,[64,1859,1646],{},[64,1861,1863],{"class":66,"line":1862},61,[64,1864,1593],{},[64,1866,1868],{"class":66,"line":1867},62,[64,1869,1870],{},"    SELECT @constraint = (SELECT TOP 1 CONSTRAINT_NAME FROM INFORMATION_SCHEMA.TABLE_CONSTRAINTS WHERE constraint_catalog=DB_NAME() AND CONSTRAINT_TYPE = 'PRIMARY KEY' AND TABLE_NAME = @name ORDER BY CONSTRAINT_NAME)    \n",[64,1872,1874],{"class":66,"line":1873},63,[64,1875,1876],{},"    WHILE @constraint is not null    \n",[64,1878,1880],{"class":66,"line":1879},64,[64,1881,1782],{},[64,1883,1885],{"class":66,"line":1884},65,[64,1886,1788],{},[64,1888,1890],{"class":66,"line":1889},66,[64,1891,1794],{},[64,1893,1895],{"class":66,"line":1894},67,[64,1896,1897],{},"        PRINT 'Dropped PK Constraint: ' + @constraint + ' on ' + @name    \n",[64,1899,1901],{"class":66,"line":1900},68,[64,1902,1903],{},"        SELECT @constraint = (SELECT TOP 1 CONSTRAINT_NAME FROM INFORMATION_SCHEMA.TABLE_CONSTRAINTS WHERE constraint_catalog=DB_NAME() AND CONSTRAINT_TYPE = 'PRIMARY KEY' AND CONSTRAINT_NAME &lt;&gt; @constraint AND TABLE_NAME = @name ORDER BY CONSTRAINT_NAME)    \n",[64,1905,1907],{"class":66,"line":1906},69,[64,1908,1812],{},[64,1910,1912],{"class":66,"line":1911},70,[64,1913,1854],{},[64,1915,1917],{"class":66,"line":1916},71,[64,1918,1618],{},[64,1920,1922],{"class":66,"line":1921},72,[64,1923,1623],{},[64,1925,1927],{"class":66,"line":1926},73,[64,1928,1929],{},"\u002F* Drop all tables *\u002F     \n",[64,1931,1933],{"class":66,"line":1932},74,[64,1934,1573],{},[64,1936,1938],{"class":66,"line":1937},75,[64,1939,1578],{},[64,1941,1943],{"class":66,"line":1942},76,[64,1944,1945],{},"SELECT @name = (SELECT TOP 1 [name] FROM sysobjects WHERE [type] = 'U' AND category = 0 ORDER BY [name])    \n",[64,1947,1948],{"class":66,"line":321},[64,1949,1646],{},[64,1951,1953],{"class":66,"line":1952},78,[64,1954,1593],{},[64,1956,1958],{"class":66,"line":1957},79,[64,1959,1960],{},"    SELECT @SQL = 'DROP TABLE [dbo].[' + RTRIM(@name) +']'    \n",[64,1962,1964],{"class":66,"line":1963},80,[64,1965,1603],{},[64,1967,1969],{"class":66,"line":1968},81,[64,1970,1971],{},"    PRINT 'Dropped Table: ' + @name    \n",[64,1973,1975],{"class":66,"line":1974},82,[64,1976,1977],{},"SELECT @name = (SELECT TOP 1 [name] FROM sysobjects WHERE [type] = 'U' AND category = 0 AND [name] &gt; @name ORDER BY [name])    \n",[64,1979,1981],{"class":66,"line":1980},83,[64,1982,1618],{},[64,1984,1986],{"class":66,"line":1985},84,[64,1987,471],{},[152,1989,715],{},{"title":11,"searchDepth":12,"depth":12,"links":1991},[],"2015-04-20T08:07:15.3400000-04:00","\u002Farticles\u002Fimages\u002Fsql.jpg",{},"\u002Farticles\u002Fsql-server-and-drop-all-objects-tables-views-stored-procedures-etc",{"title":1553,"description":170},"articles\u002Fsql-server-and-drop-all-objects-tables-views-stored-procedures-etc",[395,18],"-AosXGHvi-Nm2hxkKypyQPWlfVYZ_LUe68mREC3CbRY",{"id":2001,"title":2002,"author":28,"body":2003,"createdAt":2056,"description":2057,"extension":15,"img":2058,"meta":2059,"navigation":19,"path":2060,"seo":2061,"stem":2062,"tags":2063,"updatedAt":2056,"__hash__":2065},"articles\u002Farticles\u002Fnew-ssdt-power-tools-now-for-both-visual-studio-2010-and-visual-studio-2012.md","New SSDT Power Tools! Now for both Visual Studio 2010 and Visual Studio 2012",{"type":8,"value":2004,"toc":2054},[2005,2008,2011],[32,2006,2007],{},"Microsoft is pleased to announce the latest release of SSDT Power Tools!",[32,2009,2010],{},"We continue to use power tools to get early versions of experiences or quick features to you and we’re always interested in hearing your feedback.",[32,2012,2013,2014,2018,2019,2022,2025,2026,2029,2032,2033,2037,2038,2042,2043,2045,2046,2048,2051],{},"This release of the tools (Version 1.3) builds on the previous release.  This release of the power tools is",[2015,2016,2017],"i",{}," only ","compatible with the newest update for SQL Server Data Tools. First, get the SSDT – September 2012 update for Visual Studio 2010 or Visual Studio 2012 here:  SSDT for Visual Studio 2012: ",[229,2020],{"href":2021},"http:\u002F\u002Fmsdn.microsoft.com\u002Fen-us\u002Fjj650015",[229,2023,2021],{"href":2021,"rel":2024},[1300],"  SSDT for Visual Studio 2010: ",[229,2027],{"href":2028},"http:\u002F\u002Fmsdn.microsoft.com\u002Fen-us\u002Fjj650014",[229,2030,2028],{"href":2028,"rel":2031},[1300],"    For the first time, this power tools release provides a version of the power tools for Visual Studio 2012 in addition to the version for Visual Studio 2010. They are separate installs that you can grab here:  ",[229,2034,2036],{"href":2035},"http:\u002F\u002Fvisualstudiogallery.msdn.microsoft.com\u002F9b0228c6-15d1-44de-9279-66dde12bf861?SRC=Featured","SSDT Power Tools for Visual Studio 2010","  ",[229,2039,2041],{"href":2040},"http:\u002F\u002Fvisualstudiogallery.msdn.microsoft.com\u002F96a2f8cc-0c8b-47dd-93cd-1e8e9f34a917","SSDT Power Tools for Visual Studio 2012","  Requirements:",[44,2044],{},"\nSQL Server 2008 Service Pack 1",[44,2047],{},[229,2049],{"href":2050},"http:\u002F\u002Fwww.microsoft.com\u002Fen-us\u002Fdownload\u002Fdetails.aspx?id=20302",[229,2052,2050],{"href":2050,"rel":2053},[1300],{"title":11,"searchDepth":12,"depth":12,"links":2055},[],"2015-04-20T08:07:12.8400000-04:00","SQL Server Data Tools (SSDT) provides project templates and design surfaces for building SQL Server content types - relational databases, Analysis Services models, Reporting Services reports, and Integration Services packages.","\u002Farticles\u002Fimages\u002FMdpbTnH58m.png",{},"\u002Farticles\u002Fnew-ssdt-power-tools-now-for-both-visual-studio-2010-and-visual-studio-2012",{"title":2002,"description":2057},"articles\u002Fnew-ssdt-power-tools-now-for-both-visual-studio-2010-and-visual-studio-2012",[2064,395,18],"visualstudio","e_YUJhN16WAmwBhand1Scn-44WrB72gU7EuktLScjHE",1781574760392]