<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>SQL on Bryan Avery</title><link>https://bryanavery.co.uk/categories/sql/</link><description>Recent content in SQL on Bryan Avery</description><generator>Hugo -- gohugo.io</generator><language>en-GB</language><copyright>© 2026 Bryan Avery.</copyright><lastBuildDate>Wed, 10 Feb 2021 15:02:01 +0000</lastBuildDate><atom:link href="https://bryanavery.co.uk/categories/sql/index.xml" rel="self" type="application/rss+xml"/><item><title>SQL Record Count</title><link>https://bryanavery.co.uk/sql-record-count/</link><pubDate>Wed, 10 Feb 2021 15:02:01 +0000</pubDate><guid>https://bryanavery.co.uk/sql-record-count/</guid><description>&lt;p&gt;The fastest way to perform a SQL record count is:&lt;/p&gt;&#10;&lt;div&gt;&lt;pre class="brush: plain; title: ; notranslate" title=""&gt;&#10;DECLARE @TableName sysname&#10;SET @TableName = 'Log'&#10;&lt;p&gt;SELECT TBL.object_id, TBL.name, SUM(PART.rows) AS rows&#10;FROM sys.tables TBL&#10;INNER JOIN sys.partitions PART ON TBL.object_id = PART.object_id&#10;INNER JOIN sys.indexes IDX ON PART.object_id = IDX.object_id&#10;AND PART.index_id = IDX.index_id&#10;WHERE TBL.name = @TableName&#10;AND IDX.index_id &amp;amp;lt; 2&#10;GROUP BY TBL.object_id, TBL.name;&#10;&lt;/pre&gt;&lt;/div&gt;&lt;/p&gt;</description></item><item><title>How to export all tables to csv by one export job</title><link>https://bryanavery.co.uk/how-to-export-all-tables-to-csv-by-one-export-job/</link><pubDate>Wed, 16 Jan 2019 10:22:13 +0000</pubDate><guid>https://bryanavery.co.uk/how-to-export-all-tables-to-csv-by-one-export-job/</guid><description>&lt;p&gt;If you just want to export all the tables in a SQL database in to separate CSV files, then this is a quick and easy way of doing it.&lt;/p&gt;&#10;&lt;ol&gt;&#10;&lt;li style="font-weight: 400;"&gt;&lt;span style="font-weight: 400;"&gt;Execute below query which generates BCP commands&lt;/span&gt;&lt;span style="font-weight: 400;"&gt;&lt;br/&gt;&#10;&lt;/span&gt;&lt;span style="font-weight: 400;"&gt;&lt;br/&gt;&#10;&lt;/span&gt;&lt;span style="font-weight: 400;"&gt;SELECT ‘bcp ‘ + st.NAME + ‘ out c:\Target\’ + st.NAME + ‘.csv -c -r -d ‘ + DB_NAME() + ‘ -U user@??????.database.windows.net -S tcp:?????.database.windows.net -P ?????? &lt;/span&gt;&lt;span style="font-weight: 400;"&gt;FROM sys.tables st&lt;/span&gt;&lt;/li&gt;&#10;&lt;li style="font-weight: 400;"&gt;&lt;span style="font-weight: 400;"&gt;Paste the result set into text file. Make batch file and schedule it. (It can also be run in CMD manually)&lt;/span&gt;&lt;/li&gt;&#10;&lt;/ol&gt;&#10;&lt;p&gt; &lt;/p&gt;</description></item><item><title>Break apart the connection string</title><link>https://bryanavery.co.uk/break-apart-the-connection-string/</link><pubDate>Tue, 31 Jul 2018 07:35:23 +0000</pubDate><guid>https://bryanavery.co.uk/break-apart-the-connection-string/</guid><description>&lt;p&gt;It is sometimes useful to know which database you are connected to, here is a simple method that pulls apart the connection string and provides you with the section you request.&lt;span id="more-992"&gt;&lt;/span&gt;&lt;/p&gt;&#10;&lt;pre&gt;private static string GetSection(string section)&#10;{&#10;var connectionString = string.Empty;&#10;&lt;p&gt;Configuration rootWebConfig = System.Web.Configuration.WebConfigurationManager.OpenWebConfiguration(&amp;quot;/MyWebSiteRoot&amp;quot;);&#10;ConnectionStringSettings connString;&lt;/p&gt;&#10;&lt;p&gt;if (rootWebConfig.ConnectionStrings.ConnectionStrings.Count &amp;gt; 0)&#10;{&#10;connString = rootWebConfig.ConnectionStrings.ConnectionStrings[&amp;ldquo;Entities&amp;rdquo;];&#10;if (connString != null)&#10;connectionString = connString.ConnectionString;&#10;}&lt;/p&gt;&#10;&lt;p&gt;string[] parts = connectionString.Split(&amp;rsquo;;&amp;rsquo;);&lt;/p&gt;&#10;&lt;p&gt;for (int i = 0; i &amp;lt; parts.Length; i++)&#10;{&#10;string part = parts[i].Trim().ToLowerInvariant();&#10;if (part.StartsWith($&amp;quot;{section}=&amp;quot;))&#10;{&#10;return part.Replace($&amp;quot;{section}=&amp;quot;, &amp;ldquo;&amp;rdquo;);&#10;}&#10;}&lt;/p&gt;&#10;&lt;p&gt;return &amp;ldquo;Unknown&amp;rdquo;;&#10;}&lt;/pre&gt;</description></item><item><title>Search every column in a SQL Server Database</title><link>https://bryanavery.co.uk/search-every-column-in-a-sql-server-database/</link><pubDate>Thu, 22 Feb 2018 10:27:46 +0000</pubDate><guid>https://bryanavery.co.uk/search-every-column-in-a-sql-server-database/</guid><description>&lt;p&gt;Following on from the &lt;a href="https://bryanavery.co.uk/index.html%3Fp=878.html"&gt;Search every table and field in a SQL Server Database&lt;/a&gt; article I posted last week, I thought it would be useful also to be able to search every column for some text and return where it was found.&lt;/p&gt;</description></item><item><title>Search every column in a SQL Server Database</title><link>https://bryanavery.co.uk/search/</link><pubDate>Thu, 22 Feb 2018 10:27:46 +0000</pubDate><guid>https://bryanavery.co.uk/search/</guid><description>&lt;p&gt;Following on from the &lt;a href="https://bryanavery.co.uk/index.html%3Fp=878.html"&gt;Search every table and field in a SQL Server Database&lt;/a&gt; article I posted last week, I thought it would be useful also to be able to search every column for some text and return where it was found.&lt;/p&gt;</description></item><item><title>Search every table and field in a SQL Server Database</title><link>https://bryanavery.co.uk/search-every-table-and-field-in-a-sql-server-database/</link><pubDate>Fri, 16 Feb 2018 08:10:27 +0000</pubDate><guid>https://bryanavery.co.uk/search-every-table-and-field-in-a-sql-server-database/</guid><description>&lt;p&gt;One thing I do like about MySQL is when using phpMyAdmin is the ability to search the whole database for any string, this should only be available for developers who are searching for data in an extensive database.  It does take some time to run, but remember it has a lot to do.&lt;/p&gt;</description></item><item><title>Database Layer</title><link>https://bryanavery.co.uk/database-layer/</link><pubDate>Mon, 24 Jul 2017 15:39:35 +0000</pubDate><guid>https://bryanavery.co.uk/database-layer/</guid><description>&lt;p&gt;The DatabaseLayer is an abstraction for database access which means the calling application or library does not need to be tight-coupled to the database itself. A set of factory methods is available to call in order to create commands and parameters, all based on the .NET abstract base classes.&lt;/p&gt;</description></item><item><title>ttt</title><link>https://bryanavery.co.uk/ttt/</link><pubDate>Wed, 05 Mar 2014 06:44:00 +0000</pubDate><guid>https://bryanavery.co.uk/ttt/</guid><description>&lt;p style="margin: 0px 0px 1em; padding: 0px; border: 0px; font-size: 14px; vertical-align: baseline; clear: both; font-family: Arial, 'Liberation Sans', 'DejaVu Sans', sans-serif; line-height: 17.804800033569336px;"&gt;I can’t believe I couldn’t find a working solution to this after an hour of searching. I’m following &lt;a href="http://www.dotnetcurry.com/showarticle/?ID=941" rel="nofollow" style="margin: 0px; padding: 0px; border: 0px; vertical-align: baseline; background-color: transparent; color: #4a6b82; text-decoration: none; cursor: pointer;"&gt;this article&lt;/a&gt;on Entity Framework 6.0 which gives a simple walk-through on Code First. I created the project and installed the latest &lt;a href="https://www.nuget.org/packages/EntityFramework/6.0.2" rel="nofollow" style="margin: 0px; padding: 0px; border: 0px; vertical-align: baseline; background-color: transparent; color: #4a6b82; text-decoration: none; cursor: pointer;"&gt;EF Nuget package&lt;/a&gt; for the project to compile. I also verified that I have Microsoft SQL Server 2012 Express LocalDB installed which came with Visual Studio 2013. I don’t have any other instances of SQL installed on my local computer. The program runs and entries are added to the database and outputted in the console. But when the article says “check your localdb” it doesn’t say how! I don’t see any ‘.mdf’ or ‘.ldf’ files created under the project folder. I tried every way to connect Visual Studio’s Server Explorer to LocalDB. The wizard cannot locate &lt;code style="margin: 0px; padding: 1px 5px; border: 0px; vertical-align: baseline; background-color: #eeeeee; font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Courier New', monospace, serif; white-space: pre-wrap;"&gt;(localdb)&lt;/code&gt; or cannot find any provider in Server Explorer to accept connection string like &lt;code style="margin: 0px; padding: 1px 5px; border: 0px; vertical-align: baseline; background-color: #eeeeee; font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Courier New', monospace, serif; white-space: pre-wrap;"&gt;(localdb)\v11.0;Integrated Security=true;"&lt;/code&gt; I’ve seen this asked several places in StackOverflow but no answer works or marked as answer. Please help, this doesn’t have to be this frustrating!&lt;/p&gt;</description></item><item><title>How to Rank your search results with multiple search terms using LINQ and EntityFramework</title><link>https://bryanavery.co.uk/how-to-rank-your-search-results-with-multiple-search-terms-using-linq-and-entityframework/</link><pubDate>Tue, 31 Dec 2013 11:59:00 +0000</pubDate><guid>https://bryanavery.co.uk/how-to-rank-your-search-results-with-multiple-search-terms-using-linq-and-entityframework/</guid><description>&lt;p&gt;I have always used a ranked search criteria, it’s the only true way to get good results back from a data set.  But I’ve been doing my ranking within C# code.  But this got all the data from the data source and then ranked the results.  This is very poor on performance, as we should only be returning back the results for the page size we require.&lt;/p&gt;</description></item><item><title>Backup SQL Azure</title><link>https://bryanavery.co.uk/backup-sql-azure/</link><pubDate>Sat, 28 Dec 2013 10:36:00 +0000</pubDate><guid>https://bryanavery.co.uk/backup-sql-azure/</guid><description>&lt;p&gt;There are a number of options for backing up SQL Azure, which can be found here:&lt;/p&gt;&#10;&lt;p&gt;&lt;a href="http://blogs.msdn.com/b/windows_azure_technical_support_wats_team/archive/2013/03/04/different-ways-to-backup-your-windows-azure-sql-database/" target="_blank"&gt;Different ways to Backup your Windows Azure SQL Database&lt;/a&gt;&lt;/p&gt;&#10;&lt;p&gt;I like the Azure way, which is just exporting, importing and setting a scheduled&lt;/p&gt;</description></item><item><title>Migration from SQL to SQL Azure</title><link>https://bryanavery.co.uk/migration-from-sql-to-sql-azure/</link><pubDate>Wed, 04 Dec 2013 05:17:00 +0000</pubDate><guid>https://bryanavery.co.uk/migration-from-sql-to-sql-azure/</guid><description>&lt;h2&gt;Tasks in Migration&lt;/h2&gt;&#10;&lt;ol&gt;&#10;&lt;li&gt;Migrate users and login ID’s&lt;/li&gt;&#10;&lt;li&gt;Map data types&lt;/li&gt;&#10;&lt;li&gt;Map database objects: tables, triggers, views, stored procedures&lt;/li&gt;&#10;&lt;li&gt;Update incompatible objects to work with SQL Azure&lt;/li&gt;&#10;&lt;li&gt;Update application to work with SQL Azure&lt;/li&gt;&#10;&lt;li&gt;Migrate data to SQL Azure&lt;/li&gt;&#10;&lt;/ol&gt;</description></item><item><title>SQL Performance Profiler for SQL Express</title><link>https://bryanavery.co.uk/sql-performance-profiler-for-sql-express/</link><pubDate>Fri, 19 Apr 2013 13:54:00 +0000</pubDate><guid>https://bryanavery.co.uk/sql-performance-profiler-for-sql-express/</guid><description>&lt;p&gt;I came across this smart little Profiler for SQL Express, or any version of SQL as it happens.&lt;/p&gt;&#10;&lt;p&gt;Microsoft SQL Server family includes free Express edition, that is fully functional, however has some disappointing limitations which prevent from using it in development process. One of them is absense of profiling tools, standard SQL profiler is not included. However, I came across this SQL Performance Profiler to use with the express edition for tuning your system.&lt;/p&gt;</description></item><item><title>Search every SQL table for a string</title><link>https://bryanavery.co.uk/search-every-sql-table-for-a-string/</link><pubDate>Fri, 15 Mar 2013 11:15:00 +0000</pubDate><guid>https://bryanavery.co.uk/search-every-sql-table-for-a-string/</guid><description>&lt;p&gt;Here is some neat SQL to allow you to search every table and every field in the database for a string&lt;/p&gt;&#10;&lt;pre class="brush: sql;"&gt;CREATE TABLE myTable99 (TABLE_NAME sysname, COLUMN_NAME sysname, Occurs int)&#10;GO&#10;&lt;p&gt;SET NOCOUNT ON&lt;/p&gt;&#10;&lt;p&gt;DECLARE @SQL varchar(8000), @TABLE_NAME sysname, @COLUMN_NAME sysname, @Sargable varchar(80), @Count int&lt;/p&gt;&#10;&lt;p&gt;SELECT @Sargable = &amp;lsquo;There are too many subscription products resulting from the supplied request data&amp;rsquo;&lt;/p&gt;&#10;&lt;p&gt;DECLARE insaneCursor CURSOR FOR&#10;SELECT c.TABLE_NAME, c.COLUMN_NAME&#10;FROM INFORMATION_SCHEMA.Columns c INNER JOIN INFORMATION_SCHEMA.Tables t&#10;ON t.TABLE_SCHEMA = c.TABLE_SCHEMA AND t.TABLE_NAME = c.TABLE_NAME&#10;WHERE c.DATA_TYPE IN (&amp;lsquo;char&amp;rsquo;,&amp;rsquo;nchar&amp;rsquo;,&amp;lsquo;varchar&amp;rsquo;,&amp;rsquo;nvarchar&amp;rsquo;,&amp;rsquo;text&amp;rsquo;,&amp;rsquo;ntext&amp;rsquo;)&#10;AND t.TABLE_TYPE = &amp;lsquo;BASE TABLE&amp;rsquo;&lt;/p&gt;&#10;&lt;p&gt;OPEN insaneCursor&lt;/p&gt;&#10;&lt;p&gt;FETCH NEXT FROM insaneCursor INTO @TABLE_NAME, @COLUMN_NAME&lt;/p&gt;&#10;&lt;p&gt;WHILE @@FETCH_STATUS = 0&#10;BEGIN&#10;SELECT @SQL = &amp;lsquo;INSERT INTO myTable99 (TABLE_NAME, COLUMN_NAME, Occurs) SELECT '&#10;+ &amp;rsquo;&amp;rsquo;&amp;rsquo;&amp;rsquo; + @TABLE_NAME + &amp;rsquo;&amp;rsquo;&amp;rsquo;&amp;rsquo; + &amp;lsquo;,&amp;rsquo;&#10;+ &amp;rsquo;&amp;rsquo;&amp;rsquo;&amp;rsquo; + @COLUMN_NAME + &amp;rsquo;&amp;rsquo;&amp;rsquo;&amp;rsquo; + &amp;lsquo;,&amp;rsquo;&#10;+ &amp;lsquo;COUNT(*) FROM [&amp;rsquo; + @TABLE_NAME&lt;br&gt;&#10;+ &amp;lsquo;] WHERE [&amp;rsquo; + @COLUMN_NAME + &amp;lsquo;] Like '&#10;+ &amp;lsquo;&amp;rsquo;&amp;rsquo;&amp;rsquo;+ &amp;lsquo;%&amp;rsquo; + @Sargable + &amp;lsquo;%&amp;rsquo; + &amp;rsquo;&amp;rsquo;&amp;rsquo;&amp;rsquo;&#10;&amp;ndash;SELECT @SQL&#10;EXEC(@SQL)&#10;IF @@ERROR &amp;lt;&amp;gt; 0&#10;BEGIN&#10;SELECT @SQL&#10;SELECT * FROM INFORMATION_SCHEMA.Columns WHERE TABLE_NAME = @TABLE_NAME&#10;GOTO Error&#10;END&#10;FETCH NEXT FROM insaneCursor INTO @TABLE_NAME, @COLUMN_NAME&#10;END&lt;/p&gt;&#10;&lt;p&gt;SELECT * FROM myTable99 WHERE Occurs &amp;lt;&amp;gt; 0&lt;/p&gt;&#10;&lt;p&gt;Error:&#10;CLOSE insaneCursor&#10;DEALLOCATE insaneCursor&lt;/p&gt;&#10;&lt;p&gt;GO&lt;/p&gt;&#10;&lt;p&gt;DROP TABLE myTable99&#10;GO&lt;/p&gt;&#10;&lt;p&gt;SET NOCOUNT OFF&lt;/pre&gt;</description></item><item><title>Deploy a database project with TFS Build</title><link>https://bryanavery.co.uk/deploy-a-database-project-with-tfs-build/</link><pubDate>Wed, 27 Feb 2013 14:24:00 +0000</pubDate><guid>https://bryanavery.co.uk/deploy-a-database-project-with-tfs-build/</guid><description>&lt;p&gt;When you develop web application you often have this scenario. Some people are testers, they are testing the application in dev all day, and they want always to test latest version. Moreover testers usually fills data into web application, so they want their data to be preserved between various deploy. If you simply clear all data in test database you will end with a lot of furious tester so do not even think to do this.&lt;br/&gt; &lt;br/&gt;If a developer needs to change database schema, we need to automate not only the deploy of the web application, but we need also to sync test database with the latest changes. This is necessary so the test site can work with the new version, but old data is preserved for the happiness of the testers.&lt;br/&gt; &lt;br/&gt;This is quite simple using TFS and Database project. The situation is this one&lt;/p&gt;</description></item><item><title>Who is locking my SQL database?</title><link>https://bryanavery.co.uk/who-is-locking-my-sql-database/</link><pubDate>Tue, 19 Feb 2013 12:13:00 +0000</pubDate><guid>https://bryanavery.co.uk/who-is-locking-my-sql-database/</guid><description>&lt;p&gt;Need to know who is logged on to your SQL database ,here is a nice script that I got from Gary Dunne &lt;/p&gt;&#10;&lt;pre class="brush: sql;"&gt;DECLARE @spid1 int = NULL /* server process id to check for locks */ &#10;DECLARE @spid2 int = NULL /* other process id to check for locks */ &#10;&lt;p&gt;set nocount on&#10;/*&#10;** Show the locks for both parameters.&#10;*/&#10;declare @objid int,&#10;@dbid int,&#10;@string Nvarchar(255)&lt;/p&gt;&#10;&lt;p&gt;CREATE TABLE #locktable&#10;(&#10;spid smallint&#10;,loginname nvarchar(20)&#10;,hostname nvarchar(30)&#10;,dbid int&#10;,dbname nvarchar(20)&#10;,objId int&#10;,ObjName nvarchar(128)&#10;,IndId int&#10;,Type nvarchar(4)&#10;,Resource nvarchar(16)&#10;,Mode nvarchar(8)&#10;,Status nvarchar(5)&#10;)&lt;/p&gt;&#10;&lt;p&gt;if @spid1 is not NULL&#10;begin&#10;INSERT #locktable&#10;(&#10;spid&#10;,loginname&#10;,hostname&#10;,dbid&#10;,dbname&#10;,objId&#10;,ObjName&#10;,IndId&#10;,Type&#10;,Resource&#10;,Mode&#10;,Status&#10;)&#10;select convert (smallint, l.req_spid)&#10;&amp;ndash;,coalesce(substring (user_name(req_spid), 1, 20),&amp;rsquo;&amp;rsquo;)&#10;,coalesce(substring (s.loginame, 1, 20),&amp;rsquo;&amp;rsquo;)&#10;,coalesce(substring (s.hostname, 1, 30),&amp;rsquo;&amp;rsquo;)&#10;,l.rsc_dbid&#10;,substring (db_name(l.rsc_dbid), 1, 20)&#10;,l.rsc_objid&#10;,&amp;rsquo;'&#10;,l.rsc_indid&#10;,substring (v.name, 1, 4)&#10;,substring (l.rsc_text, 1, 16)&#10;,substring (u.name, 1, 8)&#10;,substring (x.name, 1, 5)&#10;from master.dbo.syslockinfo l,&#10;master.dbo.spt_values v,&#10;master.dbo.spt_values x,&#10;master.dbo.spt_values u,&#10;master.dbo.sysprocesses s&#10;where l.rsc_type = v.number&#10;and v.type = &amp;lsquo;LR&amp;rsquo;&#10;and l.req_status = x.number&#10;and x.type = &amp;lsquo;LS&amp;rsquo;&#10;and l.req_mode + 1 = u.number&#10;and u.type = &amp;lsquo;L&amp;rsquo;&#10;and req_spid in (@spid1, @spid2)&#10;and req_spid = s.spid&#10;end&#10;/*&#10;** No parameters, so show all the locks.&#10;*/&#10;else&#10;begin&#10;INSERT #locktable&#10;(&#10;spid&#10;,loginname&#10;,hostname&#10;,dbid&#10;,dbname&#10;,objId&#10;,ObjName&#10;,IndId&#10;,Type&#10;,Resource&#10;,Mode&#10;,Status&#10;)&#10;select convert (smallint, l.req_spid)&#10;&amp;ndash;,coalesce(substring (user_name(req_spid), 1, 20),&amp;rsquo;&amp;rsquo;)&#10;,coalesce(substring (s.loginame, 1, 20),&amp;rsquo;&amp;rsquo;)&#10;,coalesce(substring (s.hostname, 1, 30),&amp;rsquo;&amp;rsquo;)&#10;,l.rsc_dbid&#10;,substring (db_name(l.rsc_dbid), 1, 20)&#10;,l.rsc_objid&#10;,&amp;rsquo;'&#10;,l.rsc_indid&#10;,substring (v.name, 1, 4)&#10;,substring (l.rsc_text, 1, 16)&#10;,substring (u.name, 1, 8)&#10;,substring (x.name, 1, 5)&#10;from master.dbo.syslockinfo l,&#10;master.dbo.spt_values v,&#10;master.dbo.spt_values x,&#10;master.dbo.spt_values u,&#10;master.dbo.sysprocesses s&#10;where l.rsc_type = v.number&#10;and v.type = &amp;lsquo;LR&amp;rsquo;&#10;and l.req_status = x.number&#10;and x.type = &amp;lsquo;LS&amp;rsquo;&#10;and l.req_mode + 1 = u.number&#10;and u.type = &amp;lsquo;L&amp;rsquo;&#10;and req_spid = s.spid&#10;order by spID&#10;END&#10;DECLARE lock_cursor CURSOR&#10;FOR SELECT dbid, ObjId FROM #locktable WHERE Type =&amp;lsquo;TAB&amp;rsquo;&lt;/p&gt;&#10;&lt;p&gt;OPEN lock_cursor&#10;FETCH NEXT FROM lock_cursor INTO @dbid, @ObjId&#10;WHILE @@FETCH_STATUS = 0&#10;BEGIN&#10;SELECT @string =&#10;&amp;lsquo;USE &amp;rsquo; + db_name(@dbid) + char(13)&lt;br&gt;&#10;+ &amp;lsquo;UPDATE #locktable SET ObjName = object_name(&amp;rsquo;&#10;+ convert(varchar(32),@objId) + &amp;lsquo;) WHERE dbid = &amp;rsquo; + convert(varchar(32),@dbId)&#10;+ &amp;rsquo; AND objid = &amp;rsquo; + convert(varchar(32),@objId)&lt;/p&gt;&#10;&lt;p&gt;EXECUTE (@string)&#10;FETCH NEXT FROM lock_cursor INTO @dbid, @ObjId &lt;br&gt;&#10;END&#10;CLOSE lock_cursor&#10;DEALLOCATE lock_cursor&lt;/p&gt;&#10;&lt;p&gt;SELECT * FROM #locktable&#10;DROP TABLE #locktable&lt;/pre&gt;</description></item><item><title>Publish Database Project causing “the script file could not be found”</title><link>https://bryanavery.co.uk/publish-database-project-causing-the-script-file-could-not-be-found/</link><pubDate>Thu, 03 Jan 2013 13:22:00 +0000</pubDate><guid>https://bryanavery.co.uk/publish-database-project-causing-the-script-file-could-not-be-found/</guid><description>&lt;p&gt;If you come across publishing a SQL databse from a Visual Studio Database Project that the “the script file could not be found”, after a lot of digging around I found that all you need to do is delete the .dbmdl file, and it will publish again.&lt;/p&gt;</description></item><item><title>SQL71566 when upgrading to VS12</title><link>https://bryanavery.co.uk/sql71566-when-upgrading-to-vs12/</link><pubDate>Thu, 03 Jan 2013 08:36:00 +0000</pubDate><guid>https://bryanavery.co.uk/sql71566-when-upgrading-to-vs12/</guid><description>&lt;p&gt;In VS 2012 I receive the following error message (one for each table) when trying to build a database project.&lt;/p&gt;&#10;&lt;p&gt;SQL71566: Microsoft.Data.Tools.Schema.Sql.SchemaModel.SqlFilegroup cannot not be set on both the Microsoft.Data.Tools.Schema.Sql.SchemaModel.SqlTable and the clustered Microsoft.Data.Tools.Schema.Sql.SchemaModel.SqlPrimaryKeyConstraint.&lt;/p&gt;&#10;&lt;p&gt;For reference here is script associated with this error.&lt;/p&gt;</description></item></channel></rss>