Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 Database & Tables

Author  Topic 

sunny_10
Yak Posting Veteran

72 Posts

Posted - 2013-03-18 : 00:47:45
Hi

I want to check whether Database exists or not , if not then i want to create Database & tables . How this can be done . I want this through Visual Basic.

Thanks

bandi
Master Smack Fu Yak Hacker

2242 Posts

Posted - 2013-03-18 : 01:06:12
This is in SQL Server

IF NOT EXISTS (SELECT * FROM sys.databases where name = 'DBName')
CREATE DATABASE DBName;
GO
USE DBName
GO
CREATE TABLE ..............

--
Chandu
Go to Top of Page

ScottPletcher
Aged Yak Warrior

550 Posts

Posted - 2013-03-18 : 18:05:24
[code]
IF NOT EXISTS (SELECT name FROM sys.databases where name = 'db_name')
BEGIN
CREATE DATABASE db_name;
CREATE TABLE db_name.dbo.table_name1 ( .... )
CREATE TABLE db_name.dbo.table_name2 ( .... )
END --IF
GO
[/code]
Go to Top of Page
   

- Advertisement -