473,725 Members | 2,032 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

invalid object like view, function etc.

Hi is there a way to know if object (view, function, etc) are invalid
?
let say a have a table t1 (field col1, col2)
and a view v1 (field t1.col1, t1.col2)

if I drop t1.col2, the view v1 is not working anymore. I want to know
that information.

In Oracle (8.1.7), i can query the all_objects, user_object table,
where status = 'INVALID'. So i can recompile invalid objects (or
correct it).

In sql Server, the table sysobjects give me some status info, but
they are not documented enough.
Do you know if i can user one of those fields : status, userstat,
sysstat ?

Same question for function , procedure.
TKS.
Jul 20 '05 #1
1 4464
SQL Server doesn't expose this information. One method to identify invalid
objects is to reference them with SET FMPONLY ON:

SET FMTONLY ON
SELECT * FROM MyView
SET FMTONLY OFF
GO
SET FMTONLY ON
EXEC MyProcedure NULL
SET FMTONLY OFF
GO

However, this is not as thorough as actually exercising the objects. For
example, it won't detect invalid dynamic SQL or triggers. Below is a proc
that will generate and execute such a script for all views, functions and
procedures in the database. Note that it is still under development and
hasn't been tested thoroughly.

CREATE PROC #ValidateObject s
AS
SET NOCOUNT ON
--procedures and functions
SELECT
CASE r.ROUTINE_TYPE
WHEN 'PROCEDURE' THEN 'Procedure'
WHEN 'FUNCTION' THEN
CASE
WHEN
OBJECTPROPERTY( OBJECT_ID(QUOTE NAME(ROUTINE_SC HEMA) +
N'.' +
QUOTENAME(ROUTI NE_NAME)), 'IsTableFunctio n') = 1
THEN 'TableFunction'
WHEN
OBJECTPROPERTY( OBJECT_ID(QUOTE NAME(ROUTINE_SC HEMA) +
N'.' +
QUOTENAME(ROUTI NE_NAME)), 'IsScalarFuncti on') = 1
THEN 'ScalarFunction '
WHEN
OBJECTPROPERTY( OBJECT_ID(QUOTE NAME(ROUTINE_SC HEMA) +
N'.' +
QUOTENAME(ROUTI NE_NAME)), 'IsInlineFuncti on') = 1
THEN 'InlineFunction '
END
END AS ObjectType,
QUOTENAME(ROUTI NE_SCHEMA) +
N'.' +
QUOTENAME(ROUTI NE_NAME) AS ObjectName,
REPLICATE(N'NUL L,',
ISNULL((SELECT COUNT(*) AS Parameters
FROM INFORMATION_SCH EMA.PARAMETERS p
WHERE
p.IS_RESULT = 'NO' AND
p.SPECIFIC_SCHE MA = r.ROUTINE_SCHEM A AND
p.SPECIFIC_NAME = r.ROUTINE_NAME) , 0)) AS Parameters
INTO #Objects
FROM INFORMATION_SCH EMA.ROUTINES r
WHERE
ROUTINE_TYPE IN ('PROCEDURE', 'FUNCTION') AND
OBJECTPROPERTY( OBJECT_ID(QUOTE NAME(ROUTINE_SC HEMA) +
N'.' +
QUOTENAME(ROUTI NE_NAME)), 'IsMSShipped') = 0
UNION ALL
--views
SELECT
'View' AS ObjectType,
QUOTENAME(TABLE _SCHEMA) +
N'.' +
QUOTENAME(TABLE _NAME) AS ObjectName,
'' AS Parameters
FROM INFORMATION_SCH EMA.TABLES t
WHERE
TABLE_TYPE = 'VIEW' AND
OBJECTPROPERTY( OBJECT_ID(QUOTE NAME(TABLE_SCHE MA) +
N'.' +
QUOTENAME(TABLE _NAME)), 'IsMSShipped') = 0

--remove trailing comma from parameter list
UPDATE #Objects
SET Parameters = LEFT(Parameters , LEN(Parameters) - 1)
WHERE RIGHT(Parameter s, 1) = N','

--generate invocation scripts
SELECT
CASE ObjectType
WHEN 'View' THEN 'SELECT * FROM '
WHEN 'Procedure' THEN 'EXEC '
WHEN 'ScalarFunction ' THEN 'SELECT '
WHEN 'InlineFunction ' THEN 'SELECT * FROM '
WHEN 'TableFunction' THEN 'SELECT * FROM '
END +
RTRIM(ObjectNam e) +
CASE ObjectType
WHEN 'View' THEN ''
WHEN 'Procedure' THEN ' '
WHEN 'ScalarFunction ' THEN '('
WHEN 'InlineFunction ' THEN '('
WHEN 'TableFunction' THEN '('
END +
Parameters +
CASE ObjectType
WHEN 'View' THEN ''
WHEN 'Procedure' THEN ''
WHEN 'ScalarFunction ' THEN ')'
WHEN 'InlineFunction ' THEN ')'
WHEN 'TableFunction' THEN ')'
END
AS InvocationScrip t
INTO #InvocationScri pts
FROM #Objects
ORDER BY ObjectName

DECLARE InvocationScrip ts CURSOR LOCAL FAST_FORWARD READ_ONLY FOR
SELECT InvocationScrip t
FROM #InvocationScri pts
DECLARE @InvocationScri pt nvarchar(4000)
OPEN InvocationScrip ts
WHILE 1 = 1
BEGIN
FETCH NEXT FROM InvocationScrip ts INTO @InvocationScri pt
IF @@FETCH_STATUS = -1 BREAK
SET @InvocationScri pt = 'PRINT ''' +
@InvocationScri pt +
''' SET FMTONLY ON ' + @InvocationScri pt + ' SET FMTONLY OFF'
EXEC sp_executesql @InvocationScri pt
END
CLOSE InvocationScrip ts
DEALLOCATE InvocationScrip ts

DROP TABLE #Objects, #InvocationScri pts
GO
--
Hope this helps.

Dan Guzman
SQL Server MVP

"Fran?ois Bourdages" <fr************ ****@harfan.com > wrote in message
news:92******** *************** ***@posting.goo gle.com...
Hi is there a way to know if object (view, function, etc) are invalid
?
let say a have a table t1 (field col1, col2)
and a view v1 (field t1.col1, t1.col2)

if I drop t1.col2, the view v1 is not working anymore. I want to know
that information.

In Oracle (8.1.7), i can query the all_objects, user_object table,
where status = 'INVALID'. So i can recompile invalid objects (or
correct it).

In sql Server, the table sysobjects give me some status info, but
they are not documented enough.
Do you know if i can user one of those fields : status, userstat,
sysstat ?

Same question for function , procedure.
TKS.

Jul 20 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

12
2430
by: R | last post by:
Hello everybody. I'm writing my own Content System in PHP5. I've written so far main classes for handling DB connections, XML, XForms and Sessions. But I've got problem with one thing - it's not even relative with implementation - I'm looking for a smart solution My present system works like this:
0
349
by: Fran?ois Bourdages | last post by:
Hi is there a way to know if object (view, function, etc) are invalid ? let say a have a table t1 (field col1, col2) and a view v1 (field t1.col1, t1.col2) if I drop t1.col2, the view v1 is not working anymore. I want to know that information. In Oracle (8.1.7), i can query the all_objects, user_object table, where status = 'INVALID'. So i can recompile invalid objects (or
3
4619
by: Paul | last post by:
I have an Access 2000 database with a form that is giving me some major headaches. When you open the form, it displays all records and allows editing, but has AllowAdditions set to False so that the user has to use my New Record button. When you click the New Record button, the form presents a new record for editing. My client wants to use the Escape key to cancel changes to new or existing records. On existing records, Access already...
1
1407
by: Owen Jenkins | last post by:
I have found references to this problem in several threads on this newsgroup but none provide an answer to explain this problem. So any further assistance would be very helpful... I have 2 forms (one in form view-FF, one in datasheet view-FD) which are open together and which use a query as the recordsource with data from the same table. When one form (FF) is visible, the other (FD) is hidden. In some circumstances, entering data onto...
1
2553
by: Ghost | last post by:
Hi all, I wrote a program in C# and now I have to "translate" it i visual C++ (MFC) using .NET, but I had a little problem: *ERRORS* error C3181: 'CTestDlg' : invalid operand for __typeof, expected fully defined managed type error C3363: 'void CTestDlg::BtnAboutClick(System::Object __g *,System::EventArgs __gc *)' : cannot create a delegate handler fo 'System::EventHandler' from a non-member function or a member of a
2
3215
by: Vinod I | last post by:
Hi Team, When I tryed following code, I am getting the Runtime Error as "The View State is invalid for this page and might be corrupted." Exception Details: System.Web.HttpException: The View State is invalid for this page and might be corrupted. Stack Trace: System.Web.UI.Page.LoadPageStateFromPersistenceMedium() +150 System.Web.UI.Page.LoadPageViewState() +16
2
783
by: Brad | last post by:
I have an intranet app that has just started sporadically getting the following error "The viewstate is invalid for this page and might be corrupted." By sproadic I mean 3-4 times during the past two days out of 100's of hits. The error just started yesterday and this app has been running for quite some time without this error and has not been updated just before or after the error started. Reseaching this error I've checked the...
2
2692
by: Jerry Nelson | last post by:
I get the following error: WGA_Update is a view not a Table Invalid object name 'WGA_Update'. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. Exception Details: System.Data.SqlClient.SqlException: Invalid object
1
8031
by: Java Guy | last post by:
I'm trying to view a web page. IE tells me there are (Java?) errors on the page. Here they are: Line: 15 Char: 7 Error: Wrong number of arguments or invalid propert assignment Code: 0 URL: http://(address.of.my.webcam):port/LiveView.html and
0
8888
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9401
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
9174
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9111
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8096
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6702
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4517
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4782
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3221
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.