Solved

VB.net SQL Distinguish between a table and a view

Posted on 2014-10-24
5
127 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:murbro
[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 65

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 65

Expert Comment

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

Author Comment

by:murbro
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:murbro
ID: 40404495
Thank you both
0

Featured Post

Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

Question has a verified solution.

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

This article shows gives you an overview on SQL Server 2016 row level security. You will also get to know the usages of row-level-security and how it works
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 ?
Via a live example combined with referencing Books Online, show some of the information that can be extracted from the Catalog Views in SQL Server.
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function

752 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