Parsing SQL DDl

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • mike65
    New Member
    • Aug 2010
    • 1

    Parsing SQL DDl

    In the program I am trying to write, I need to extract table names, attribute names, data types from a text file which is actually a SQL DDL.The text file is something like this
    Code:
    CREATE TABLE SYSTEM.AQ$_INTERNET_AGENT (
    AGENT_NAME VARCHAR2(30) NOT NULL,
    PROTOCOL NUMBER(0) NOT NULL,
    SPARE1 VARCHAR2(128),
    PRIMARY KEY (AGENT_NAME)
    );
    CREATE TABLE SYSTEM.AQ$_INTERNET_AGENT_PRIVS (
    AGENT_NAME VARCHAR2(30) NOT NULL,
    DB_USERNAME VARCHAR2(30) NOT NULL
    );
    Is there an easy way to extract table names and attribute names from such a text file?
    Thanks.
  • Alex Papadimoulis
    Recognized Expert New Member
    • Jul 2010
    • 26

    #2
    There is no easy way to do this.

    Based on VARCHAR2 in your code, it looks like you're using Oracle, and their CREATE TABLE statement is a complete beast.

    In order for you to get table names, column names, etc., you would first need to write a parser. There are some great tools avaiable for this (GOLD Parsing System comes to mind), but it's still a ton of work.

    Comment

    • damaha
      New Member
      • Aug 2010
      • 1

      #3
      I think this article is what you are looking for:


      It illustrates how to analyze create table statement, extract table name, attribute names, data types, fetch Primary Key, Foreign Key, Unique Columns.

      Comment

      Working...