Login or Sign Up
Logging in...
Remember me
Log in
Or
Sign Up
Forgot password or user name?
Log in with
Search in titles only
Search in SQL Server only
Search
Advanced Search
Forums
Product Launch
Updates
Today's Posts
Member List
Calendar
Home
Forum
Topic
SQL Server
Function to see if Table exists in sql server
Collapse
X
Collapse
Posts
Latest Activity
Photos
Page
of
1
Filter
Time
All Time
Today
Last Week
Last Month
Show
All
Discussions only
Photos only
Videos only
Links only
Polls only
Events only
Filtered by:
Clear All
new posts
Previous
template
Next
Barno77
New Member
Join Date:
Oct 2007
Posts:
22
#1
Function to see if Table exists in sql server
Jan 10 '08, 04:26 PM
Trying to build a function to see if table exists and if it doesn't then create that table!
Help would be greatly appreciated!
ck9663
Recognized Expert
Specialist
Join Date:
Jun 2007
Posts:
2878
#2
Jan 10 '08, 05:35 PM
Originally posted by
Barno77
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 = @mytableparamet ername)
begin
create table ....
or you can also do a..
select * newtablename from blanktemplateta ble
or
set @sqlstring = ('create table ' + @mytableparamet ername + '.....')
exec (@sqlstring)
or
set @sqlstring = ('select * into ' + @mytableparamet ername + ' from blanktemplateta ble')
exec (@sqlstring)
end
this is obviously a pseudo-code...but i hope you get the idea...
-- CK
Comment
Post
Cancel
Barno77
New Member
Join Date:
Oct 2007
Posts:
22
#3
Jan 10 '08, 06:18 PM
Originally posted by
ck9663
lots of ways...one of them:
if not exists (select 1 from sysobjects where name = @mytableparamet ername)
begin
create table ....
or you can also do a..
select * newtablename from blanktemplateta ble
or
set @sqlstring = ('create table ' + @mytableparamet ername + '.....')
exec (@sqlstring)
or
set @sqlstring = ('select * into ' + @mytableparamet ername + ' from blanktemplateta ble')
exec (@sqlstring)
end
this is obviously a pseudo-code...but i hope you get the idea...
-- CK
Yes, I understand thank you!
Comment
Post
Cancel
Previous
template
Next
Working...
Yes
No
OK
OK
Cancel
👍
👎
☕
Comment