October 22, 2006 at 9:43 pm
Hi, the issue is that we have a number of views where their view name does not match the name of the actual view. For example the view name in Enterprise Manager is MYTEST_tvMARA_MATKL_IsNullOrBlankSel. However the actual view is as follows.
CREATE VIEW dbo.[TEST tvMARA_MATKL_IsNullOrBlankSel]
AS
SELECT ZSource, MATKL, MATNR, MTART
FROM dbo.ttMARA
WHERE (MATKL = N'') OR
(MATKL IS NULL)
As you can see, the names do not match. Apparently there a heaps just like this. Please don't ask why, I've been assigned the problem of fixing it. Now I know that I can simply re-save the view and it will do this automatically.
But before that, I would like to know a way that you could find ALL the view that have different names and also if there is a short-cut way to enable me to re-synchronise the name with the actual view?
Thanks,
Ged
October 23, 2006 at 12:27 am
Hi..
What does Query Analzer say about the view names?
What does select * from information_schema.views return?
What tool did you use to give you that code? Scripting from Enterprise Manager, Query Analyzer or something else?
I don't often use Enterprise Manager for view & stored proc creation - only use it for table maintenance via diagrams so I'm not sure if what you're describing is possible (spose it must be) and what might cause it. Is there a way to change the way the views are listed in Enterprise Manager? For example, Windows explorer lets you view things as icons (yuk) or as details (nicer). Perhaps, if you can change the way things are listed, the method of listing is confusing and might be including the view's owner (although your script says dbo).
With answers to the above questions I, or someone else, may be better able to help.
Cheers,
Ian
October 24, 2006 at 6:34 am
I've seen this before; it is caused by editing the name directly in Enterprise manager, and not via drop create/alter statements;
to prove it:
go to enterprise manager and find any view;
click the name of the view, and change it's name to "bob"
now double click the "bob" view, and you will see the original statement that exists in syscomments...CREATE VIEW VW_WHATEVER AS ....
note how it does not say CREATE VIEW BOB AS....
this can happen to all compiled objects: procs, functions and views.
result: don't use Enterprise manager to rename objects. drop and recreate them, or use sp_rename
Lowell
October 24, 2006 at 11:33 am
Ged,
If you run the command
select * from information_schema.views
as Ian suggested, you'll see the table_name value is what the view was renamed to using Enterprise Manager, and the view_definition starts out CREATE VIEW owner.viewname before it was changed in Enterprise Manager. Someone way more skilled in string manipulation than I am could probably write a routine that compared the two viewname values and returned only the ones that didn't match.
Mattie
October 24, 2006 at 7:56 pm
If the naming differences are that bad, generate scripts for all the views from EnterPrise Manger, drop all the views, recreate the views using the script.
--Jeff Moden
Change is inevitable... Change for the better is not.
November 2, 2006 at 10:43 pm
Thanks all.
As it turned out, all they wanted was to generate the knowledge of what views/stored procs are out of sync.
so I wrote a nice simple little script as per below to interrogate the database for this.
select table_catalog, table_name, view_definition from INFORMATION_SCHEMA.views
where view_definition not like '%'+table_name+'%'
This does it quite nicely.
November 3, 2006 at 5:47 am
very handy Ged;
I added another selection below that you can use if you have stored procs or functions that have been renamed the same way; Thank you for writing something for the detection of this issue:
select specific_name, routine_name, routine_definition from INFORMATION_SCHEMA.routines
where routine_definition not like '%'+routine_name+'%'
Lowell
Viewing 7 posts - 1 through 6 (of 6 total)
You must be logged in to reply to this topic. Login to reply