Solved

VB.net SQL Distinguish between a table and a view

Posted on 2014-10-24
5
130 Views
Last Modified: 2014-10-25
Hi

Is it possible to distinguish between a table and a view programmatically?
What VB.net code would I use?
Thanks
0
Comment
Question by:Murray Brown
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
5 Comments
 
LVL 66

Assisted Solution

by:Jim Horn
Jim Horn earned 250 total points
ID: 40402574
No idea about a VB.net answer, but the T-SQL answer would be...
SELECT name, 
   CASE type 
      WHEN 'U' THEN 'Table' 
      WHEN 'V' THEN 'View' 
      ELSE 'Something Else' END as object_type
FROM sys.objects  
WHERE type IN ('U', 'V') 
   and name = 'object name goes here'

Open in new window

0
 
LVL 66

Expert Comment

by:Jim Horn
ID: 40402782
{Potentially stupid question}  Why do you ask?
0
 

Author Comment

by:Murray Brown
ID: 40402884
Hi Jim
I have spent the last 3 years building an Excel add-in that is used to edit SQL data.
All the tables and views in a SQL database are loaded to a TreeView where the user
can manipulate them. When they  click on an item to edit I want the code to distinguish between a table and view
0
 
LVL 40

Accepted Solution

by:
Jacques Bourgeois (James Burger) earned 250 total points
ID: 40403497
You can execute the following SQL command against the system tables:

SELECT xtype FROM sysobjects WHERE name='YourObjectName'

The result will be U for a table (User Table) or V for a View.
0
 

Author Closing Comment

by:Murray Brown
ID: 40404495
Thank you both
0

Featured Post

Free learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this article we will learn how to fix  “Cannot install SQL Server 2014 Service Pack 2: Unable to install windows installer msi file” error ?
What if you have to shut down the entire Citrix infrastructure for hardware maintenance, software upgrades or "the unknown"? I developed this plan for "the unknown" and hope that it helps you as well. This article explains how to properly shut down …
Using examples as well as descriptions, and references to Books Online, show the different Recovery Models available in SQL Server and explain, as well as show how full, differential and transaction log backups are performed
Using examples as well as descriptions, and references to Books Online, show the documentation available for datatypes, explain the available data types and show how data can be passed into and out of variables.

635 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