Avatar of Mark
Mark
 asked on

SQL Server 2014 - How to list a view

How can I list a view in SQL Server 2014? In SQL Sever 2015 it was sp_helptext @objname = 'myview'. That doesn't work in 2014. I get the error "There is no text for object 'myview'"
Microsoft SQL Server

Avatar of undefined
Last Comment
Mark

8/22/2022 - Mon
Jim Horn

Define 'list a view'.  Perhaps..
SELECT * FROM sys.views

Open in new window

Mark

ASKER
No, I'm looking for a list of views. I'm looking for how to list the "create view ..." etc. of a given view.
Vitor Montalvão

I get the error "There is no text for object 'myview'"
Did you run the command in the correct database? Also, verify if you added the schema name.
use databasename
go
sp_helptext @objname = 'schema.myview'

Open in new window

Your help has saved me hundreds of hours of internet surfing.
fblack61
Mark

ASKER
Well, here's the interesting thing. When I run the sp_helptext in the Server Management Studio, it works. When I run it from a remote host inside an java program I get:

Select Failed: 15197 There is no text for object 'myview'

This is true whether I use a Microsoft jdbc driver or a 3rd party driver.

However, if I run the same procedure from the same java program connecting to the SQL Server 2005 database, it works.

Thoughts?
ASKER CERTIFIED SOLUTION
Vitor Montalvão

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
Mark

ASKER
Ah ha! That's the problem. I ran using 'sa' in SSMS, but a normal user in the java program. When I ran as 'sa' with the java program, it worked.

Now I just have to give VIEW DEFINITION priv to the normal user.
Mark

ASKER
Yup, I did "grant view definition to public" and that solved the problem. Thanks!
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.