Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Code Generation in Quick SQL Creates Randomly Ordered Tables, Leading to Script Execution Failures #72

Open
pallasinfotech opened this issue Nov 12, 2024 · 1 comment
Assignees

Comments

@pallasinfotech
Copy link

When generating SQL code in Quick SQL, the tool currently produces table creation statements in a the order it appears in the QuickSQL side order. This approach often results in dependency issues where a table that references another table is created before the referenced table, causing the script to fail upon execution.

It would be highly beneficial if Quick SQL could automatically analyze table dependencies and adjust the order of table creation accordingly. Specifically, the tool should:

Generate tables without dependencies first.
Follow with tables that reference other tables, ensuring referenced tables are created prior to the dependent ones.
This enhancement would ensure that even large models can be executed without manual intervention, improving efficiency and reliability.

Use Case:
Quick SQL is an incredibly powerful tool that significantly reduces development time while ensuring the accuracy of triggers and packages. However, when working with medium to large models (e.g., 50 or 100 tables tables), the current behavior of generating SQL statements in a random order creates substantial overhead.

In my case, every time I regenerate SQL for my 62-table model, the table creation order changes. As a result, running the script fails unless I manually reorder the CREATE TABLE statements. This manual step negates some of the time-saving benefits Quick SQL is meant to provide.

Implementing dependency-aware script generation would eliminate this issue, allowing developers to focus more on design and less on troubleshooting script execution.

@vadim-tropashko vadim-tropashko self-assigned this Nov 16, 2024
@vadim-tropashko
Copy link
Member

Why tables have to be ordered? Here is the test:

 SQL> create table abc_emp (
  2      id             number generated by default on null as identity
  3                     constraint abc_emp_id_pk primary key,
  4      deptno         number,
  5      ename          varchar2(4000 char)
  6*  );

Table ABC_EMP created.

SQL> 
SQL> create index abc_emp_i1 on abc_emp (deptno);

Index ABC_EMP_I1 created.

SQL> 
SQL> create table abc_dept (
  2      id             number generated by default on null as identity
  3                     constraint abc_dept_id_pk primary key,
  4      dname          varchar2(4000 char)
  5* );

Table ABC_DEPT created.

SQL> 
SQL> 
SQL> alter table ABC_EMP add constraint  abc_emp_deptno_fk  foreign key (DEPTNO)  references ABC_DEPT;

Table ABC_EMP altered.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants