Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 138
  • Last Modified:

VB.net SQL Distinguish between a table and a view

Hi

Is it possible to distinguish between a table and a view programmatically?
What VB.net code would I use?
Thanks
0
Murray Brown
Asked:
Murray Brown
  • 2
  • 2
2 Solutions
 
Jim HornMicrosoft SQL Server Developer, Architect, and AuthorCommented:
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
 
Jim HornMicrosoft SQL Server Developer, Architect, and AuthorCommented:
{Potentially stupid question}  Why do you ask?
0
 
Murray BrownMicrosoft Cloud Azure/Excel Solution DeveloperAuthor Commented:
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
 
Jacques Bourgeois (James Burger)PresidentCommented:
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
 
Murray BrownMicrosoft Cloud Azure/Excel Solution DeveloperAuthor Commented:
Thank you both
0

Featured Post

Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now