• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 119
  • Last Modified:

Where to store the queries for modification of table

Hi,
Where do i store the queries for modification of the table.
In my java project i have made a file called dump.sql which contains all the create table queries which were used to create tables.. what happens is sometimes say i need to add a new column or change the type of existing column i just store the new create table query and not the steps of queries i made to change the table.. I feel they should also be stored... What is the standard way or how you do it..
Do you store the in between queries that were used to made modification to the table or just the final queries ?

In case of storing them how do i store them... Should i just make a separate .sql file and put all these modification queries there ?

Thanks
0
Rohit Bajaj
Asked:
Rohit Bajaj
3 Solutions
 
dpearsonCommented:
Should i just make a separate .sql file and put all these modification queries there ?

That's exactly how we do it.  We maintain a list of patch files - each of which contains the "ALTER TABLE" and similar statements that modify the database table schema.

We then apply those patch files to the live database (the one which contains data) and can also run them all in sequence to create a new empty database when testing.

Once you have that series of files, you can always generate the "CREATE TABLE" statements if you need them for some reason by just dumping the database again.

Doug
0
 
gurpsbassiCommented:
Are you using any version management for the schema?

I've always used liquibase or flyway. It does the job nicely.
0
 
awking00Commented:
What database?
0
 
Chandramouli kArchitectCommented:
you can store these files under a DBScripts folder in Source control - ex SVN with name of the file as DDL_Tablename.sql

you can keep appending the sqls for all changes made in sequence.

for ex:
-- 1) Create table
-- 2) Add constraints
-- 3) Alter table to add columns
and so on.

if you dont want to maintain in same file, You can also create sqls and maintain with Sl No in the name that will help you to identify the order and history of what has happened over a period of time

Hope this helps
0

Featured Post

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now