How do I get a list of all tables in a mysql db, ordered by foreign key dependencies?

I want a list of tables, ordered by foreign key. So if table "Book" has a FK dependency on table "Author", Author would be listed first and Book second. I have no cyclic dependency loops but I do have a few self-join relationships (table has an FK dependency on itself). I would like a script to generate this list. (Or perhaps a recursive CTE in mysql 8?)

I can get the foreign key dependencies from: (mysql query)

select CONSTRAINT_NAME, TABLE_NAME, REFERENCED_TABLE_NAME from information_schema.referential_constraints where constraint_schema = 'DBName' order by TABLE_NAME; 

And the table-list from:

show full tables where table_type <> "VIEW"; 

Background: I would like to copy my mysql db-schema into an in-memory H2 database for testing. But H2 does not support full mysql syntax. In particular FOREIGN_KEY_CHECKS=0 is not supported and H2 SET REFERENTIAL_INTEGRITY FALSE only applies to insert/update-constraint-checks not table-creation. So my tables need to be created in the correct order, according to FK dependencies.

I can dump the schema with mysqldump. But mysqldump does not order the table creation by foreign keys. If table "Child" has a FK dependency on table "Parent", mysqldump appears to put the table-creation in alphabetical order so Child will be created before Parent even though it depends on Parent. It relies on disabling foreign key checks while all the tables are created.

So if I had a list of table names, in fk order, I could pass that to mysqldump to dump the schema.

Determine third normal form in case of two functional dependencies

Assume I’m given an entity E which has attributes A, B and C, (each of them is a candidate key, but let’s say I can introduce some EID that serves as a PK) with functional dependencies: A determines C and B determines C. How would I get this into a third normal form?

I have tried the following:


but in this representation, I’m have the attribute C twice in my database. Can anyone advise on a more appropriate way of getting into a third normal form?

How to find efficiently all positive linear dependencies between some vectors

I’ve got these vectors

vecs= {{0,1,0,0,0,0,0,-1,0},    {1,-1,1,0,0,0,-1,1,-1},  {1,0,-1,1,0,-1,1,0,-1},  {1,0,-1,1,0,0,-1,0,1},   {1,0,0,-1,0,1,0,0,-1},   {1,0,0,-1,1,-1,1,-1,1},  {1,0,0,0,-1,0,0,1,0},    {-1,0,1,0,0,-1,1,0,-1},  {-1,0,1,0,0,0,-1,0,1},  {-1,1,-1,1,-1,1,0,0,-1}, {-1,1,-1,1,0,-1,1,-1,1}, {-1,1,0,-1,0,1,0,-1,1},   {-1,1,0,-1,1,-1,0,1,0},  {0,-1,0,0,1,0,0,0,-1},   {0,-1,0,1,-1,1,0,-1,1},  {0,-1,0,1,0,-1,0,1,0},   {0,-1,1,-1,0,1,-1,1,0},  {0,0,-1,0,0,0,1,0,0}} 

And I would like to find all linear dependencies with positive coefficients between them. I started with

ns = NullSpace[Transpose[vecs]]  

which gave me

{{2,2,-1,0,-1,0,0,0,0,0,0,0,0,0,0,0,0,3},  {2,-1,2,0,-1,0,0,0,0,0,0,0,0,0,0,0,3,0},   {2,-1,-1,0,2,0,0,0,0,0,0,0,0,0,0,3,0,0},  {1,1,1,0,1,0,0,0,0,0,0,0,3,0,3,0,0,0},   {2,-1,-1,0,-1,0,3,0,0,0,0,0,0,3,0,0,0,0}, {-1,2,2,0,-1,0,0,0,0,0,0,3,0,0,0,0,0,0},   {-1,2,-1,0,2,0,0,0,0,0,3,0,0,0,0,0,0,0},  {-1,2,-1,0,-1,3,0,0,0,3,0,0,0,0,0,0,0,0},   {-1,-1,2,0,2,0,0,0,3,0,0,0,0,0,0,0,0,0},  {-1,-1,-1,3,2,0,0,3,0,0,0,0,0,0,0,0,0,0}} 

so there is one linear dependence with nonnegative coefficients (the fourth one). To check whether there are others, I made a system of inequalities with

ineqs = Simplify[Union[Map[# >= 0 &, Table[x[k], {k, Length[ns]}].ns]]] 

which returns

{x[1]>=0,x[2]>=0,x[3]>=0,x[4]>=0,x[5]>=0,x[6]>=0,x[7]>=0,x[8]>=0,x[9]>=0,x[10]>=0,  2 x[1]+2 x[2]+2 x[3]+x[4]+2 x[5] >= x[6]+x[7]+x[8]+x[9]+x[10],  2 x[1]+x[4]+2 (x[6]+x[7]+x[8])   >= x[2]+x[3]+x[5]+x[9]+x[10],  2 x[2]+x[4]+2 (x[6]+x[9])        >= x[1]+x[3]+x[5]+x[7]+x[8]+x[10],  2 x[3]+x[4]+2 (x[7]+x[9]+x[10])  >= x[1]+x[2]+x[5]+x[6]+x[8]} 

but my notebook runs out of memory on both Solve[ineqs] and Reduce[ineqs].

What is the proper way?

Finding two nontrivial functional dependencies that follow from F (but are not in F)

Given below is the set F of functional dependencies for the relational schema:

R = {A,B,C,D,E,F,G}.  F = {AB → C,BC → D,G → F,AE → FG} 

Show two nontrivial functional dependencies that follow from F:

Which is :



I don’t know how those two derived from? Could someone walk me through? thanks

understanding makefiles & their dependencies

In a practice question, I was supposed to derive a dependencies graph from a given make-file. I couldn’t find any relevant examples online but I attempted the following. Is this what is expected?

enter image description here

all: prog x.o: x.cpp globals.hh $  (CC) -c x.cpp y.o: y.cpp globals.hh $  (CC) -c y.cpp prog: x.o y.o $  (LD) -o prog x.o y.o -lc 

Also, I would like to understand what happens if we repeat make all after altering either x.cpp or the headers file after.

From what I understand, if I run make all once and then change x.cpp, the following commands will be re-run:

$  (CC) -c x.cpp and -o prog x.o y.o -lc 

and in case of the headers file, I think all three will re-run when I do make all again. Am I correct? What would be the sequence?

Shortest sequence of jobs, with dependencies, subject to capacity constraints

Suppose I have $ n$ courses, some with some prerequisites, and I can take up to $ k$ courses in a semester. I want to compute the least number of semesters needed to complete all courses, while respecting prerequisites.

Equivalently: suppose I have a dag $ G=(V,E)$ , and a positive integer $ k$ . The desired output is a sequence $ S_1,\dots,S_m$ of vertices that minimizes $ m$ , subject to the constraint that $ S_1 \cup \dots \cup S_m = V$ , $ |S_i| \le k$ for all $ k$ , and every edge goes from some set $ S_i$ to $ S_j$ where $ i<j$ (i.e., there is no edge $ v \to w$ where $ v\in S_i$ , $ w\in S_j$ , and $ i \ge j$ ).

Is there a polynomial-time algorithm for this problem?

Approaches I’ve considered:

The obvious greedy strategy is a variant of Kahn’s algorithm is: in each semester, arbitrarily pick $ k$ courses whose prerequisites have all been previously taken, and take those $ k$ courses. Unfortunately, this algorithm is not guaranteed to generate an optimal schedule. For example, in the graph with vertices $ v_1,v_2,v_3,v_4$ and the single edge $ v_1 \to v_2$ , with $ k=2$ this algorithm might generate the schedule $ \{v_3,v_4\},\{v_1\},\{v_2\}$ , which is longer than the optimal schedule $ \{v_1,v_3\},\{v_2,v_4\}$ .

The next natural idea is to modify the above approach by breaking ties in favor of vertices that are part of longer dependency chains. I’m not sure whether this works or not.

Inspired by taking school courses efficiently.

How many RAW dependencies are present in these instructions?

What is the number of RAW dependencies in below set of instructions?

I1: R1 = R2 - R3 I2: R2 = R1 + R3 I3: R3 = R1 + R2 I4: R1 = R2 - R2 

I can see the following RAW dependencies in it:

$ I_2-I_1\ for\ R_1$ ……… (a)

$ I_3-I_1\ for\ R_1$ ……… (b)

$ I_3-I_2\ for\ R_2$ ……… (c)

$ I_4-I_2\ for\ R_2$ ……… (d)

I think taking (a) and (b) implies that (c) has already been included. So, should this be counted as 4 RAW dependencies or 3 RAW dependencies?

How to formally prove the dependencies of a computer malware?

I’m in the process of the writing a thesis. A small part of it is to prove that certain malware have certain dependencies which must first be satisfied before they are successful in infecting the host. For instance, a virus must first get on the host and then start executing before infection.

  • Dependency 1: getting on the host
  • Dependency 2: executing

We know these dependencies to be true from experience and common sense, however, how would be go about formally proving these in computer science? I am not asking for all the proofs (I realize that that’s my job!), but just how to approach them since right now I see no way to formally prove it.

What are the types of these functional dependencies?

I was wondering if anyone could help me solve this homework problem I have for my database management class. We were given this table:

Table assigned to me

We were then given the following functional dependencies

CourseID -> CourseLanguage, CourseLevel ClientID -> ClientName CourseID, ClientID -> Attendance, FinalScore 

We had to identify each dependency by the types of full, transitive, or partial.

I have come to the following conclusions and want to know if they are logical:

  • The first dependency is partial because CourseLanguage and CourseLevel are both determined by CourseID, which is part of a composite primary key
  • The second dependency is also partial because ClientName is determined by ClientID, which is part of a composite primary key
  • The third dependency is full because the entire primary key determines the columns attendance and final score.

Thank you for your time and help!

Checking to see if my relation is in 3NF based on the functional dependencies

I have a relation, called Score (which stores scores of football games), and it has the following functional dependencies for its various attributes G, H, T, S, W, D, and O (representing GameID, HomeOrAway, TeamID, Season, Week, Date, and Outcome):


SD → W


D → SW

I would like to know if Score is in 3NF, or if not, suggest a decomposition that achieves 3NF. Can you guys help me go about figuring this out? I know that for each functional dependency, I need to check that the left side contains a key for Score, but I’m not sure how to really go about doing that. Any help would be greatly appreciated!