Designing ERDs within DDL (Create Table Statement)

In summary, the conversation revolves around the possibility of using DDL statements to express relationships between tables in a database schema and ultimately create an ERD as output. There are tools and methods available, such as using metadata tables and the 'start with connect by' tree creation SQL statement, to achieve this. One person also suggests using CONSTRAINT to link the foreign key column to the key column in the relationship.
  • #1
WWGD
Science Advisor
Gold Member
7,007
10,465
Hi again,
just curious as to whether it is possible to use DDL (Data definition, i.e., non-GUI ); more specifically to add something to the usual create table statements to express the relation between tables, i.e., these tables being either in 1:1, M:1 or M:N relation (so that a new, bridge table with default primary keys would be created )?

We seem to already have gone a good part along the way, having info on FKeys and what fields
they reference in other tables. Is there additional code to allow for this, i.e., to allow for the description of these relations and to ultimately have as an output the ERD of the relation?

Thanks.
 
Technology news on Phys.org
  • #2
  • Like
Likes WWGD
  • #3
You can specify that keys are unique or not in the table and you can specify whether fields can be null or not.

Are you designing a database schema or trying to understand database programming?

Have you looked at star schema design?
 
  • #4
jedishrfu said:
You can specify that keys are unique or not in the table and you can specify whether fields can be null or not.

Are you designing a database schema or trying to understand database programming?

Have you looked at star schema design?
Hi, both actually, I am trying to understand in general and use for designing schemas. It would be great to hve a full ERD as output without the need to use GUIs.
 
  • #5
You can use metatdata tables (in Oracle example: all_tab_columns, all_tables, etc.) to use the 'start with connect by' tree creation SQL statement to create an ERD.

You've essentially asked the same question multiple times. Question== "I want to automagically create an ERD".

Answer:
I do not know mysql (what you seem to use) from beans. But, I do know there are free tools to analyze table metadata out there. Start googling, some terms:
database, metadata, analysis, entity relationships.

Personally, I find most ERD's for commerically produced database application systems to be a digression. As well as requiring a huge wall to display the darned thing on paper. Whenever something trancends normal human perception limits, its usefulness is quite limited.

There is a reason for metadata tables other than to keep the db engine amused: ERD information is one select statement. How do you suppose, for an existing application, someone created an ERD to start with?
 
  • #6
jim mcnamara said:
You can use metatdata tables (in Oracle example: all_tab_columns, all_tables, etc.) to use the 'start with connect by' tree creation SQL statement to create an ERD.

You've essentially asked the same question multiple times. Question== "I want to automagically create an ERD".

Answer:
I do not know mysql (what you seem to use) from beans. But, I do know there are free tools to analyze table metadata out there. Start googling, some terms:
database, metadata, analysis, entity relationships.

Personally, I find most ERD's for commerically produced database application systems to be a digression. As well as requiring a huge wall to display the darned thing on paper. Whenever something trancends normal human perception limits, its usefulness is quite limited.

There is a reason for metadata tables other than to keep the db engine amused: ERD information is one select statement. How do you suppose, for an existing application, someone created an ERD to start with?
Sorry, I was thinking of MSSQL2014 . I just thought that since DDL statements go so far towards laying out the needed specs for an ERD, that it may be possible to go all the way and implement a design. But, yes, for reasonable ERDs with, say, less than 10 tables.
 
  • #8
Not quite sure what you are getting at: are you familiar with the concept of a CONSTRAINT? You can use a CONSTRAINT to link the foreign key column in the 'many' side of the relationship to the key column on the 'one' side. You can then use a tool to create an ERD from the schema (e.g. SqlServer's Diagrammer).
 

1. What is an ERD?

An ERD (Entity Relationship Diagram) is a visual representation of the relationships between data entities in a database. It is used to design and organize the data structure for a database.

2. What is DDL?

DDL (Data Definition Language) is a set of commands used to define and manipulate the structure of a database. This includes creating and modifying tables, views, and indexes.

3. How do I create a table in DDL?

To create a table in DDL, you use the CREATE TABLE statement. This statement specifies the table name, column names, data types, and any constraints on the data. For example, the syntax to create a table named "Students" with columns for first name, last name, and student ID would be: CREATE TABLE Students (first_name VARCHAR(50), last_name VARCHAR(50), student_id INT);

4. What are the advantages of using ERDs within DDL?

Using ERDs within DDL allows for a visual representation of the database structure, making it easier to design and understand the relationships between data entities. It also ensures consistency and accuracy in the database design, as any changes made to the ERD will automatically update the DDL statements.

5. Are there any best practices for designing ERDs within DDL?

Yes, there are some best practices to follow when designing ERDs within DDL. These include using clear and consistent naming conventions, properly defining data types and constraints, and documenting any assumptions or decisions made during the design process. It is also important to regularly review and update the ERD as the database evolves over time.

Similar threads

  • Programming and Computer Science
Replies
1
Views
1K
  • Programming and Computer Science
Replies
4
Views
336
  • Programming and Computer Science
Replies
2
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
3
Views
1K
  • Programming and Computer Science
Replies
1
Views
2K
  • Sci-Fi Writing and World Building
Replies
24
Views
643
  • Engineering and Comp Sci Homework Help
Replies
2
Views
3K
  • Programming and Computer Science
Replies
1
Views
2K
  • Programming and Computer Science
Replies
1
Views
1K
  • Programming and Computer Science
Replies
1
Views
3K
Back
Top