Solved

How can I see if a table exists in SQL before creating it

Posted on 2010-08-26
8
326 Views
Last Modified: 2012-05-10
Hello guys

I need to create a table in my database, but before creating it, I need to see if there is already this table, how can I do this?

thanks
0
Comment
Question by:hidrau
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
  • 2
8 Comments
 
LVL 41

Accepted Solution

by:
ralmada earned 250 total points
ID: 33532537

IF OBJECT_ID ('yourtable') IS NULL
 create TABLE yourtable ( ....

Open in new window

0
 
LVL 35

Assisted Solution

by:YZlat
YZlat earned 250 total points
ID: 33532546
0
 
LVL 41

Expert Comment

by:ralmada
ID: 33532554
or more appropriately
IF OBJECT_ID (N'yourtable', N'U') IS NULL
      create table (....

Open in new window

0
Edgartown IT Case Study

Learn about Edgartown's quest to ensure the safety and security of the entire town's employee and citizen data. Read the case study!

 
LVL 35

Expert Comment

by:YZlat
ID: 33532573
IF EXISTS (SELECT 1
    FROM INFORMATION_SCHEMA.TABLES
    WHERE TABLE_TYPE='BASE TABLE'
    AND TABLE_NAME='tablename')
        SELECT 'tablename exists.'
ELSE
        --CREATE YOUR TABLE HERE
0
 
LVL 41

Expert Comment

by:ralmada
ID: 33534773
hmmm, I've posted first. what's wrong with my suggestion? Can you please advise?
0
 
LVL 1

Author Comment

by:hidrau
ID: 33534825
I can't believe, I didn't split the point.

I need to reopen the question
0
 
LVL 1

Author Closing Comment

by:hidrau
ID: 33536672
thanks
0

Featured Post

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

by Mark Wills PIVOT is a great facility and solves many an EAV (Entity - Attribute - Value) type transformation where we need the information held as data within a column to become columns in their own right. Now, in some cases that is relatively…
Use this article to create a batch file to backup a Microsoft SQL Server database to a Windows folder.  The folder can be on the local hard drive or on a network share.  This batch file will query the SQL server to get the current date & time and wi…
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.

726 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question