473,545 Members | 2,011 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

how to check existance of a table in sql server?

Dan
Hello,

we have an intranet application using Windows Integrated Authentificatio n.
When an user starts the application, he gets a form for inputting data. The
first time he does that, the application creates in a specific database a
table with the name of his account (read with
Request.ServerV ariables("remot e_user") and creates in that table the records
he enters. From the second time the user starts the application, still the
same form appears but the table may not be recreated.
How can i check in code-behind (VB) whether that table (e.g. table 'dan'
exists)?

Thanks
Dan
Jul 7 '07 #1
14 2113
"Dan" <d@er.dfwrote in message
news:O2******** ******@TK2MSFTN GP03.phx.gbl...
How can i check in code-behind (VB) whether that table (e.g. table 'dan'
exists)?
Since you don't mention what back-end RDBMS you're using, I'll assume it's
SQL Server...

Whatever method you're using to connect to the RDBMS, use the ADO.NET
ExecuteScaler method on the following SQL:

SELECT COUNT(*) FROM sys.tables WHERE [name] = 'dan' AND [type] = 'U'

If ExecuteScalar returns 1, the table exists - if it returns 0, it
doesn't...

There must be at least half a dozen other ways of doing this...
--
Mark Rae
ASP.NET MVP
http://www.markrae.net

Jul 7 '07 #2

"Dan" <d@er.dfwrote in message
news:O2******** ******@TK2MSFTN GP03.phx.gbl...
Hello,

we have an intranet application using Windows Integrated Authentificatio n.
When an user starts the application, he gets a form for inputting data.
The first time he does that, the application creates in a specific
database a table with the name of his account (read with
Request.ServerV ariables("remot e_user") and creates in that table the
records he enters. From the second time the user starts the application,
still the same form appears but the table may not be recreated.
How can i check in code-behind (VB) whether that table (e.g. table 'dan'
exists)?
You make a stored procedure and ask the question.

If exist(tablename )

The stored procedure returns a Return code of zero if it's there or non-zero
if it's not there, which you'll check in code the return code that you have
set and returned, taking take the appropriate action.

Use Google where you can ask *How to check if a SQL Table Exist* or
something along those lines. Also look up *How to get a output parm or
return code from a Stored Procedure using ADO.NET* or something along those
lines.

Jul 7 '07 #3
Dan
Thanks to you two

"Mr. Arnold" <MR. Ar****@Arnold.c omschreef in bericht
news:ON******** ********@TK2MSF TNGP03.phx.gbl. ..
>
"Dan" <d@er.dfwrote in message
news:O2******** ******@TK2MSFTN GP03.phx.gbl...
>Hello,

we have an intranet application using Windows Integrated
Authentificati on. When an user starts the application, he gets a form for
inputting data. The first time he does that, the application creates in a
specific database a table with the name of his account (read with
Request.Server Variables("remo te_user") and creates in that table the
records he enters. From the second time the user starts the application,
still the same form appears but the table may not be recreated.
How can i check in code-behind (VB) whether that table (e.g. table 'dan'
exists)?

You make a stored procedure and ask the question.

If exist(tablename )

The stored procedure returns a Return code of zero if it's there or
non-zero if it's not there, which you'll check in code the return code
that you have set and returned, taking take the appropriate action.

Use Google where you can ask *How to check if a SQL Table Exist* or
something along those lines. Also look up *How to get a output parm or
return code from a Stored Procedure using ADO.NET* or something along
those lines.

Jul 7 '07 #4
If exists(Tablenam e) does not work in this case. That has to be a legitimate
query, not a "sysobject" . Mark's solution would be the preferred one to me.
-- Peter
Site: http://www.eggheadcafe.com
UnBlog: http://petesbloggerama.blogspot.com
BlogMetaFinder( BETA): http://www.blogmetafinder.com

"Mr. Arnold" wrote:
>
"Dan" <d@er.dfwrote in message
news:O2******** ******@TK2MSFTN GP03.phx.gbl...
Hello,

we have an intranet application using Windows Integrated Authentificatio n.
When an user starts the application, he gets a form for inputting data.
The first time he does that, the application creates in a specific
database a table with the name of his account (read with
Request.ServerV ariables("remot e_user") and creates in that table the
records he enters. From the second time the user starts the application,
still the same form appears but the table may not be recreated.
How can i check in code-behind (VB) whether that table (e.g. table 'dan'
exists)?

You make a stored procedure and ask the question.

If exist(tablename )

The stored procedure returns a Return code of zero if it's there or non-zero
if it's not there, which you'll check in code the return code that you have
set and returned, taking take the appropriate action.

Use Google where you can ask *How to check if a SQL Table Exist* or
something along those lines. Also look up *How to get a output parm or
return code from a Stored Procedure using ADO.NET* or something along those
lines.

Jul 8 '07 #5

"Peter Bromberg [C# MVP]" <pb*******@yaho o.yabbadabbadoo .comwrote in
message news:36******** *************** ***********@mic rosoft.com...
If exists(Tablenam e) does not work in this case. That has to be a
legitimate
query, not a "sysobject" . Mark's solution would be the preferred one to
me.
What? Do you think I am going to rattle this stuff off the top of my head?
The OP has got the point, and I am sure the OP will find it, the solution,
after being given a little push. That's all it was and nothing else. I am
not going to worry about something as trivial as this.

Jul 8 '07 #6
Mark Rae [MVP] wrote:
[...]
SELECT COUNT(*) FROM sys.tables WHERE [name] = 'dan' AND [type] = 'U'
[...]
There must be at least half a dozen other ways of doing this...
A better one IMO is to use the INFORMATION_SCH EMA views.

\\\
select *
from INFORMATION_SCH EMA.Tables
where TABLE_NAME = 'dan'
///

This is an ANSI standard (http://en.wikipedia.org/wiki/Information_Schema).
No directly accessing system tables, no "magic" codes (why does 'type' need
to be set to 'U'?), won't break on future versions of SQL Server and also
works on other RDBMSs.

There are lots of other INFORMATION_SCH EMA views that give access to
columns, views, constraints, stored procedures, etc. To see them all, take a
look at the views that are defined against the master database on your
server.

HTH,

--

(O)enone
Jul 8 '07 #7
"(O)enone" <oe****@nowhere .comwrote in message
news:H_******** *********@newsf e1-gui.ntli.net...
This is an ANSI standard
(http://en.wikipedia.org/wiki/Information_Schema).
Indeed.
won't break on future versions of SQL Server
You can't know that for sure...
and also works on other RDBMSs.
Apart from the ones which don't support it, e.g. Oracle, Jet etc:
http://www.databasejournal.com/news/article.php/3686366
http://www.thescripts.com/forum/thread199615.html
--
Mark Rae
ASP.NET MVP
http://www.markrae.net

Jul 8 '07 #8
Mark Rae [MVP] wrote:
>won't break on future versions of SQL Server

You can't know that for sure...
Maybe not, but I think it's a much safer bet than selecting from system
tables. If MS decide to reorganise the internals of SQL Server (and I'm sure
it's a possibility!), I would certainly hope they would ensure that the
INFORMATION_SCH EMA views keep working. And if not, it would be much easier
to modify they to maintain their previous functionality than to fix every
bit of code that selected from the system tables directly.

--

(O)enone
Jul 8 '07 #9
You know, people make mistakes. I certainly do. But acting like you're from
another planet doesn't add much clarity to the thread, IMHO.
Cheers.
--
Site: http://www.eggheadcafe.com
UnBlog: http://petesbloggerama.blogspot.com
BlogMetaFinder( BETA): http://www.blogmetafinder.com

"Mr. Arnold" wrote:
>
"Peter Bromberg [C# MVP]" <pb*******@yaho o.yabbadabbadoo .comwrote in
message news:36******** *************** ***********@mic rosoft.com...
If exists(Tablenam e) does not work in this case. That has to be a
legitimate
query, not a "sysobject" . Mark's solution would be the preferred one to
me.

What? Do you think I am going to rattle this stuff off the top of my head?
The OP has got the point, and I am sure the OP will find it, the solution,
after being given a little push. That's all it was and nothing else. I am
not going to worry about something as trivial as this.

Jul 8 '07 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
2717
by: Patrick Kowalzick | last post by:
Hello all, I want to test run-time if a template function for a special type exists. See example below. The checkfoo function is where I need some hints. Regards, Patrick #include <iostream>
4
4398
by: KathyB | last post by:
Sorry this is a bit of a repost because I wasn't quite accurate in my original. I have an hmtl page with a function to see if there are any input type=text boxes. If so, that means a user did not complete them (once entered, my xsl stylesheet makes them text instead of text input boxes, so there should be NO input text boxes when the user...
7
1846
by: Ajit | last post by:
Is there anyway to check for existance of a file on different machine. i.e. we have a data file (text file) thats stored on some other machine as its not to be exposed in case the web server is hacked. and we want to update data from this text file into our database. I know file object but it works only locally.(i.e. work with files stored...
3
14930
by: Anthony Bowman | last post by:
Hello, I have a access application that resides locally on users desk, I am writing a VB.Net interface that let's the users pull data down from a SQL server database and populate the local access database with that data, I need to check the local access database to see if there is already a table with the name the users give. Anyone run...
2
7463
by: UJ | last post by:
I'm getting a dataset back from a web service and I want to verify that the table I want exists before trying to access it (which will cause an exception.) Is there an easy way to check for a specific table in my dataset without doing a try/catch or is that the easiest way? TIA - Jeff.
1
13638
by: jaya_rath | last post by:
Check table's existance -------------------------------------------------------------------------------- How can I check if a table exists in an MS SQL database using asp.plz help me . advance thanx <% Option Explicit %> <% Response.Buffer=True %> <!--#include File ="Include/Connection.asp" -->
10
8016
by: Dieter Pelz | last post by:
Hallo, what is the best way to check the installation of mfc80 and vcrt sidebyside assemblies? Best Regards, Dieter Pelz
14
1699
by: Dan | last post by:
Hello, we have an intranet application using Windows Integrated Authentification. When an user starts the application, he gets a form for inputting data. The first time he does that, the application creates in a specific database a table with the name of his account (read with Request.ServerVariables("remote_user") and creates in that table...
1
1396
by: Cirene | last post by:
Using VB.NET (latest version) I want to log onto an FTP server and check for the existance of 10 files in 3 different directories. I would prefer to do this over 1 live connection. Anyone have any sample code that does this? (The code samples that I've seen connects via a FtpWebRequest to a specific URI (which includes a filename) and just...
0
7409
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7921
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7437
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7771
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
4958
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3465
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3446
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1900
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1023
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.