473,406 Members | 2,867 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

Function to see if Table exists in sql server

22
Trying to build a function to see if table exists and if it doesn't then create that table!

Help would be greatly appreciated!
Jan 10 '08 #1
2 6301
ck9663
2,878 Expert 2GB
Trying to build a function to see if table exists and if it doesn't then create that table!

Help would be greatly appreciated!

lots of ways...one of them:

if not exists (select 1 from sysobjects where name = @mytableparametername)
begin
create table ....

or you can also do a..

select * newtablename from blanktemplatetable

or

set @sqlstring = ('create table ' + @mytableparametername + '.....')

exec (@sqlstring)

or

set @sqlstring = ('select * into ' + @mytableparametername + ' from blanktemplatetable')
exec (@sqlstring)

end


this is obviously a pseudo-code...but i hope you get the idea...

-- CK
Jan 10 '08 #2
Barno77
22
lots of ways...one of them:

if not exists (select 1 from sysobjects where name = @mytableparametername)
begin
create table ....

or you can also do a..

select * newtablename from blanktemplatetable

or

set @sqlstring = ('create table ' + @mytableparametername + '.....')

exec (@sqlstring)

or

set @sqlstring = ('select * into ' + @mytableparametername + ' from blanktemplatetable')
exec (@sqlstring)

end


this is obviously a pseudo-code...but i hope you get the idea...

-- CK
Yes, I understand thank you!
Jan 10 '08 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: Jonas Asberg | last post by:
Hi, I got a new SQL Server database and are in the process of porting my Access databases to my new SQL Server. I have worked with Access and Oracle in the past but I am new to the SQL Server...
4
by: Robin Tucker | last post by:
Hi, I'm trying to determine with my program whether or not a given database supports a given feature set. To do this I'm querying for certain stored procedures in the sysobjects table and if...
3
by: teddysnips | last post by:
In the script below is the DDL to create some tables and a UDF. What I'm interested in is the UDF at the end. Specifically, these few lines: --CLOSE OTRate --DEALLOCATE OTRate ELSE --...
11
by: Jules Alberts | last post by:
Hello everybody, Someone helped me earlier with this TCL trigger function: create or replace function tlow() returns trigger as ' set NEW($1) return ' language 'pltcl'; I use it to force...
1
by: Lauren Quantrell | last post by:
I have read the newsgroups and see this is a common issue but I saw no resolution for it: I have an Access2K frotn end and SQL Server 2K backend. In access, I create a temp table using code in a...
8
by: David | last post by:
Hi, Could someone please xplain how to add a field to an existing SQL table in VB.Net I have added the field in the Server Explorer and it shows up when I reload the program but I cannot...
11
by: sara | last post by:
I am trying my first functions in my code. I have a set of queries that runs to create temp tables with the right data for some reports. They can run for a long time, so I want the user to know...
4
by: serge | last post by:
Lately I did a mass update on all our scripts and added dbo. in front of all tables and other objects. There is a function that returns a table and the function is I think 300 lines. There are a...
8
by: bob | last post by:
I am writing some code to create new tables in a SQL database. However, I don't want to try to create a table if it already exists. How can I test beforehand to see if a particular named table...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.