It is necessary to delete all the tables.

After such a request, part of the tables remain.

Message 911, level 16, state 1, line 1 Database 'DATA-BASE-NAME' does not exist. Make sure that the name is entered correctly.

USE [DATA-BASE-NAME] GO declare @i int set @i = 0 while (@i<99) begin declare @table_name varchar(100) declare table_list cursor for select name from sysobjects o2 where xtype='U' and not exists ( select * from sysforeignkeys k join syscolumns c1 on (k.fkeyid = c1.id and c1.colid=k.fkey) join syscolumns c2 on (k.rkeyid = c2.id and c2.colid=k.rkey) where c2.id = o2.id and c1.id <> o2.id ) open table_list fetch next from table_list into @table_name while @@fetch_status = 0 begin print 'dropping table '+@table_name exec ('drop table '+@table_name) fetch next from table_list into @table_name end close table_list deallocate table_list set @i = @i+1 end GO 
  • one
    But it was not easier to drop the database and create it again? empty ... - Akina
  • @Akina rights should be distributed to mb users. and no one drops the viewport with views (although I’m not good at what is selected here) - teran
  • @teran More than unlikely this is done from the client application (and if done, the SSZB TS). Most likely the almost one-time act of a lazy developer, which will occasionally, but periodically, be repeated. And if so - let through SSMS scripts the necessary objects and after the re-creation will deploy. - Akina

1 answer 1

The error message states:

Verify that the database name entered is correct. And then this does not exist: (

Most likely, it is necessary to replace the first line.

 USE [DATA-BASE-NAME] 

on

 USE [ВВЕДИТЕ ИМЯ БАЗЫ ДАННЫХ] 

that is, replace it with the database name used.

  • it would seem obvious that the author replaced the name of the real database with the data-base-name in the code in question. - teran
  • @teran, nevertheless the answer is correct - vp_arth
  • @vp_arth then I don’t understand how the author removes part of the tables, but not all - teran
  • I think they all don't go away :) - labris