dbTalk Databases Forums  

How to Identify table???

microsoft.public.sqlserver.clients microsoft.public.sqlserver.clients


Discuss How to Identify table??? in the microsoft.public.sqlserver.clients forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Deiny García Pérez
 
Posts: n/a

Default How to Identify table??? - 04-07-2008 , 09:56 AM






my problem is the following...

Sometimes I create table "X" in my database, I meed someting to know if I
have table "X" already created, can you help me with that???

Thank you in advance...



Reply With Quote
  #2  
Old   
Rick Byham, \(MSFT\)
 
Posts: n/a

Default Re: How to Identify table??? - 04-07-2008 , 10:41 AM






If the table is named X, this is the code that Management Studio will create
for you:
SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[X]') AND type
in (N'U')

What do you want to do if the table exists?
If you want to stop the operation, then something like:
IF NOT EXISTS (SELECT * FROM sys.objects
WHERE object_id = OBJECT_ID(N'[dbo].[X]') AND type in (N'U'))
CREATE TABLE X ...

If you want to drop the table and then create table X, then do something
like:
IF EXISTS (SELECT * FROM sys.objects
WHERE object_id = OBJECT_ID(N'[dbo].[X]') AND type in (N'U'))
DROP TABLE [dbo].[X]
GO
CREATE TABLE X ...

--
Rick Byham (MSFT), SQL Server Books Online
This posting is provided "AS IS" with no warranties, and confers no rights.

"Deiny García Pérez" <deiny (AT) nnn (DOT) com> wrote

Quote:
my problem is the following...

Sometimes I create table "X" in my database, I meed someting to know if I
have table "X" already created, can you help me with that???

Thank you in advance...



Reply With Quote
  #3  
Old   
Rick Byham, \(MSFT\)
 
Posts: n/a

Default Re: How to Identify table??? - 04-07-2008 , 10:41 AM



If the table is named X, this is the code that Management Studio will create
for you:
SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[X]') AND type
in (N'U')

What do you want to do if the table exists?
If you want to stop the operation, then something like:
IF NOT EXISTS (SELECT * FROM sys.objects
WHERE object_id = OBJECT_ID(N'[dbo].[X]') AND type in (N'U'))
CREATE TABLE X ...

If you want to drop the table and then create table X, then do something
like:
IF EXISTS (SELECT * FROM sys.objects
WHERE object_id = OBJECT_ID(N'[dbo].[X]') AND type in (N'U'))
DROP TABLE [dbo].[X]
GO
CREATE TABLE X ...

--
Rick Byham (MSFT), SQL Server Books Online
This posting is provided "AS IS" with no warranties, and confers no rights.

"Deiny García Pérez" <deiny (AT) nnn (DOT) com> wrote

Quote:
my problem is the following...

Sometimes I create table "X" in my database, I meed someting to know if I
have table "X" already created, can you help me with that???

Thank you in advance...



Reply With Quote
  #4  
Old   
Rick Byham, \(MSFT\)
 
Posts: n/a

Default Re: How to Identify table??? - 04-07-2008 , 10:41 AM



If the table is named X, this is the code that Management Studio will create
for you:
SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[X]') AND type
in (N'U')

What do you want to do if the table exists?
If you want to stop the operation, then something like:
IF NOT EXISTS (SELECT * FROM sys.objects
WHERE object_id = OBJECT_ID(N'[dbo].[X]') AND type in (N'U'))
CREATE TABLE X ...

If you want to drop the table and then create table X, then do something
like:
IF EXISTS (SELECT * FROM sys.objects
WHERE object_id = OBJECT_ID(N'[dbo].[X]') AND type in (N'U'))
DROP TABLE [dbo].[X]
GO
CREATE TABLE X ...

--
Rick Byham (MSFT), SQL Server Books Online
This posting is provided "AS IS" with no warranties, and confers no rights.

"Deiny García Pérez" <deiny (AT) nnn (DOT) com> wrote

Quote:
my problem is the following...

Sometimes I create table "X" in my database, I meed someting to know if I
have table "X" already created, can you help me with that???

Thank you in advance...



Reply With Quote
  #5  
Old   
Rick Byham, \(MSFT\)
 
Posts: n/a

Default Re: How to Identify table??? - 04-07-2008 , 10:41 AM



If the table is named X, this is the code that Management Studio will create
for you:
SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[X]') AND type
in (N'U')

What do you want to do if the table exists?
If you want to stop the operation, then something like:
IF NOT EXISTS (SELECT * FROM sys.objects
WHERE object_id = OBJECT_ID(N'[dbo].[X]') AND type in (N'U'))
CREATE TABLE X ...

If you want to drop the table and then create table X, then do something
like:
IF EXISTS (SELECT * FROM sys.objects
WHERE object_id = OBJECT_ID(N'[dbo].[X]') AND type in (N'U'))
DROP TABLE [dbo].[X]
GO
CREATE TABLE X ...

--
Rick Byham (MSFT), SQL Server Books Online
This posting is provided "AS IS" with no warranties, and confers no rights.

"Deiny García Pérez" <deiny (AT) nnn (DOT) com> wrote

Quote:
my problem is the following...

Sometimes I create table "X" in my database, I meed someting to know if I
have table "X" already created, can you help me with that???

Thank you in advance...



Reply With Quote
  #6  
Old   
Rick Byham, \(MSFT\)
 
Posts: n/a

Default Re: How to Identify table??? - 04-07-2008 , 10:41 AM



If the table is named X, this is the code that Management Studio will create
for you:
SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[X]') AND type
in (N'U')

What do you want to do if the table exists?
If you want to stop the operation, then something like:
IF NOT EXISTS (SELECT * FROM sys.objects
WHERE object_id = OBJECT_ID(N'[dbo].[X]') AND type in (N'U'))
CREATE TABLE X ...

If you want to drop the table and then create table X, then do something
like:
IF EXISTS (SELECT * FROM sys.objects
WHERE object_id = OBJECT_ID(N'[dbo].[X]') AND type in (N'U'))
DROP TABLE [dbo].[X]
GO
CREATE TABLE X ...

--
Rick Byham (MSFT), SQL Server Books Online
This posting is provided "AS IS" with no warranties, and confers no rights.

"Deiny García Pérez" <deiny (AT) nnn (DOT) com> wrote

Quote:
my problem is the following...

Sometimes I create table "X" in my database, I meed someting to know if I
have table "X" already created, can you help me with that???

Thank you in advance...



Reply With Quote
  #7  
Old   
Rick Byham, \(MSFT\)
 
Posts: n/a

Default Re: How to Identify table??? - 04-07-2008 , 10:41 AM



If the table is named X, this is the code that Management Studio will create
for you:
SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[X]') AND type
in (N'U')

What do you want to do if the table exists?
If you want to stop the operation, then something like:
IF NOT EXISTS (SELECT * FROM sys.objects
WHERE object_id = OBJECT_ID(N'[dbo].[X]') AND type in (N'U'))
CREATE TABLE X ...

If you want to drop the table and then create table X, then do something
like:
IF EXISTS (SELECT * FROM sys.objects
WHERE object_id = OBJECT_ID(N'[dbo].[X]') AND type in (N'U'))
DROP TABLE [dbo].[X]
GO
CREATE TABLE X ...

--
Rick Byham (MSFT), SQL Server Books Online
This posting is provided "AS IS" with no warranties, and confers no rights.

"Deiny García Pérez" <deiny (AT) nnn (DOT) com> wrote

Quote:
my problem is the following...

Sometimes I create table "X" in my database, I meed someting to know if I
have table "X" already created, can you help me with that???

Thank you in advance...



Reply With Quote
  #8  
Old   
Rick Byham, \(MSFT\)
 
Posts: n/a

Default Re: How to Identify table??? - 04-07-2008 , 10:41 AM



If the table is named X, this is the code that Management Studio will create
for you:
SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[X]') AND type
in (N'U')

What do you want to do if the table exists?
If you want to stop the operation, then something like:
IF NOT EXISTS (SELECT * FROM sys.objects
WHERE object_id = OBJECT_ID(N'[dbo].[X]') AND type in (N'U'))
CREATE TABLE X ...

If you want to drop the table and then create table X, then do something
like:
IF EXISTS (SELECT * FROM sys.objects
WHERE object_id = OBJECT_ID(N'[dbo].[X]') AND type in (N'U'))
DROP TABLE [dbo].[X]
GO
CREATE TABLE X ...

--
Rick Byham (MSFT), SQL Server Books Online
This posting is provided "AS IS" with no warranties, and confers no rights.

"Deiny García Pérez" <deiny (AT) nnn (DOT) com> wrote

Quote:
my problem is the following...

Sometimes I create table "X" in my database, I meed someting to know if I
have table "X" already created, can you help me with that???

Thank you in advance...



Reply With Quote
  #9  
Old   
Rick Byham, \(MSFT\)
 
Posts: n/a

Default Re: How to Identify table??? - 04-07-2008 , 10:41 AM



If the table is named X, this is the code that Management Studio will create
for you:
SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[X]') AND type
in (N'U')

What do you want to do if the table exists?
If you want to stop the operation, then something like:
IF NOT EXISTS (SELECT * FROM sys.objects
WHERE object_id = OBJECT_ID(N'[dbo].[X]') AND type in (N'U'))
CREATE TABLE X ...

If you want to drop the table and then create table X, then do something
like:
IF EXISTS (SELECT * FROM sys.objects
WHERE object_id = OBJECT_ID(N'[dbo].[X]') AND type in (N'U'))
DROP TABLE [dbo].[X]
GO
CREATE TABLE X ...

--
Rick Byham (MSFT), SQL Server Books Online
This posting is provided "AS IS" with no warranties, and confers no rights.

"Deiny García Pérez" <deiny (AT) nnn (DOT) com> wrote

Quote:
my problem is the following...

Sometimes I create table "X" in my database, I meed someting to know if I
have table "X" already created, can you help me with that???

Thank you in advance...



Reply With Quote
  #10  
Old   
Rick Byham, \(MSFT\)
 
Posts: n/a

Default Re: How to Identify table??? - 04-07-2008 , 10:41 AM



If the table is named X, this is the code that Management Studio will create
for you:
SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[X]') AND type
in (N'U')

What do you want to do if the table exists?
If you want to stop the operation, then something like:
IF NOT EXISTS (SELECT * FROM sys.objects
WHERE object_id = OBJECT_ID(N'[dbo].[X]') AND type in (N'U'))
CREATE TABLE X ...

If you want to drop the table and then create table X, then do something
like:
IF EXISTS (SELECT * FROM sys.objects
WHERE object_id = OBJECT_ID(N'[dbo].[X]') AND type in (N'U'))
DROP TABLE [dbo].[X]
GO
CREATE TABLE X ...

--
Rick Byham (MSFT), SQL Server Books Online
This posting is provided "AS IS" with no warranties, and confers no rights.

"Deiny García Pérez" <deiny (AT) nnn (DOT) com> wrote

Quote:
my problem is the following...

Sometimes I create table "X" in my database, I meed someting to know if I
have table "X" already created, can you help me with that???

Thank you in advance...



Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.