How to 'follow' foreign keys in a SQL client - mysql

I am currently using Sequel Pro to view my database. I find much of my time spent on 'following' foreign keys. For example, if an entry in table A links to table B, I find myself writing down the id number, then clicking the other table, scrolling down to find that id, etc. It becomes quite tedious.
Is there a way in Sequel Pro or in another SQL client to link to the FK (e.g., double click the FK and it takes you to that entry)?

You can benefit from the foreign key lookup editor for easy editing of fields referencing other tables in dbForge Studio for MySQL.

Related

Talend Open Studio data migration with MySQL on parent-child relation

I am using Talend Open Studio for data migration as I am upgrading my existing application architecture to a new one. I am using MySQL in both the applications but with different schema. I have migrated data successfully between single tables but while I am transferring data from a single table to a parent-child relationship table with a foreign key constraint, the data transfer is tremendously slow.
For e.g. I am migrating my Cities table to Cities and Citiesi18n and below is the schema for them:
My old schema :
CITIES (
id
city_name
status
created_at
)
The newly created schema where I need to migrate the data :
CITIES (
id
status
created_at
)
CITIESI18N (
id
lang_code
name
fk_city_id (// foreign key of cities table)
)
Below are the snapshots from my Talend jobs:
And here is the tmap configuration :
Now when I transfer the data without the foreign key the result are super fast. See below :
But the same when I transfer with a foreign key, my transfer is super slow :
(Note: I have taken province table for example as it is similar to cities table)
I think with Foreign key constraint it must be indexing the columns while transferring the data making it slower, but I am not sure. Is there any way I can fix this as I have a lot of tables similar to this which needs to be migrated. I am just curious to know the reason.
I don't know why you have this behaviour : you can try to redirect 'provience_i18n' to a tHashOutput (cache component), then link to a subjob with tHashInput (refering to your tHashOutput)-->tMySQLOutput. You'll have 2 subjobs, one for each insertion.
You are loading data to the parent & child at the same time. Using one tmap. When you are inserting foreign key in the second table, there is also insertion being made in the foreign/parent table. What you could alternatively do is: Load the data in the main CITIES table first, then onSubJobOk, load into child/CITIESI18N table. It would be faster. Let me know if it works.

Remote foriegn key on SQL Server

I am building a database on SQL Server 2014. I have a users table and a profiles table and I need to have a relationship with both these tables. I am relating the userid (primary key on user table) to the profiles table (userid there as foreign key). This is just an example to consider.
What I need to know is, what if the profiles table is on another server instance? Is there a way with which I can link both? The reason is that I don't want to overload the sql server with too many tables and data...
Thanks,
Sarin Gopalan
It is not at all possible to create foreign key relations between databases - let alone between server instances.
You might be able to create a trigger on the Profiles table, that checks if a userid exists in the User table in the other database, but I fear the performance of this approach will be very bad.
A much better solution would be to replicate one table to the other database, and then create the foreign key relations in a normal way. How you replicate the table (SSIS, CDC, triggers, etc.) is up to you.

manually choose foreign key column mysql workbench

Let's say I have a bunch of MyISAM tables in a MySQL database. I know that if my tables are InnoDB MySQL Workbench will pick up the relationships between the tables automatically. But if my tables are MyISAM, is there a way that I can select which column to use as a foreign key in MySQL Workbench without MySQL Workbench adding a column in my table schema? For example, let's say I have these columns in a table called users:
id PRIMARY KEY
username VARCHAR (255)
password VARCHAR (255)
email VARCHAR (255)
user_type_id INT
As you can see above, user_type_id would be a foreign key coming from a table called user_types. If I add a many-to-one relationship between my tables users and user_types in MySQL Workbench, a column user_types_id will be automatically added to the schema of my table users (because that's what MySQL Workbench considers as a foreign key usually). I don't want that to happen, I want to be able to tell MySQL Workbench to use the column user_type_id as my foreign key. Any way I can do that?
Thank you
NOTE: There is a Foreign Keys tab when I double click on a table on the model view in MySQL Workbench, but when I do so, I get the following text:
Note: foreign keys can only be defined for certain storage engines (like InnoDB). The server accepts foreign key definitions for other storage engines but silently ignores them. Switch your table engine to one that supports foreign keys to allow adjustments here.
You could temporarily switch to InnoDB, define the relationship and switch back to MyISAM. The relationships will remain. BUT, they are of no real use except to document your intention.
If that's all you want then go ahead.
Btw: the FK tab page is only unavailable on Windows (for engines that don't support FKs), as we have seen many complaints from users that defined FKs for MyISAM, just to see no effect in their target DB. On Linux + OS X you can work on FKs regardless of the selected storage engine.
If I'm understanding your question correctly, I believe you can do this from the Foreign Keys tab on the table itself. If you double click a table from the model overview, on the bottom tabs there is a Foreign Key tab. You can manually add in foreign keys however you choose from that dialog. Does that make sense?

access 2010 with linked sql tables

I have a split form view with data coming from linked sql server (2008).
How do I go about updating the record?
Currently, it will not let me change anything in the text boxes i assume this is because the data is coming from linked tables?!
In order to update do i have to create command and coonn objects and program it in the usual vb manner?
And if so, what is the syntax for referencing the linked tables when creating the update query?
On my split form I dropped a button on there and I can see options to make it run macro, run code, etc etc, which one is suitable?
many thanks,
KS
First make sure the table was not linked read-only.
When you link to a remote table, Access will make it read-only if it is unable to identify a primary key or another combination of fields to uniquely identify each row. Sometimes, but not always, it may ask you to tell it which field(s) to use as the primary key if it is uncertain.
But this issue is simple to check. Open the linked table directly in Datasheet View and see whether you can edit any values. If not, re-link the table and look for an option to inform Access about the primary key.
If the link is not read-only, make sure your form's Allow Edits property is set as Yes.
Also you could try a simple form rather than a split form to determine whether something about the split form is causing the problem.
Solution:
MS Access barfs when trying to register tables with a primary key of type BigInt which is 8 bytes, Access can only handle Ints of 4 bytes. Workaround is below:
Drop the constraint (bigint PK) in SQL table
Create a new primary key (int) with identity seed
Link the table in MS Access
Drop new constraint (int PK) & Re-Add your previous constraint (bigint PK) in MS SQL
Voila!

SQL 2008 Management Studio-- where to find table relationships?

I'm brand new to SQL Server 2008, and have some newbie questions about the diagram pane. I just dragged two tables onto it to do an inner join, and the console "knew" to create a one-to-many relationship between them. Where is this information kept in the Management Studio for me to look at closer?
Thanks!
Much of this information is actually available in system tables in the database containing the user tables.
Here are two of the available tables of interest. sys.tables contains table information, sys.foreign_keys contains relationship information via foreign key constraints.
sys.tables (Transact-SQL) # MSDN
sys.foreign_keys (Transact-SQL) #MSDN
Also handy is the following information on Pinal Dave's site on using this information for your own lookups.
Find tables with Foreign Key Constraint in Database # SQLAuthority.com
Find Relationship of Primary key and Foreign Key using T-SQL # SQLAuthority.com
One of the tables has a foreign key referencing the other table. In Object Explorer, expand the information for the tables involved and look under Keys.