Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's the recommended location for SQL (DDL) scripts?

Tags:

sql

maven

What's the recommended location for SQL, DDL, ... scripts in the Maven standard directory structure?

I bet almost every web project uses a DB and some kind of SQL scripts that need to be stored somewhere, so what would probably be the "best" place where to keep these files?

Please advise.

like image 659
Kawu Avatar asked Oct 07 '11 11:10

Kawu


People also ask

Where are SQL scripts stored?

By default all of the scripts are saved to a "Scripts" folder located in your project inside the workspace directory. This can be changed by clicking the Configure button in Project Explorer view. There you can click on a folder's name an pick any other folder inside the Project.

What is a SQL DDL script?

Data Definition Language (DDL) is a subset of SQL. It is a language for describing data and its relationships in a database. You can generate DDL in a script for database objects to: Keep a snapshot of the database structure. Set up a test system where the database acts like the production system but contains no data.

How do I create a DDL script in SQL Server?

The DDL stands for Data Definition Language. To generate the table DDL via query, you can use show create command. SHOW CREATE TABLE yourTableName; The above syntax is MySQL specific.


1 Answers

I think there is no best practice for this. In my past project, I created a separate directory for storing such SQL script.

For example src/main/db.

It won't be packaged to final JAR by default (which are the preferred way in most case), yet it is convenient enough to let it packaged in assembly. You can even package them in the main artifact JAR, by adding corresponding resource declaration or using maven build-helper plugin.

However, all depends on your usage on this script. My simple "rule of thumb" is that, I would consider putting them in resources/ only when they are really resources to be loaded by the application.

like image 85
Adrian Shum Avatar answered Sep 28 '22 15:09

Adrian Shum