Finding MySQL Tables with no primary key OR no composite keyAre these custom module Drupal tables lacking...
Avoiding morning and evening handshakes
Explain the objections to these measures against human trafficking
How to deal with an incendiary email that was recalled
Would the Vulcan nerve pinch work on a Borg drone?
My cat mixes up the floors in my building. How can I help him?
Why has the mole been redefined for 2019?
How can I get my players to come to the game session after agreeing to a date?
Why Prushim were the ones who "separated"?
Publishing research using outdated methods
Are there any modern advantages of a fire piston?
Why would the Pakistan airspace closure cancel flights not headed to Pakistan itself?
Could a phylactery of a lich be a mirror or does it have to be a box?
How to avoid being sexist when trying to employ someone to function in a very sexist environment?
Math Saturation Symbol
awk + sum all numbers
One Half of Ten; A Riddle
Porting Linux to another platform requirements
Why is mind meld hard for T'pol in Star Trek: Enterprise?
Normalization for two bulk RNA-Seq samples to enable reliable fold-change estimation between genes
Using only 1s, make 29 with the minimum number of digits
What is the wife of a henpecked husband called?
How to count the characters of jar files by wc
How do Chazal know that the descendants of a Mamzer may never marry into the general populace?
Roman Numerals equation 1
Finding MySQL Tables with no primary key OR no composite key
Are these custom module Drupal tables lacking foreign keys? mysqldump with table structures without data is includedBatch converting indexes to keysPhpmyadmin / mysql error defining primary keys as foreign keys of two separate tablesConverting a composite primary key to composite unique, and adding an auto-incremented PK columnForeign key on partial primary keyFinding Damage Done by FOREIGN_KEY_CHECKS=0Is there a possibility to see cascade path in MS SQLForeign key constraint across tablesComposite Primary Key on partitioned tables, and Foreign KeysHow to find which foreign key constraints a table row is associated with?
I can easily find tables that do not contain a PK from information_schema, but I'm having a tough time writing the logic to find tables that might contain neither a PK nor a CK (via two FKs).
What I need is a for loop that says for each table if there is no instance of a PRIMARY KEY constraint_type then select it where there are at least 2 records of it where constraint_type is FOREIGN KEY.
To be honest I'm not even sure where to begin. It's been a long while since I wrote a FOR loop in SQL.
foreign-key primary-key
add a comment |
I can easily find tables that do not contain a PK from information_schema, but I'm having a tough time writing the logic to find tables that might contain neither a PK nor a CK (via two FKs).
What I need is a for loop that says for each table if there is no instance of a PRIMARY KEY constraint_type then select it where there are at least 2 records of it where constraint_type is FOREIGN KEY.
To be honest I'm not even sure where to begin. It's been a long while since I wrote a FOR loop in SQL.
foreign-key primary-key
add a comment |
I can easily find tables that do not contain a PK from information_schema, but I'm having a tough time writing the logic to find tables that might contain neither a PK nor a CK (via two FKs).
What I need is a for loop that says for each table if there is no instance of a PRIMARY KEY constraint_type then select it where there are at least 2 records of it where constraint_type is FOREIGN KEY.
To be honest I'm not even sure where to begin. It's been a long while since I wrote a FOR loop in SQL.
foreign-key primary-key
I can easily find tables that do not contain a PK from information_schema, but I'm having a tough time writing the logic to find tables that might contain neither a PK nor a CK (via two FKs).
What I need is a for loop that says for each table if there is no instance of a PRIMARY KEY constraint_type then select it where there are at least 2 records of it where constraint_type is FOREIGN KEY.
To be honest I'm not even sure where to begin. It's been a long while since I wrote a FOR loop in SQL.
foreign-key primary-key
foreign-key primary-key
asked 6 mins ago
tadamhickstadamhicks
1063
1063
add a comment |
add a comment |
0
active
oldest
votes
Your Answer
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "182"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fdba.stackexchange.com%2fquestions%2f231011%2ffinding-mysql-tables-with-no-primary-key-or-no-composite-key%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
0
active
oldest
votes
0
active
oldest
votes
active
oldest
votes
active
oldest
votes
Thanks for contributing an answer to Database Administrators Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fdba.stackexchange.com%2fquestions%2f231011%2ffinding-mysql-tables-with-no-primary-key-or-no-composite-key%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown