I have two databases on two different physical servers. At this time, I want to make relation between some tables in database1 and some tables in database2. I want to know is there anyway for doing that?
Note I have both mysql and oracle databases on my two servers and I can use them. Is it possible to make join between to physical databases with mysql or oracle?
Hamed, check this out.
In oracle it is possible to have a foreign key constraint based on a view. So follow these steps:
first: create a view to a table on the remote database. example:
create view test_view_dblink as
select * from some_table#some_dblink;
second: create a foreign key constraint on the view. example:
alter view test_view_dblink
add constraint test_view_dblink_fk foreign key (column_name)
references table_view_in_your_database(column_name) disable;
the "disable" in the constraint definition is very important.
in my environment this works perfect!
You can also have a primary key:
alter view test_view_dblink
add constraint test_view_dblink_pk primary key (column_name) disable;
Related
I am creating a table using the GUI in phpMyAdmin mySQL hosted on an Apache web server (XAMMP).
How do I define a column as a foreign key and where do I insert the reference to the corresponding primary key? There is a drop down option for Primary Key but I don't see any such option for a foreign key.
Thanks
Find the Relation view see picture and there you can define our foreign keys.
There is no option of relation view in GoDaddy phpMyAdmin
so how do I set relation.
I tried manually by using query but it does not work.
Is there any way I can set relation between two tables.
Even there is no any solution on Google about GoDaddy phpMyAdmin.
If I'm working on local there is option of relation view but on godady there is no option.
How do I alter tables?
Working on this since last 2 hours and I'm new at this
I use this query for relation
ALTER TABLE co_pass_ticket_book
ADD CONSTRAINT ticket_id_fk
FOREIGN KEY (ticket_id)
REFERENCES booking_table(ticket_id);
I need to create the database schema and include it in my software requirements specification for my school project, however, when I try to create a relationship between 2 tables, I get Error: Missing index on column(s).
I think #HazarathChillara has this right; you need to create primary, unique, or index keys.
You said every table has an primary key, but did you make each foreign and referenced key an index as well? It sounds like you neglected to properly set up your table structure; I only get the error when I don't have a primary key or index on the particular columns I'm working with.
"MySQL requires indexes on foreign keys and referenced keys so that foreign key checks can be fast and not require a table scan"
You can just put an INDEX on the foreign key (often my referenced key is a primary key anyway, so I don't need any additional key on that column).
This error appears only when you neglect table structure. Make sure that you Indexed a foreign key as well. you can see i marked how could i select my foreign key as index.In this Image I am indexing selected, 'sr' my foreign key
As Usman Khan said you have to go to the structure tab of the particular table and clicked on more options and select 'INDEX' for the foreign key.
the below image will help you how to do it
I think i have another simple solve,
thing is, phpMyAdmin wont allow the addition of foreign keys to an already available data entry, so here is the my simple solve,
1. ensure to backup your database
2. confirm that your data was backed-up securely, recommended Offline backups
4. delete all data entries in all tables that will be part of the new relationship.
5. now Create the relevant relationships.
6. be sure you have created all required and preferred relations to avoid the need to
export data again
I have a schema on my db where there are some tables. I have to create a table into this schema and i have to connect it with the others already present on the schema.I make an example:
Tables already present:
SCHOOL(IdSchool,NumStud,IdCountry);
SHOP(IdShop,IdCountry);
New table:
Country(IdCountry,....);
I want to know if there is an automatic mode to connect them (it means not to set the foreign key manually).
I want to know if there is an automatic mode to connect them (it means not to set the foreign key manually).
No.
How is the DBMS to know that Country.IdCountry and SCHOOL.IdCountry are given the same name with the intention to be connected, instead of just accidentally?
You'll have to use ALTER TABLE ... ADD FOREIGN KEY (...) REFERENCES ...1 to explicitly create the foreign key in the existing table.
1 Or ALTER TABLE ... ADD CONSTRAINT ... FOREIGN KEY (...) REFERENCES ....
I have an InnoDB table claims which has about 240 million rows. The table has a foreign key constraint: CONSTRAINT FK78744BD7307102A9 FOREIGN KEY (ID) REFERENCES claim_details (ID). I want to delete the table claim_details as quickly as possible.
Based on some experimentation it seems that if I use SET foreign_key_checks = 0; drop claim_details and then re-enable foreign keys, mysql will continue to enforce the constraint even though the table no longer exists. So, I believe I must drop the constraint from the table.
I have tried to use ALTER TABLE claims DROP FOREIGN KEY FK78744BD7307102A9 to drop the constraint and the query has been in a state of "copy to tmp table" for over 24 hours (on a machine with no other load). I don't understand why dropping a constraint requires making a copy of the table. Is there any way to prevent this?
mysql version 5.1.48.
Starting with MySQL 5.6, MySQL supports dropping of foreign keys in-place/without copying. Oracle calls this Online DDL.
This table lists all Online DDL operations and their runtime behavior.
From my experience, dropping foreign keys and the corresponding constraints on a 600GB table is almost instantaneous. With 5.5 it would probably have taken days.
The only disadvantage that I am aware of is, that 5.6 does not allow you to reclaim table space. I.e. if you are using innodb_file_per_table, that file will not shrink when you drop indices. Only the unused data in the file will grow. You can easily check using SHOW TABLE STATUS, and the Data_free column.
I think there is no a good way to drop that foreign key
http://dev.mysql.com/doc/refman/5.5/en/innodb-create-index-limitations.html
"MySQL 5.5 does not support efficient creation or dropping of FOREIGN KEY constraints. Therefore, if you use ALTER TABLE to add or remove a REFERENCES constraint, the child table is copied, rather than using Fast Index Creation." This probably refers also to older versions of mysql.
I think the best method will be to dump data from claims with mysqldump, recreate table without foreign key referencing to claim_details, disable key check with SET foreign_key_checks = 0; in case you have other foreign keys and import back data for claims. Just remember to make separate dumps for data and structure so you don't need to edit this huge file to remove foreign key from table creation syntax.