Solved

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

Posted on 2010-08-26
8
322 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
  • 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
Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

 
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

Suggested Solutions

Title # Comments Views Activity
SQL help 5 51
Testing connection to sql 7 58
passing parameter in sql procedure 9 56
Selection from table2 where criteria for table1 10 32
This article will describe one method to parse a delimited string into a table of data.   Why would I do that you ask?  Let's say that you need to pass multiple parameters into a stored procedure to search for.  For our sake, we'll say that we wa…
I am showing a way to read/import the excel data in table using SQL server 2005... Suppose there is an Excel file "Book1" at location "C:\temp" with column "First Name" and "Last Name". Now to import this Excel data into the table, we will use…
This is used to tweak the memory usage for your computer, it is used for servers more so than workstations but just be careful editing registry settings as it may cause irreversible results. I hold no responsibility for anything you do to the regist…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

920 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now