Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

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

Posted on 2010-08-26
8
Medium Priority
?
329 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 1000 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 1000 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
Learn Veeam advantages over legacy backup

Every day, more and more legacy backup customers switch to Veeam. Technologies designed for the client-server era cannot restore any IT service running in the hybrid cloud within seconds. Learn top Veeam advantages over legacy backup and get Veeam for the price of your renewal

 
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

What’s Wrong with Your Cloud Strategy ?

Even as many CIOs are embracing a cloud-first strategy, the reality is that moving to the cloud is a lengthy process and the end-state is likely to be a blend of multiple clouds—public and private. Learn why multicloud solutions matter in this webinar by Nimble Storage.

Question has a verified solution.

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

Introduction This article will provide a solution for an error that might occur installing a new SQL 2005 64-bit cluster. This article will assume that you are fully prepared to complete the installation and describes the error as it occurred durin…
INTRODUCTION: While tying your database objects into builds and your enterprise source control system takes a third-party product (like Visual Studio Database Edition or Red-Gate's SQL Source Control), you can achieve some protection using a sing…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…

636 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