a list of all the tables, columns and their consntraints in the database

Hello

I need to write sql code which considers a list of all tables in the database, their columns and the primary or foreign key for each column (if any) and the refrence for each foreign key column.

Any ideas how ro?

DROP TABLE table_b;
DROP TABLE table_a;
--
CREATE TABLE table_a (
 CONSTRAINT pk_table_a PRIMARY KEY (column_b)
,column_a INTEGER
,column_b INTEGER
);
--
CREATE TABLE table_b (
 column_c INTEGER
,column_d INTEGER CONSTRAINT fk_table_a REFERENCES table_a(column_b)
);
--

SELECT  utc.table_name
       ,utc.column_name
       ,CASE WHEN uc.constraint_type = 'P' AND position IS NOT NULL THEN uc.constraint_name END primary_key
       ,CASE WHEN uc.constraint_type = 'R' AND position IS NOT NULL THEN uc.constraint_name END foreign_key
       ,CASE WHEN uc.constraint_type = 'R' AND position IS NOT NULL THEN uc.r_constraint_name END referenced_key
FROM    user_tab_cols utc
        LEFT JOIN user_constraints uc
          ON  (utc.table_name = uc.table_name)
        LEFT JOIN user_cons_columns ucc
          ON(ucc.table_name = utc.table_name
               AND utc.column_name = ucc.column_name
               AND uc.constraint_name = ucc.constraint_name)
WHERE   utc.table_name IN ('TABLE_A','TABLE_B');

TABLE_NAME COLUMN_NAME PRIMARY_KEY FOREIGN_KEY REFERENCED_KEY

TABLE_A COLUMN_B PK_TABLE_A

TABLE_A COLUMN_A

TABLE_B COLUMN_D FK_TABLE_A PK_TABLE_A

TABLE_B COLUMN_C

If you want to 'improve' the referenced_key column for the column referenced actually, you need to join user_cons_colums once again and use the column position.

Concerning

Marcus

Tags: Database

Similar Questions

  • How can I generate a list of all the albums I have in my music library

    How can I generate a list of all the albums I have in my music library

    See http://answers.microsoft.com/en-us/windows/forum/windows_7-sound/how-to-print-a-list-of-items-in-the-window-media/6490fe4f-bb0e-4afa-97ca-3ce58c3aaeba

    but, if you only do this several times, you can use this procedure instead:

    Open a command prompt in your folder music [shift-right click on the name of the folder in the Windows Explorer & select a window of commands here]

    Run the dir/ad/b /s > AlbumList.txt

    Then open the text file in Word and he put away: -.

    Replaceyourusernamewith Nothing \Music\ C:\Users\

    Replace-with ^ t [the code of the tab]

    Select all, convert table to use the trademarks of the tab as column separators

    Select column 1 [the artists], and delete

    If there is garbage in all 3 columns - go just delete the columns thus

    That should leave a unique list of album names

  • How to display the list of all the constraints, triggers, procedures... .etc

    Hello
    How to view a list of all the available constraints, triggers, procedures, functions and packages in a database. And how to view its definition?

    user12222356 wrote:
    Not working is this said sql statement "object"sys"". "" DBA_OBJECTS"does not exist"

    OK, so the problem is that you have not allowed access to any data dictionary table. If you want to be able to view all of the DBA_ * dictionary of data tables, you need the ADMINISTRATOR to grant you the privilege to CHOOSE ANY DICTIONARY.

    In the future, when you post an error message, in addition to displaying the error message, it will be useful if you can get the error number, for example, that is, ORA-xxxxx

    Justin

  • The list of all the steps in a sequence file

    Hi guys,.

    I'm new on the forum of NI Teststand, so this my first topic here. The situation is the following:

    Currently I develop a LV operator interface and I need to have a list of all the test step in a sequence file.

    I am able to list all the steps of a sequence, but in the file of the entire sequence.

    Are there opportunities to do?

    Thanks in advance!

    Hi Maroci,

    first of all, I am also quite new to TestStand, but I still think I can help you a bit.

    Given that your code works for a sequence in the file simply browse all the sequences in the SequenceFile. Consider something like this:

    This help you?
    Edit: Don forgt not (like me) to close the SequenceFile reference!

  • HP 14-ro24TX Haswell Corei3: can I have a list of all the RAM sticks capable for HP 14-ro24TX Haswell Corei3

    Can Inplease cause a list of all the RAM sticks, that I can use it on the HP 14 - ro24TX Haswell Corei3

    Hello

    You have a lot of messages. Please use the following post:

    http://h30434.www3.HP.com/T5/notebook-hardware-and-upgrade-questions/will-the-Kingston-Technology-4GB-1600MHz-DDR3L-PC3-12800/m-p/5721473

    Thank you.

  • In Windows Mail, when I want to create an email, then click on the "to:" I do not get my list of contacts with folders, I have just the button get a long list of all the contacts in my contact list.

    I'm having a problem with Windows Mail.  I have Vista.  When I want to create an email and find people to send to, then click on the "to:" I do not receive my contacts with folders list, I have just the button get a long list of all the contacts in my contact list and no folder where to choose from... and MANY of them are repeated 2 or 3 times.  It takes me forever to browse all of the names to find the little that I could transmit or write.    I tried to delete properties, but they simply duplicate himself instead of delete.  Since the contacts button, it's how I organized them... but there is no contact on the "create mail" window button click to access my files organized.  Can anyone help?

    original title: problem with Windows Mail

    Hello

    I suggest that you check the troubleshooting provided by S of Halima steps and check if they help to resolve the issue.

    http://answers.Microsoft.com/en-us/Windows/Forum/windows_vista-windows_programs/i-have-Vista-and-Windows-mail-i-cant-create-a/ace23d91-5d55-4AC7-8ca1-75aa5d53fb20

  • Don't need a list of all the recipients printed as wasting valuable resources

    Original title: print the list of safe senders

    Don't need a list of all the recipients printed as a waste of valuable resources paper and ink printing *.

    A little additional information would facilitate answering questions.

    What type of program. Print what etc.

    If you're talking about emails from Outlook.

    Export the data as a CSV file, but exclude unwanted fields, in particular the field of message body, because that would be very great.

    Import into Excel and clean the remaining fields.

  • Where is the list of all the questions I ask myself?

    Hello

    I did not use the community forums for a long time and I've noticed that things have changed and so I looked around to familiarize myself with the things again.

    However, I find is no longer the list of questions I have asked over the years and would love to be able to access them again if possible.

    Does anyone know that that they have been removed? Or if there is a way I can find my questions?

    Really appreciate your time and your help.

    Thank you!

    Click on your post: where is the list of all the questions I ask myself?

    Click on your name in blue at the top of your message

    Click on content in your profile under your photo and a little left.

    You should see a list of your messages.

  • List of all the roles a user belongs

    Hello
    I want to get a list of all the roles to which a user belongs with OIM 11 g APIs.
    oracle.iam.identity.usermgmt.api.UserManager
    oracle.iam.identity.rolemgmt.api.RoleManager

    A code example will be very useful.

    Thank you

    for the time being, use "*" instead of ConstantsDefinition.WILDCARD and move forward

  • How to get a list of all the pipes in a ThinApp

    I have a simple program to list all files in a folder.  I use it to get a list of named pipes by the way
    \\.\pipe\*as the argument, but it does not work if I Pack the program as a fine application.  I get the error code 3 (ERROR_PATH_NOT_FOUND).  I tried to use CreateFile on
    \\.\pipe\but he also failed when running as a ThinApp. Are their ways to get a list of all the pipes in a ThinApp?  Here is the source code.

    #include <windows.h>
    #include <tchar.h>
    #include <stdio.h>
    
    #include "stdafx.h"
    
    int main(int argc, char* argv[])
    {
       WIN32_FIND_DATA FindFileData;
       HANDLE hFind;
    
       if( argc != 2 )
       {
              _tprintf(TEXT("Usage: %s [target_file]\n"), argv[0]);
              return -1;
       }
    
       _tprintf (TEXT("Target file is %s\n"), argv[1]);
    
       hFind = FindFirstFile(argv[1], &FindFileData);
       if (hFind == INVALID_HANDLE_VALUE) 
       {
              printf ("FindFirstFile failed (%d)\n", GetLastError());
              return -1;
       } 
       else 
       {
              _tprintf (TEXT("The first file found is %s\n"), 
                   FindFileData.cFileName);
    
              BOOL nextFile = FindNextFile(hFind, &FindFileData);
    
              while (nextFile)
              {
                   _tprintf (TEXT("The next file found is %s\n"), 
                             FindFileData.cFileName);
    
                   nextFile = FindNextFile(hFind, &FindFileData);
              }
    
              FindClose(hFind);
       }
    
       return 0;
    }
    

    OK, so what about the original example of FindFirstFile, if I try with 4.6 it does not work for me. I use 6 VC to create the application and then add it to the cmd project and then rebuild. I tried these combinations:

    App.exe \\.\pipe\* (this works)

    App.exe \\.\pipe\ (this does not work, in native mode as it does not work)

    App.exe //./pipe/* (this works)

    App.exe //./pipe/ (this does not work, in native mode as it does not work)

    can you tell me about the results you get when you try the above?

    Thank you.

  • How to make a list of all the missing files in a catalog in LR2?

    Is there an easy way to get a list of all the missing files for thumbnails in Lr2? I know that the symbol that appears in the upper right of any particular photo that does not contain the file, but how can I get a list of all these photos for a catalogue (or at least large chunks of a catalog).

    Thank you.

    You can click with the right button on a folder and choose synchronize - it has a button to display the missing files.

    John

  • Is it possible to see a list of all the words of hotspot?

    Hello

    I noticed that I can see the list of all the words in the index and glossary, however I can't find a list of all the words of hotspot - not everything in the index is a word hotspot - ideas?

    Thank you

    Jill

    Not quite like this would also pick up other hotspots in expansion entered manually. Search for a class = glossterm instead.

  • New to pix, need help with "debug access list of all the" command

    I have a pix 515 v6.3. I am tring to use then "debug access list of all the" command to see what traffic is stopped by my access list. However, I don't get any output. I turn execution of the command, but nothing happens. Other debug commands give the console. Perhaps, I do not understand what "debug to access list of all the" is used for. Any help that can be provided would be greatly appreciated.

    Tim

    Also try following the commands of logging

    LOGG on

    LOGG buff 7

    term Lun

    M.

  • Is this possible? Subforms appeal based on the drop-down list associated with the database

    I'm hoping to make a dynamic shape and I wonder if it's possible.

    I have a database with about 300 entries - pieces of agricultural goods and a few little bits of info on each of these properties. I want to create a form where users can choose the piece there rather than the property in a drop-down list. Based on the property they select, another menu drop down to fill with the cultures associated with this property. Then based on the selection made in this drop-down list, a specific form will be brought upward.

    For example, a person selects property #102 in the drop-down list. In the database, property #102 is associated with wheat, barley and corn, so the next drop would be complete with these three cultures. The user selects the wheat in the drop-down list and the form of wheat would be called. 

    I hope I explained that well enough.

    Is this possible? And if it's possible, how complicated to do? Assuming that I already have the database and subforms, it would be a long process from weeks to the script, or it would be simple enough?

    Yes, this could be done, here is an example that should help: Drop dependent dropdown (specimen attached)

    On the basis of selection (change event of the second menu drop-down), you can show or hide a subform.

    -Wasil

  • list of all the vm and what host they belong to

    Hi, I'm new to powercli & just had a (probably really simple) question.

    When I do something like:

    Get-vmhost-name "hostname" | Get - vm

    I get all the VMs on that host, but I only get powerstate, name, num cpu and memory. But if I again through "export-csv" pipes, I get tons more of information. How can I get this info on the command line itself, or better still to filter the columns that I want to see when the piping to the csv format?

    My goal was actually to get a list of all vm AND host it that belonged to, using the command get - vm, but I couldn't very well to show me was the information I'm looking for.

    Thanks in advance.

    Hello, lm31-

    There are several ways you could get the data properties.  You can "select" properties of the object using the Select-Object cmdlet.  So if you want to get a virtual machine and return some properties of choice, you might do something like:

    PS C:\> Get-VM myVM | Select-Object Name,Folder,ProvisionedSpaceGB,NumCpu,MemoryMB
    
    Name               : myVM
    Folder             : testVMs
    ProvisionedSpaceGB : 41.01
    NumCpu             : 1
    MemoryMB           : 2048
    

    A simple example of something that would work for your scenario to get all virtual machines and displaying the name of the host on which they are running:

    PS C:\> Get-VM | Select-Object Name,VMHost
    
    Name          VMHost
    ----          ------
    myVM          ourHost0
    myVM1         ourHost1
    ...
    

    Once you get a little more complicated reporting, you will definitely want to use the cmdlet Get-View, for reasons of speed of the script, but for this example, the foregoing will do ok.

Maybe you are looking for