Monday, December 11, 2017

SQL SERVER - How check if database exists

Use this script code:
use master;

/* -- define DB name */

declare @database_name nvarchar( max );  
set @database_name = 'framework'; 

/* -- check if DB exists yet */

if db_id( @database_name ) is not null
begin
  print 'DB exists.';
  /* db exists -> end */
  return;
end;
...

No comments:

Post a Comment