Parsing query and getting list of tables used

Hi All,
   I require to parse sql query (simple & complex as well) and to get the list of tables used in the query.
   And need to validate that, the list of tables against a whitelist to maintained in the file.
  I tried to write my own parser, since there are lots possible ways to write complex queries, i am unable to cover all the scenarios.
  I require a help, Is there any other ways to get the list of tables used in a query?
Thanks,
Mahendran..

user10279893 wrote:
Hi All,
   I require to parse sql query (simple & complex as well) and to get the list of tables used in the query.
   And need to validate that, the list of tables against a whitelist to maintained in the file.
  I tried to write my own parser, since there are lots possible ways to write complex queries, i am unable to cover all the scenarios.
  I require a help, Is there any other ways to get the list of tables used in a query?
Thanks,
Mahendran..
You'll never cover all scenarios by trying to parse a query.
For example, what about a query that queries views and those views query pipelined functions, and those pipelined functions query other views or tables or pipelined functions etc.
And what about a query that dynamically obtains the table names, such as...
SQL> select
  2    table_name,
  3    to_number(
  4      extractvalue(
  5        xmltype(
  6 dbms_xmlgen.getxml('select count(*) c from '||table_name))
  7        ,'/ROWSET/ROW/C')) count
  8  from user_tables
  9 where iot_type != 'IOT_OVERFLOW'
10 or    iot_type is null;
TABLE_NAME                      COUNT
DEPT                                4
EMP                                14
BONUS                               0
SALGRADE                            5
.. in this case the tables being accessed (to count their rows) are not even known within the code, they are dynamically generated queries at run-time, so the only way to know what tables are accessed is to actually run the query.
Of course, a well designed system, with proper documentation and version control would allow you to take any database object and know where and what is using it, and whether it's even being used.

Similar Messages

  • How to get list of tables used in packages

    Dear All
    Can you pls tell me how to get list of tables used in packages
    Regards

    select referenced_name
      from user_dependencies
    where name = 'your_package'
       and referenced_type = 'TABLE'Regards,
    Rob.

  • Query to find out the list of tables used in a package

    hello,
    can anyone please help me out with a query; i want to find out the list of tables used by a particular package.
    thanks,
    orton

    orton607 wrote:
    thanks for replying guys. But the thing is i am using dynamic sql execute immediate in my package, so i want those tables also and the schema name.
    thanks,
    ortonThis is not possible. The best you could do is to have a good guess.
    Or how would you parse some dynamic statement as this:
       v_suffix := 'loyees';
       v_sql := 'Select count(*) from (select ''nonsense'' col1 from emp'||v_suffix||') where col1 = ''Y'''';
       execute_immediate(v_sql);
    ...What is the table name? How do you want to parse that?
    Better rewrite all dynamic SQL statements into non dynamic ones. Or do the source control logic for those dynamic parts in an extra module. For example implement your own dependency table and force every developer to add there all dynamic parts.

  • To Get List of Tables from Database which has the data 'AAAA' - T-SQL Query

    Hi,
    I have a database "Adventureworks", I need to get list of tables, which has the data 'AAAA' in their rows.
    Is there any optimised or simple way to do this task?
    Any T-SQL Query Available
    --- Thanks in advance..

    You can refer the same below URL provided by Praveen:
    https://gallery.technet.microsoft.com/scriptcenter/c0c57332-8624-48c0-b4c3-5b31fe641c58
    It has the SQL SP - "SP_SearchTables". You can pass parameters the way you want and get the expected output.
    -- Search for 'bike' instead of 'AAAA'
    Use AdventureWorks2012
    EXEC SP_SearchTables @Tablenames = '%', @SearchStr = '%bike%'
    -Vaibhav Chaudhari

  • Need tool/utility to get list of tables from sql query

    Hi,
    I often have to analyze huge queries without having access to database. Is there any tool where I can submit the a sql query and it gives me list of tables used in the query.  I also need similar thing for documentation.
    Let me know if anybody uses anything like this.
    Thanks.
    liquidloop[at]live[dot]co[dot]uk

    You can find the size of each table, and thus list the tables in the process.
    SET NOCOUNT ON
    DBCC UPDATEUSAGE(0)
    -- DB size.
    EXEC sp_spaceused
    -- Table row counts and sizes.
    CREATE TABLE #t
    [name] NVARCHAR(128),
    [rows] CHAR(11),
    reserved VARCHAR(18),
    data VARCHAR(18),
    index_size VARCHAR(18),
    unused VARCHAR(18)
    INSERT #t EXEC sp_msForEachTable 'EXEC sp_spaceused ''?'''
    SELECT *
    FROM #t
    -- # of rows.
    SELECT SUM(CAST([rows] AS int)) AS [rows]
    FROM #t
    SELECT
    t.NAME AS TableName,
    p.rows AS RowCounts,
    SUM(a.total_pages) * 8 AS TotalSpaceKB,
    SUM(a.used_pages) * 8 AS UsedSpaceKB,
    (SUM(a.total_pages) - SUM(a.used_pages)) * 8 AS UnusedSpaceKB
    FROM
    sys.tables t
    INNER JOIN
    sys.indexes i ON t.OBJECT_ID = i.object_id
    INNER JOIN
    sys.partitions p ON i.object_id = p.OBJECT_ID AND i.index_id = p.index_id
    INNER JOIN
    sys.allocation_units a ON p.partition_id = a.container_id
    WHERE
    t.NAME NOT LIKE 'dt%'
    AND t.is_ms_shipped = 0
    AND i.OBJECT_ID > 255
    GROUP BY
    t.Name, p.Rows
    ORDER BY
    t.Name
    --- SQL2005
    select o.name
    , reservedpages = sum(a.total_pages)
    , usedpages = sum(a.used_pages)
    , pages = sum(case when a.type <> 1 then a.used_pages
    when p.index_id < 2 then a.data_pages else 0 end)
    , SUM(a.used_pages)*8096 AS 'Size(B)'
    , rows = sum(case when (p.index_id < 2) and (a.type = 1) then p.rows else 0 end)
    from sys.objects o
    join sys.partitions p on p.object_id = o.object_id
    join sys.allocation_units a on p.partition_id = a.container_id
    where o.type = 'U'
    group by o.name
    order by 3 desc --biggest tables first
    Knowledge is the only thing that I can give you, and still retain, and we are both better off for it.

  • List of tables used in Custom Forms

    Hi All,
    I am working on forms . There are nearly 100 forms, I need to find all the tables used in these forms.
    Is there any way I can know the list of tables used in each form from backend.
    Or do I need to open each form and analyze the forms one by one?
    Thanks,
    Raj Kumar

    I am working on forms . There are nearly 100 forms, I need to find all the tables used in these forms.
    Is there any way I can know the list of tables used in each form from backend.
    Or do I need to open each form and analyze the forms one by one?You cannot get the list from the backend.
    You have 3 options here.
    Option 1) Open each form using Forms Builder and get the list of objects
    Option 2) Use Record History and LAST_QUERY
    Option 3) Enable trace
    How To Determine Table and Column Name from a Field in a Form in 11i [ID 259722.1]
    FAQ: Common Tracing Techniques within the Oracle Applications 11i/R12 [ID 296559.1]
    Thanks,
    Hussein

  • Getting list of tables the user has access to across different schemas.

    Hi,
    I have to get the list of tables that an User has access to. I tried the below code. It takes a very long time. Is there any way in which I can specify the user name and get all the tables that he has access to? I know that we can use dbMetadata.getTables api. But this returns the list of tables under the said schema. But I want the list of tables that the user has access including tables in other schema.
    In the below code, I am trying to get the tables for which USER_MICHAEL has access to.
    DatabaseMetaData dbMetadata = connection.getMetaData(); String userName = null; dbrs = dbMetadata.getTables(null,userName , "%", new String[] { "TABLE" }); dbrs=dbMetadata.getTablePrivileges("",userName,"%"); while (dbrs.next()) { String tableName = dbrs.getString("TABLE_NAME"); String schema = dbrs.getString("TABLE_SCHEM"); String privilege = dbrs.getString("PRIVILEGE"); String grantee = dbrs.getString("GRANTEE"); if(grantee!=null && grantee.equals("USER_MICHAEL")){       System.out.println("Schema---"+schema+" Table---"+tableName+"  Privilege----"+privilege+"  grantee---- "+grantee); } }

    That would be database dependent.
    Some engines have some system tables that together may be used to extract such information, others may not make it available at all outside closed APIs.

  • List of Tables used in IS Retail

    Hi ,
    I am currently desingning an adapter to integrate IS Retail and non SAP BI Solution. I need your help on the complete list of tables used in IS-Retails. It would be great if you could provide me the tcodes as well.
    Expecting a prompt reply from experts.
    Regards,
    Raghu.
    SAP Adapter Specialist.

    Dear Raghavendra,
    There are lot of SAP tables in IS Retail.
    You can search all tables using transaction code SE16 or SE16N
    For which transaction, you need SAP Table details?
    Bye,
    Muralidhara

  • Can i buy an iPhone at a pawn shop and get it unlocked for use with Straight Talk wireless?

    Just wondering if I can buy a used iphone at a pawn shop or on ebay and get it unlocked for use with the prepaid Straight Talk wireless service? If so, how much would it cost to get it unlocked?

    PHones can only be unlocked from the carrier; if you're looking for an unlocked device I'd recommand buying it directly from Apple as that is the only way to promise it is, if you buy it second hand you may find it is locked to a carrier who doesn't support unlocking, or worst yet activation lock

  • Is there a good website creation app on the iPad, or should I save up and get a MacBook to use RapidWeaver/iWeb?

    Is there a good website creation app on the iPad, or should I save up and get a MacBook to use RapidWeaver/iWeb?

    Wasn't being condescending, this is a new thead that continues one he already started asking if he could get iWeb on the iPad. Two people explained to him that iWeb was being discontinued (along with MobileMe) and suggested Rapidweaver and two other apps as replacements. It was also explained to him that there were no web creation apps on the iPad because you need to run a local web server, such as Apache, on your computer in order to use them. This is why they work on the Mac because it does have such a server. The iPad does not have one and cannot run one. And I suggested using HTML code if he wanted to develop on his iPad.
    You were aware that is how web creation software works?
    Here is the other thread:
    https://discussions.apple.com/message/15804045#15804045
    Do you know a good book on HTML web creation you could recomment to him?
    Message was edited by: deggie
    Message was edited by: deggie

  • Table names to get list of characteristics used in Query

    Hello,
    I am trying to get separate list of characteristics & key figures used in query. i want that particular table which will give me the list of characteristics. & other table which will give me list of key figures used in that query. I want these characteristics & keyfigures specifically used in query.I don't want the global list dependant on infoprovider but dependant on query like (ZSJM_ZSD_C05_Q001).
    Can anybody help in getting the table names?
    Thanks in advance.

    Hi Deepak,
    You need to go to RSRREPDIR - to get the GUID of the query.
    Then you can work your way through  RS* X *REF (type in this name in SE11/SE16 and press F4 ) table to find the query elements.
    There is also a text table where you can read the component names... but dont have the system at hand, hence cant furnish you that info... I think, it may be RSZELTTXT.
    Also in my opinion the best way to get this information is from metadata repository view in admin workbench.(RSA1). Keep drilling down from the query to its characteristics.. you shall get what you need.
    Also you may use transport connection to display the elements of the query. Just go to the transport connection , in the object list, choose the required query and and transfer it to the collector area. Diplay the elements as a list... you shall then find all your query elements...
    You may not need to traverse through the tables to retrieve this information.
    Hope it helps,
    Best regards,
    Sunmit.

  • Program to get list of tables accessed by query

    Hi Guru's,
    Is there any program or function module to get the list of tables accessed by the query(as we get in query execution plan by using SQL debug option)?

    Shanthi,
    The SQL trace is giving only object list..
    when i used combined table accesses  option its giving the standard SAP tables.. not tables related to master data or TD....
    And my requirement is to get directly the program output or program intermediate output as
    tables (like MD TD tables etc)

  • Getting List of SQL server and on selection of server get List of Databases using SMO

    Hi,
    I need to have functionality where I need to populate List of available SQL servers from local network, and when i select SQL server from list, get the list of Databases from that Server.
    For this i referenced SQL SMO Dll's and placed two drop down, one lists Server names, and one lists Database names.
    Dlls refered are:
    Microsoft.SqlServer.ConnectionInfo.dll
    Microsoft.SqlServer.Management.Sdk.Sfc.dll
    Microsoft.SqlServer.Smo.dll
    Microsoft.SqlServer.SqlClrProvider.dll
    Microsoft.SqlServer.SqlEnum.dll
    Above DLL's i have copied from SQL server SQL server 2008 installed location
    C:\Program Files\Microsoft SQL Server\110\SDK\Assemblies
    DLL version : 11.0.3000.0
    Code i have used is:
    private void MainForm_Load(object sender,
    EventArgs e)
       DataTable dataTable = SmoApplication.EnumAvailableSqlServers(false);
       cmbServers.ValueMember = "Name";
       cmbServers.DataSource = dataTable;
    //Now, load Databases on selection of Server combo box.
    private void cmbServers_SelectedIndexChanged(object sender,
    EventArgs e)
       cmbDatabases.Items.Clear();
       if (cmbServers.SelectedIndex != -1)
          string serverName = cmbServers.SelectedValue.ToString();
          Server server = new Server(serverName);
          try
             foreach (Database database in server.Databases)
                cmbDatabases.Items.Add(database.Name);
          catch (Exception ex)
             string exception = ex.Message;
    It works where SQL server is installed, but in systems where no SQL server is installed, it is not working, it is not returning list of SQL server and so database list.
    Query is> can you please help me in this regard, what i am missing here, do i need to install any client component to use this?, or anything else what i need to do to make this functionality work.
    Thanks,
    Hemal

    Thanks Michael for replying.
    I have gone through the reply, and the link on how to get the SMO library installed.
    "To install the Client Tooks SDK without installing SQL Server, install Shared Management Objects from the SQL Server feature pack.
    If you want to ensure that SQL Server Management Objects is installed on a computer that will run your application, you can use the Shared Management Objects .msi in the SQL Server feature pack."
    I have few questions on "Shared Management Objects .msi" 
    Where do i get "Shared Management Objects .msi".
    only installing this msi will install SMO?.
    Can i ship this msi with my application installer?
    do i need to install x86 on x86 system and x64 version of msi in x64 system, or x86 can work fine with both, my application
    is x86 only.
    Thanks,
    Hemal

  • Query to get list of linked server tables referenced inside a stored procedure

    Hi,
    SQL Server 2005 sp4
    I have a requirement to get list of linked server tables referenced insider a stored procedure
    Ex:
    Databases       DB1          DB2
    Tables:            T1             T2                            
    Use DB1
    Go
    Create proc P1
    begin
    select * from T1
    select * from DB2.dbo.T2
    end
    I am looking for a query which can return a result with output as below. sp_depends is not helping here as it does not work for cross DB objects, any other thoughts.
    Tables
    T1,
    DB2.dbo.T2

    On SQL 2005, you will have to do it manually.
    On SQL 2008 or later, you could have used sys.sql_expression_dependencies.
    Erland Sommarskog, SQL Server MVP, [email protected]

  • How to get list of Reports used in iBots?

    Hi,
    What is the process to get list of all those reports used in iBots/Alerts.
    Is there any NQ table, which contains this information.
    Thanks,
    Sunil Jena

    Do you have usage tracking configured / enabled?
    From memory have a look in there - I am fairly sure you can see the difference between a 'normal' user use of a report and the i-Bot equivalent.
    And yes, you are correct there is also a table that holds the i-Bot data, in 10g it used to be nq_scheduler or something similar - not sure what it is now.
    regards,
    Robert.

Maybe you are looking for

  • AFPPRN received a return code of failure from the OSD routine FDUPRN

    Hi all, Operting system : Solaris 9 Oracle application: 11.5.10 i would like to ask query related to buffer area of pinter on solaris server. we are trying to print cheques using oracle application on network printer. some times it is printing the ch

  • Finder performance

    Many processes in the finder take very long: Opening folders, drag & drop, copying, cutting and pasting work very slow. For example, moving regular pdf or other files between folders on the same harddrive usually takes more than a minute. The „copyin

  • Cd drive ejecting empty dvd's

    Hello everyone, My cd drive of my macbook is ejecting all empty dvd's,so i cant burn any dvd's. Does anyone have an answer to this problem? thanks

  • Problem in using expr in audio tag - UCCX 8.5

    We are using voice browser step in CCX editor to invoke a voice xml file. In the voice xml, if we play back an audio using following script it is working well <prompt>         <audio src="Transfer.wav">Please hold while I transfer the call</audio> </

  • Making an int() return more than one method?

    hey people. i need an int, for example, public int someInt(){ return 1000; }to return more than one number. To clarify, i need to be able to call the int() and it return me three different values. Is this possible?