Delete all tables from a SQL database using Transact SQL Cursors

If you have a SQL2016 database but only SQL 2008R2 SSMS then you can’t delete tables with extreme prejudice using the DEL key, you get an error something like “index out of range”.

However this SQL will do the same job.

Just remember, it’s your foot…

From an idea from Richard…

declare @sql nvarchar(2048)
declare @tn nvarchar(200)

declare tablecursor cursor
select name from sys.tables
open tablecursor
fetch next from tablecursor into @tn
while @@FETCH_STATUS=0
print @tn
declare fkcursor cursor
‘ALTER TABLE [‘ + OBJECT_SCHEMA_NAME(parent_object_id) +
‘].[‘ + OBJECT_NAME(parent_object_id) +
‘] DROP CONSTRAINT [‘ + name + ‘]’
FROM sys.foreign_keys
WHERE referenced_object_id = object_id(@tn)
open fkcursor
fetch next from fkcursor into @sql
while @@fetch_status = 0
print @sql
fetch next from fkcursor into @sql
close fkcursor;
deallocate fkcursor

set @sql = ‘drop table ‘ + @tn

fetch next from tablecursor into @tn


Visual Studio 2017: Program in Invalid State: disable javascript debugging

With VS2017 and an project, you may get “Cannot start program, it’s in an invalid state”. This may be related to “enable javascript debugging for (chrome and ie)”.

Try restarting Chrome, IE or Edge.

Try turning off javascript debugging: in the quick launch bar type “javascript debugging” and enter. This takes you to Tools-Options-Debugging-General. FindĀ “enable javascript debugging for (chrome and ie)” and untick it.