简体   繁体   English

什么是从脚本中解析对象名称的最有效方法?

[英]What can be the most efficient way to parse the object name from the script?

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? 最有效的方法是什么?

Use a regular expression: 使用正则表达式:

Match m = Regex.Match(inputString, @"CREATE\s+(?<obj>.+?)\s*\(", RegexOptions.Singleline);
string objectName = m.Groups["obj"].Value;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 将来自特定列的输入解析为单独的列的最有效方法是什么? - What would be the most efficient way to parse the input from a specific column into separate columns? 解析这50万行的最有效方法是什么? - What's the most efficient way to parse these 500k rows? 从string中解析int的动态List的最有效方法 - Most efficient way to parse a dynamic List of int from string 什么是将DataTable转换为对象的最有效方法[,]? - What's the most efficient way to convert a DataTable to an object[,]? 在ObservableCollection中识别和替换对象的最有效方法是什么? - what is the most efficient way to identify and replace an object within an ObservableCollection? 比较“对象”类型的值的最有效方法是什么 - What is the most efficient way to compare values of type “object” 将标记的枚举解析为列表的最有效方法 - Most efficient way to parse a flagged enum to a list 将数据从数据库传输到服务器再传输到客户端的最有效方法是什么? - What is the most efficient way to transfert data from Database to server to client? 比较/排序两个阵列中的项目的最有效方法是什么? - What is the most efficient way to compare/sort items from two arrays? 从 KeyedCollection 获取键列表的最有效方法是什么? - What is the most efficient way to obtain the list of keys from a KeyedCollection?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM