SchemaCrawler

10,605 views

Published on

Published in: Technology
1 Comment
1 Like
Statistics
Notes
  • 1. Help
    sc

    2. Help on a command
    sc -help -command=graph

    3. Plain text list of tables
    sc -host=192.168.153.139 -user=sa -password=sualeh -database=AdventureWorks -schemas=AdventureWorks\.(?:(?!sys).)* -infolevel=minimum -procedures= -command=list

    4. Plain text list of Product tables
    sc -host=192.168.153.139 -user=sa -password=sualeh -database=AdventureWorks -schemas=AdventureWorks\.(?:(?!sys).)* -infolevel=minimum -procedures= -tables=.*\..*\.Product.* -command=list

    5. Plain text, standard schema
    sc -host=192.168.153.139 -user=sa -password=sualeh -database=AdventureWorks -schemas=AdventureWorks\.(?:(?!sys).)* -infolevel=standard -procedures= -tables=.*\..*\.Product.* -command=schema

    6. HTML standard schema
    sc -host=192.168.153.139 -user=sa -password=sualeh -database=AdventureWorks -schemas=AdventureWorks\.(?:(?!sys).)* -infolevel=standard -procedures= -tables=.*\..*\.Product.* -command=schema -outputformat=html > ProductTables.html

    7. Plain text, detailed
    sc -host=192.168.153.139 -user=sa -password=sualeh -database=AdventureWorks -schemas=AdventureWorks.Production -procedures= -tables=AdventureWorks.Production.WorkOrder -noinfo -infolevel=lint -command=details

    8. Detailed plain text for a view
    sc -host=192.168.153.139 -user=sa -password=sualeh -database=AdventureWorks -schemas=AdventureWorks.Sales -procedures= -tables=AdventureWorks.Sales.vIndividualCustomer -noinfo -infolevel=lint -command=details

    9. Counts
    sc -host=192.168.153.139 -user=sa -password=sualeh -database=AdventureWorks -schemas=AdventureWorks\.(?:(?!sys).)* -infolevel=minimum -procedures= -tables=.*\..*\.Product.* -command=count

    10. Dumps
    sc -host=192.168.153.139 -user=sa -password=sualeh -database=AdventureWorks -schemas=AdventureWorks.Production -infolevel=standard -procedures= -tables=AdventureWorks.Production.ProductCategory -command=dump

    11. Grep example
    sc -host=192.168.153.139 -user=sa -password=sualeh -database=AdventureWorks -schemas=AdventureWorks\.(?:(?!sys).)* -infolevel=standard -procedures= -grepcolumns=.*\..*ProductID -command=schema

    12. Procedures, detailed
    sc -host=192.168.153.139 -user=sa -password=sualeh -database=AdventureWorks -schemas=AdventureWorks\.HumanResources -noinfo -infolevel=maximum -tables= -command=details

    13. Diagram
    sc -host=192.168.153.139 -user=sa -password=sualeh -database=AdventureWorks -schemas=AdventureWorks\.(?:(?!sys).)* -infolevel=lint -table_types=TABLE -procedures= -grepcolumns=.*\..*CustomerID -command=graph -outputformat=pdf

    14. Javascript
    sc -host=192.168.153.139 -user=sa -password=sualeh -database=AdventureWorks -schemas=AdventureWorks\.(?:(?!sys).)* -tables=.*\..*\.Product.* -infolevel=standard -procedures= -command=script -outputformat=tables.js
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
No Downloads
Views
Total views
10,605
On SlideShare
0
From Embeds
0
Number of Embeds
7,177
Actions
Shares
0
Downloads
24
Comments
1
Likes
1
Embeds 0
No embeds

No notes for slide

SchemaCrawler

  1. 1. SchemaCrawler<br />Sualeh Fatehi<br />
  2. 2. What is SchemaCrawler?<br />Schema discovery tool<br />“grep” through your schema<br />Create schema diagrams<br />Lint your schema <br />Infer table relationships<br />Interact with your database using JavaScript<br />Write templates to generate output<br />http://www.schemacrawler.com<br />2<br />
  3. 3. About<br />Project started about 8 years ago<br />Continuously maintained<br />Written in pure Java and pure JDBC<br />Open source and free<br />Business-friendly LGPL license<br />Database and operating system independent<br />Command-line tool<br />Maven and ant support<br />Provides a Java API for database metadata<br />http://www.schemacrawler.com<br />3<br />
  4. 4. Installation<br />Download and unzip<br />A large number of examples provided<br />Several database-specific versions available<br />Open source JDBC drivers bundled where available<br />Oracle and DB2 drivers need to be provided<br />GraphViz needed for graphing<br />http://www.schemacrawler.com<br />4<br />
  5. 5. Problems with JDBC Metadata<br />JDBC Metadata<br />ResultSet<br />1, “YES”, or “TRUE”<br />Types<br /><ul><li>TABLE_TYPE: string
  6. 6. PROCEDURE_TYPE: integer
  7. 7. COLUMN_TYPE: does not exist SQL_DATA_TYPE: unusedDATA_TYPE: yes!</li></ul>SchemaCrawler<br />POJO<br />boolean value<br />getType() returns an enum<br />http://www.schemacrawler.com<br />5<br />http://www.devx.com/Java/Article/32443/1954<br />
  8. 8. Code Example<br />finalDatabase database = <br />SchemaCrawlerUtility.getDatabase(connection, options);<br />for(final Schema schema: database.getSchemas())<br />{<br />System.out.println(schema);<br />for(final Table table: schema.getTables())<br />{<br />System.out.println("o--> " + table);<br />for(final Column column: table.getColumns())<br /> {<br />System.out.println(" o--> " + column + <br /> " (" + column.getType() + ")");<br /> }<br /> }<br />}<br />http://www.schemacrawler.com<br />6<br />
  9. 9. Command-line Basics<br />scfor help<br />Connection parameters - user name and password, and one of<br /><ul><li>Connection URL
  10. 10. Host and port</li></ul>Information level<br /><ul><li>Determines amount of schema information retrieved
  11. 11. Determines time taken to crawl
  12. 12. Schemas
  13. 13. SchemaCrawler command</li></ul>http://www.schemacrawler.com<br />7<br />
  14. 14. Commands and Output<br />Plain text and HTML formats are available<br />All text formats are designed to be diff-ed<br />Commands<br /><ul><li>list
  15. 15. schema
  16. 16. details
  17. 17. count
  18. 18. dump
  19. 19. graph
  20. 20. script</li></ul>http://www.schemacrawler.com<br />8<br />
  21. 21. Examples<br />Help and options overview<br />Basic schema output, in text and HTML<br />Count and dump<br />grep<br />Triggers<br />Stored procedures<br />Diagram<br />Lint<br />http://www.schemacrawler.com<br />9<br />
  22. 22. Questions?<br />http://www.schemacrawler.com<br />10<br />

×