Monday, 15 February 2010

RegEx to parse stored procedure and object names from DDL in a .sql file C# -



RegEx to parse stored procedure and object names from DDL in a .sql file C# -

i have .sql file may contain ddl definitions of several stored procedures, alter statements tables, triggers, views etc

it have statements these :

create proc / create procedure alter proc / alter procedure drop proc / drop procedure create table/trigger/view alter table/trigger/view drop table/trigger/view etc

what best way parse .sql file , list of objects(proc/table/view names) , action beingness taken on them (alter/create/drop)? thinking instead of using stuff microsoft.data.schema.scriptdom or antlr or other parsers, easiest way utilize regex. not sure kind of regex should write covers scenarios.

so far, look able match above rules. how name of object in front end of it. eg. matches

(create|alter|drop)\s+(procedure|proc|table|trigger|view|function|constraint)

how name advisorgroups question. regex imperfect because have [dbo]. in front end of or not. alter table advisorgroups too. not trying take care of possibilites. bare minimum.

alter table [dbo].[advisorgroups] add together constraint [xxx]

-thanks in advance

regex won't job done - definitely... need real parser - this one (commercial).

c# regex parsing sql-parser tsql-parser

No comments:

Post a Comment