15

Is it possible to script schema of the entire database (SQL Server or Postgres) using datagrip?

I know I can get DDL for table and view and source for each stored procedure / function on it's own.

Can I get one script for all objects in database at once?

Alternatively, is there a way to search through code of all routines at once, say I need to find which ones are using #table temp table?

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
vittore
  • 17,449
  • 6
  • 44
  • 82

4 Answers4

10

From 2018.2 there is a feature called SQL generator. It will generate the whole DDL for the database/schema with several available options.

enter image description here

The result is:

enter image description here

BUT: If you want just to understand where the table is used, please use the dedicated functionality which is called Find Usages (Alt+F7 or context menu on a table name)

enter image description here

moscas
  • 9,064
  • 36
  • 42
7

I was looking for this today and just found it. If you right click the schema you want to copy and choose "Copy DDL" this will copy the create script to the clipboard.

RobbZ
  • 1,410
  • 14
  • 19
  • 2
    well, on first look it does, however it have one serious limitation: all stored procedures are scripted as `CREATE PROCEDURE usp_RequestFileDelete(@FileId INT);` i.e. no code ( at least for Sql Server) – vittore Aug 31 '16 at 11:29
  • That's a shame. I am using Datagrip only with Amazon's Redshift. I use SSMS whenever I have to work with Sql Server. SSMS is excellent if you add SQL Prompt or SQL Complete. – RobbZ Aug 31 '16 at 13:09
  • same thing, love my sqlcomplete. was hoping to have native OSX tool, so i dont need RDP to my pc just to do some DB stuff. Aparently cant do all the things i need. – vittore Aug 31 '16 at 13:17
2

To answer your second part of the question: quick and easy way to search for #table in all of your procedures you can do the following query

SELECT *
FROM information_schema.routines
WHERE routine_definition LIKE '%#table%'
1

For now only dumping tables works. In 2016.3 EAP which will be available in the end of August there will be an integration with mysqldump and pg_dump.

Check the screenshot

moscas
  • 9,064
  • 36
  • 42