How to preview database table changes SQL in DBeaver? - dbeaver

I am using DBeaver 21.2.0 and I have found the option to preview the SQL statements before saving modified data to the database (MySQL), through the Script icon in the bottom toolbar.
But when I modify the table structure (for example, add a column, remove a column...) no such option seems to exist. I can only save the changes to the database, but it is imperative for me to see the SQL statements before executing them.
Is that possible?

Related

How do you change a table's schema?

We have a MySQL Workbench project with two tabs (two schemas/two databases).
If we create a table in the first tab, it's attached to the schema
magikweb_dev_igcweb.
If we create a table in the second tab, it's attached to the schema
magikweb_dev_igcweb_archive.
If we copy-paste/duplicate a table from the first tab to the second tab, the resulting table remains in the first schema. How can you change a table's schema?
Each schema is linked with a specific database, so when we use the "Synchronize Model..." feature, it links all the tables properly.
Use the model tab. You can cut out a table from one schema tab and insert it into another.
The cut-and-paste method described in another answer works well for tables with no foreign keys, and for a reasonable number of tables.
An alternative that preserves foreign keys is to export the model as a SQL script, edit it, and then import the new script into a new model.
Using MySQL Workbench v6.3:
File -> Export -> Forward Engineer SQL Script
Carefully edit SQL script. Replace references to one schema with the other, for the tables you want to move. Do this both for CREATE TABLE commands and foreign key references.
File -> New Model
File -> Import -> Reverse Engineer SQL Script
Unfortunately you will then need to recreate any diagrams. But that can be straightforward if you have the original diagram as reference (take a screenshot or export it to PNG or PDF.)
Follow this simple steps (never miss step 4 and 5) :
Open Model Tab
Choose source schema. In my case, I want to copy table users from schema abc_develop_v1 to schema abc_develop_v2 then paste to diagram . So I choose schema abc_develop_v1, right-click table users then Copy 'users'
Go to the targeted schema. In my case is schema abc_develop_v2, right-click then Paste 'users'
Next, copy table users from schema abc_develop_v2. Right-click table users then Copy 'users'
Go to your diagram and Paste 'users'.
That's all. Your table is ready in your diagram with the right schema :-)
Notes: You can double check by double-click on the table in your diagram, and look at the right corner. It will show the Schema name.
I found a less painful way to do this.
Save and backup your diagram and your schema.
Display schema's name before table's names in diagram. This will make the next step easier.
Right-click on the tables which are on the wrong schema, and select "Copy SQL to clipboard". Paste the script in a new SQL window. Repeat for each table you want to migrate.
Edit the script to change the schema name. Watch for any miss in entries, the wrong schema might be a reference at any line. Mine was mydb, which I don't remember creating. Execute the script. Now you have the tables on the right schema.
Synchronize your model. Be sure to check "Update the model" for each missing table, otherwise, the tables will be deleted from the schema :)
Drag'n'drop the newly created tables into the diagram. Then remove the ones which are using the wrong schema. Tip: tables that are not in diagram won't display a dot next to their name.
Optionally, you can delete the faulty schema from the model so this never happens again. Be sure to know what you're doing first!

SQLite Manager - Copy table to another .sqlite database

Working on my first iOS App with SQLite database. In Project I have 2 Database, in which First Database is having only one table and the another one is working as a main database. I want to merge those databases into one (the Second one), by copy the table from first database to second database. The First database Table contains more than 32K records. So, I want to copy the entire table with Data.
I want to achieve this using SQLManager AddOn of firefox.
Any Idea?
Instead of SQLManager, You can simply do this with one command line:
$ echo '.dump tablename' | sqlite3 sourcedb | sqlite3 destdb
Export the required table contents in to an excel sheet in sqlite manager and then import the excel file in the target database.
you can see the controls for import and export in sqlite manager itself.
I hope this may help u, since I used it.

How to avoid generating database table everytime

I am using MVC 3. I use Model first approach.
I created the Product Entity, in model folder. Which contains
ProductID
Name ---properties.
then, I create the SQL table from that model,It generates SQL table perfectly.
(I right click on model image and selects the option 'Generate database from model...'
then SQL window pop ups which contains all the DB scripts and I execute it.)
Now problem comes when, If I want to make changes in that model.
I have to recreate the table each time,so my data get lost.
whether, I have to generate SQL table every time when I make change in model?
How to avoid it?

Generating all 'data dictionary' reports under each 'object' in postgres

I have a database with about 50 something tables. I would like to run the report "Data Dictionary" on each table.
Ideally, I would like them all to be in one report, for example, in PGAdminIII, if I right click select "Tables" I will get a report of all the 'objects' and under each one a data dictionary report.
Is there an automatic way of doing this, or an plugin that I can install to postgres? Or is there something analogous to this?
If I understand correctly, you're referring to the ability to right mouse click on a table in PgAdminIII and select Reports > Data Dictionary report?
I'm not aware of any way to do that from PgAdminIII. You could look into using a different tool such as SchemaSpy. Another option (as alluded to by #kgrittn) is to use psql \d with the \H flag to generate html output. My solution (since SchemaSpy didn't do what I needed, and I needed the same output for both Postgres and Oracle) was to roll my own using perl, DBD::Pg and Template::Toolkit.
Update: Added GitHub link.
I wrote a fairly simple Postgres data dictionary generator in Python that spans all schemas and tables within a specified database. If it doesn't have exactly what you want it would be fairly easy to modify.
https://github.com/kylejmcintyre/pypostgreports

How do I point Crystal Reports at a new database

I have a Crystal Reports 2008 user that has over 100 custom developed reports.
The reports all query Sql Server databases (SQL 2005).
This database server is getting replaced with a new system (running SQL 2008 R2) and the existing databases will be moved to the new server.
The new database server will have a different name (which I can address via the Crystal Reports Connections),
however, one of the applications is also being upgraded at the same time. The old database (DB_A) will be restored on the new server for historical reporting and a new database (DB_B) will be created.
The new DB_B will have a very similar schema, so I would expect that most of the Crystal Reports should be able to run against the new DB_B with little or no modification other than pointing the report definition at the new DB_B.
Of course, the majority of my users custom developed reports query against DB_A.
My question is: How do I modify existing Crystal Reports files to point at the new database name (DB_B) instead of the old database (DB_A) ?
Use the Database menu and "Set Datasource Location" menu option to change the name or location of each table in a report.
This works for changing the location of a database, changing to a new database, and changing the location or name of an individual table being used in your report.
To change the datasource connection, go the Database menu and click Set Datasource Location.
Change the Datasource Connection:
From the Current Data Source list (the top box), click once on the datasource connection that you want to change.
In the Replace with list (the bottom box), click once on the new datasource connection.
Click Update.
Change Individual Tables:
From the Current Data Source list (the top box), expand the datasource connection that you want to change.
Find the table for which you want to update the location or name.
In the Replace with list (the bottom box), expand the new datasource connection.
Find the new table you want to update to point to.
Click Update.
Note that if the table name has changed, the old table name will still appear in the Field Explorer even though it is now using the new table. (You can confirm this be looking at the Table Name of the table's properties in Current Data Source in Set Datasource Location. Screenshot http://i.imgur.com/gzGYVTZ.png) It's possible to rename the old table name to the new name from the context menu in Database Expert -> Selected Tables.
Change Subreports:
Repeat each of the above steps for any subreports you might have embedded in your report.
Close the Set Datasource Location window.
Any Commands or SQL Expressions:
Go to the Database menu and click Database Expert.
If the report designer used "Add Command" to write custom SQL it will be shown in the Selected Tables box on the right.
Right click that command and choose "Edit Command".
Check if that SQL is specifying a specific database. If so you might need to change it.
Close the Database Expert window.
In the Field Explorer pane on the right, right click any SQL Expressions.
Check if the SQL Expressions are specifying a specific database. If so you might need to change it also.
Save and close your Formula Editor window when you're done editing.
And try running the report again.
The key is to change the datasource connection first, then any tables you need to update, then the other stuff. The connection won't automatically change the tables underneath. Those tables are like goslings that've imprinted on the first large goose-like animal they see. They'll continue to bypass all reason and logic and go to where they've always gone unless you specifically manually change them.
To make it more convenient, here's a tip: You can "Show SQL Query" in the Database menu, and you'll see table names qualified with the database (like "Sales"."dbo"."Customers") for any tables that go straight to a specific database. That might make the hunting easier if you have a lot of stuff going on. When I tackled this problem I had to change each and every table to point to the new table in the new database.
Choose Database | Set Datasource Location... Select the database node (yellow-ish cylinder) of the current connection, then select the database node of the desired connection (you may need to authenticate), then click Update.
You will need to do this for the 'Subreports' nodes as well.
FYI, you can also do individual tables by selecting each individually, then choosing Update.