0

I have some inputs as

CREATE PROCEDURE dbo._ws_CallLogs_DeleteAll
(
    @UserId uniqueidentifier 
)
AS

OR

/*========== Script Analyzed by Sql Eye  on 11/30/2012 2:55:12 PM =======

  *====================== Total warnings : 0  =================================== */ 






SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
SET ANSI_PADDING ON
GO
IF EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_CachedPlan_cached_plan_Job_id]') 
                AND parent_object_id = OBJECT_ID(N'[dbo].[CachedPlan]'))
ALTER TABLE [dbo].[CachedPlan] DROP CONSTRAINT [FK_CachedPlan_cached_plan_Job_id]
GO
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[CachedPlan]') AND TYPE IN (N'U'))
DROP TABLE [dbo].[CachedPlan]
GO
CREATE TABLE [dbo].[CachedPlan](
    [cached_plan_id] [int] IDENTITY(1,1) NOT FOR REPLICATION NOT NULL,
    [cached_plan_Job_id] [int] NOT NULL,
    [dbId] [int] NOT NULL,
    [dbname] [varchar](100) NOT NULL,
    [plan_type] [varchar](50) NOT NULL,
    [objId] [int] NOT NULL,
    [objname] [varchar](100) NOT NULL,
    [sql_batch] [varchar](max) NOT NULL,

I need to pick out

PROCEDURE dbo._ws_CallLogs_DeleteAll

OR

TABLE [dbo].[CachedPlan]

What is the most efficient way to do so?

3
  • Have you tried anything already? And in what way do you need it to be efficient - in terms of code, or performance, or disk access...? Commented May 14, 2013 at 9:27
  • I am trying with Microsoft.Data.Schema.ScriptDom.Sql,Microsoft.Data.Schema.ScriptDom api's... give me some time Commented May 14, 2013 at 9:32
  • Are you trying to validate the scripts or to extract strings from them? Commented May 14, 2013 at 9:36

1 Answer 1

2

Use a regular expression:

Match m = Regex.Match(inputString, @"CREATE\s+(?<obj>.+?)\s*\(", RegexOptions.Singleline);
string objectName = m.Groups["obj"].Value;
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.