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

Our new SQL Server Forums are live! Come on over! We've restricted the ability to create new threads on these forums.

SQL Server Forums
Profile | 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
 Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

sunny_10
Yak Posting Veteran

72 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
2241 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
Aged Yak Warrior

USA
550 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  
 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.1 seconds. Powered By: Snitz Forums 2000