Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

VB.net SQL Distinguish between a table and a view

Posted on 2014-10-24
5
Medium Priority
?
134 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 1000 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 1000 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

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 …
Via a live example, show how to extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.
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

704 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