SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 Database & Tables
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

sunny_10
Yak Posting Veteran

65 Posts

Posted - 03/18/2013 :  00:47:45  Show Profile  Reply with Quote
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
Flowing Fount of Yak Knowledge

India
2206 Posts

Posted - 03/18/2013 :  01:06:12  Show Profile  Reply with Quote
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

Edited by - bandi on 03/19/2013 00:55:45
Go to Top of Page

ScottPletcher
Constraint Violating Yak Guru

USA
364 Posts

Posted - 03/18/2013 :  18:05:24  Show Profile  Reply with Quote

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


Edited by - ScottPletcher on 03/18/2013 18:05:52
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.06 seconds. Powered By: Snitz Forums 2000