Skip to content

Include "if not exists" in table creation scripts [BATCH-1729] #1855

@spring-projects-issues

Description

@spring-projects-issues
Collaborator

Matthew T. Adams opened BATCH-1729 and commented

Adding conditional table creation to the creation scripts would be nice: CREATE TABLE IF NOT EXISTS ...

That way, the scripts could be run without having to have them bomb out because a table already exists. Using <jdbc:initialize-database ignore-failures="ALL" ... /> doesn't really help when you want to ensure that the schema either already exists or needs to be created.


No further details from BATCH-1729

Activity

spring-projects-issues

spring-projects-issues commented on Apr 20, 2011

@spring-projects-issues
CollaboratorAuthor

Dave Syer commented

"IF NOT EXISTS" is not supported by many (most?) of the platforms that people use. Which databases do you use? If you know it works for a particular platform or platforms we can maybe change it there.

spring-projects-issues

spring-projects-issues commented on Apr 21, 2011

@spring-projects-issues
CollaboratorAuthor

Matthew T. Adams commented

MySQL:
http://dev.mysql.com/doc/refman/5.1/en/create-table.html

MS SQL Server: (there may also be a system stored procedure that'll do this -- seems smarter to me to do it that way)
IF NOT EXISTS (SELECT * FROM sysobjects WHERE id = object_id(N'[dbo].[tablename]')
AND OBJECTPROPERTY(id, N'IsUserTable') = 1)
CREATE TABLE [dbo].[tablename] ( columns specification );

I'm sure there are ways to do this in all of the other major databases.

spring-projects-issues

spring-projects-issues commented on Apr 26, 2011

@spring-projects-issues
CollaboratorAuthor

Dave Syer commented

OK, that's a start. I don't understand the syntax for MS SQL, so someone is going to have to submit a patch or pull request and verify that it works. If we get a few more contributions we can start to apply them. All contributions gratefully accepted. I'll post on the forum and see if anyone responds.

added this to the 5.0.0 milestone on Jan 26, 2021
removed this from the 5.0.0 milestone on Nov 24, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @fmbenhassine@spring-projects-issues

        Issue actions

          Include "if not exists" in table creation scripts [BATCH-1729] · Issue #1855 · spring-projects/spring-batch