I have a .sql file which may contain DDL definitions of several stored procedures, alter statements for Tables, Triggers, Views etc
It could have statements like 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 is the best way to parse the .sql file and just get the list of objects(Proc/Table/View names) and the action that is being taken on them (ALTER/CREATE/DROP)? I am thinking instead of using stuff like Microsoft.Data.Schema.ScriptDom or ANTLR or other parsers, the easiest way is to use a RegEx. But not sure what kind of RegEx should I write which covers all the scenarios.
So far, this expression is able to match all the above rules. But how do I get the name of the object in front of it. eg. it matches
(create|alter|drop)\s+(procedure|proc|table|trigger|view|function|constraint)
How do I get the name AdvisorGroups is my question. My RegEx is also imperfect because it could have [dbo]. in front of it or not. It could just be Alter table AdvisorGroups too. I am not trying to take care of all possibilites. Just the bare minimum.
ALTER TABLE [dbo].[AdvisorGroups] ADD CONSTRAINT [XXX]
-Thanks in advance