views:

122

answers:

2

What is the need for a database schema (embedded in the DB) if I can configure my MySQL DB structure and write CRUD statements to work with it directly? I've never worked with these, but I'm assuming they're only for performance optimization?

I know of schema diagrams that can be exported as .sql commands which generate the DB structure, for example with MySQL Workbench.

A: 

Well, you could create every column in your database as VARCHAR(255), but the result will be incredibly slow.

Think about the way the database does the querying: it has an index (think of an index in a dictionary). It looks through the index and finds the right record (the right page in the dictionary). Then, it returns the record.

If the index is small, the lookup is fast - because more "pages" of the index can fit into memory at once (just think about it - isn't it easier to look through the dictionary index if it's 2 pages instead of 500?). So using an integer index for querying is dramatically faster than using a string index.

Alex
+1  A: 

Your question is not totally clear to me. If you are asking about why have an editable graphical representation of the schema, then there is no need for a graphical representation of the structure of a database.

It certainly comes in handy when you have to learn at a glance how a database is laid out or communicate to other people your DB design. And it's sometimes easier to edit the graphical representation instead of using DDL sentences.

If you want to know where in the DB is the schema stored, it is exposed through the standard INFORMATION_SCHEMA tables. Of course the DDL is in the database (else how would the db know how to store the data)

Vinko Vrsalovic
Q: Is there a way to store the schema inside the DB for performance? Is there any need for this?
Jenko
The schema *is* in the database. You can query the INFORMATION_SCHEMA to find out everything there is to know about the DB schema
Vinko Vrsalovic