Identifying a missing primary key


 
Thread Tools Search this Thread
Top Forums Programming Identifying a missing primary key
# 1  
Old 04-06-2013
Identifying a missing primary key

I have the following method to identify missing primary keys in a MySQL database schema:
Code:
USE information_schema;
SELECT xx.table_name 
FROM (SELECT table_name, COUNT(*) FROM columns WHERE table_schema = @myDB GROUP BY table_name, column_key) xx 
GROUP BY xx.table_name 
HAVING COUNT(*) = 1;

I am not particularly enamored with the xx solution, because one can never be certain that a table with that name does not already exist. Does anyone know of a solution which is more elegant?
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Identifying missing file dates

Hi Experts, I have written the below script to check the missing files based on the date in the file name from current date to in a given interval of days. In the file names we have dates along with some name. ex:jera_sit_2017-04-25-150325.txt. The below script is working fine if we have only... (10 Replies)
Discussion started by: nalu
10 Replies

2. Shell Programming and Scripting

Shell Script @ Find a key word and If the key word matches then replace next 7 lines only

Hi All, I have a XML file which is looks like as below. <<please see the attachment >> <?xml version="1.0" encoding="UTF-8"?> <esites> <esite> <name>XXX.com</name> <storeId>10001</storeId> <module> ... (4 Replies)
Discussion started by: Rajeev_hbk
4 Replies

3. Solaris

Primary key issue when running Oracle sql file

I got a issue with running the following script below if I remove the inserts and alter table the tables will install just fine but if I try and do the full thing in one go i get the below error dose any one have any ideas on this problem? its got me spinning, thanks. REM REM List of... (1 Reply)
Discussion started by: Wpgn
1 Replies

4. Shell Programming and Scripting

Identifying Missing File Sequence

Hi, I have a file which contains few columns and the first column has the file names, and I would like to identify the missing file sequence number form the file and would copy to another file. My files has data in below format. APKRISPSIN320131231201319_0983,1,54,125,... (5 Replies)
Discussion started by: rramkrishnas
5 Replies

5. Red Hat

Yum - resolving missing dependencies that are not missing

I am trying to install VirtualBox on RHEL 5 but I need the 32 bit version for 32 bit Windows. When I run yum I get the following: sudo yum localinstall /auto/spvtg-it/spvss-migration/Software/VirtualBox-4.3-4.3.2_90405_el6-1.i686.rpm Loaded plugins: fastestmirror Setting up Local Package... (13 Replies)
Discussion started by: gw1500se
13 Replies

6. SuSE

How to resolve missing missing dependencies with opensuse 11.3 and 12.3?

Hello, This is a programming question as well as a suse question, so let me know if you think I should post this in programming. I have an application that I compiled under opensuse 12.2 using g77-3.3/g++3.3. The program compiles and runs just fine. I gave the application to a colleague who... (2 Replies)
Discussion started by: LMHmedchem
2 Replies

7. Programming

MySQL auto_increment, primary key

Hello, I want to create a table in mysql database by loading the local file. I am confused with the auto_increment column (say Run_ID) that I want to set it as primary key. My questions are: 1) Do I need add this Run_ID in my file ready? then this does not make any sense to the auto_increment;... (5 Replies)
Discussion started by: yifangt
5 Replies

8. Solaris

Solaris 8 ssh public key authentication issue - Server refused our key

Hi, I've used the following way to set ssh public key authentication and it is working fine on Solaris 10, RedHat Linux and SuSE Linux servers without any problem. But I got error 'Server refused our key' on Solaris 8 system. Solaris 8 uses SSH2 too. Why? Please help. Thanks. ... (1 Reply)
Discussion started by: aixlover
1 Replies

9. UNIX for Dummies Questions & Answers

Pressing backspace key simulates enter key

Hi, Whenever i press the backspace key, a new line appears, i.e. it works like a enter key. :confused: Thanks (2 Replies)
Discussion started by: vibhor_agarwali
2 Replies
Login or Register to Ask a Question
Parse::Dia::SQL::Utils(3pm)				User Contributed Perl Documentation			       Parse::Dia::SQL::Utils(3pm)

NAME
Parse::Dia::SQL::Utils - Helper class for Parse::Dia::SQL. SYNOPSIS
Not to be used directly. DESCRIPTION
Utility functions for Parse::Dia::SQL. set_default_pk Define primary key column names and types for automatic generation of primary keys in tables that need them, but do not have them defined. new The constructor. No arguments. new get_node_attribute_values Given a node with dia:attribute nodes inside it, go through the dia:attribute nodes with attribute "name='...'" and return the string values @infosToGet is an array of strings, where the first character is the data type to get, and the remaining characters are the name to parse for. first character legal values are: a = alpha 9 = numeric b = boolean example: aname, 9dollars, bkillOrNot get_string_from_node If it looks like <thingy><dia:string>value</dia:string></thingy> then we will get the 'value' part out given the node is 'thingy'. get_value_from_object Given an object, node name, attribute name, attribute value, and value to retrieve type, find the info and return it. get_node_from_object Given an object, node name, attribute name, and attribute value, return the node that has all these things. name_case Transform case for name comparisons to that of the database; leave unchanged if -C (preserve case) is in effect. Only sybase is known to be case sensitive. get_num_from_node Return value part of <dia:enum val="value"></thingy>. get_bool_from_node Return value part of <thingy><dia:boolean val="value"></thingy>. classify_multiplicity Look at a multiplicity descriptor and classify it as 'one' (1, or 1..1), 'zone' (0..1), 'many' (n..m, n..*, where n > 1, m >= n) and 'zmany' (0..n, 0..*, where n > 1) attlist_from_names Generate a list of attributes from a comma-separated list of names by looking up a class' attribute table. names_from_attlist Generate a comma-separated list of attribute names from a list of attributes. check_att_list_types Check that a list of primary key attributes has types corresponding to the types in a list of foreign key attributes get_base_type Check that a list of primary key attributes has types corresponding to the types in a list of foreign key attributes. Returns base type of some DMBS specific types (eg in PostgreSQL serial is integer). AFF note: This is better implemented in each sql formatter class. make_name Generate a longer name from parts supplied. Except for the first part, the first letter of each part is capitalised. If lcFirstWord is set, then any initial string of capitals in the first part is made lower case; otherwise the first part is left unchanged. Dies if $self->{db} is not set. The @parts_org values are save for "Desperation time" :) name_scramble PSuda: Name scrambling helper function, for code which auto-generates names. Takes one arg, which is string to use for md5 hashing. This returns names which consist entirely of underscores and alphanumeric characters, and starts with one or more alpha characters. mangle_name Get a name to mangle and mangle it to the length specified -- avoid too much manglification if the name is only slightly long, but mangle lots if it's a lot longer than the specified length. add_default_pk For -p - add a default primary key to a parsed table definition TODO : Add a meaningful return value. add_default_fk For -f - add missing parts of a default foreign key to a parsed table definition. perl v5.14.2 2011-02-16 Parse::Dia::SQL::Utils(3pm)