# How to run the exported DDL SQL file in Ignition

**URL:** <https://forum.inductiveautomation.com/t/how-to-run-the-exported-ddl-sql-file-in-ignition/86733>\
**Category:** Ignition Early Access\
**Created:** [March 3, 2024, 7:11pm UTC](https://forum.inductiveautomation.com/t/how-to-run-the-exported-ddl-sql-file-in-ignition/86733 "2024-03-03T19:11:47Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![nader.chinichian](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/nader.chinichian/32/9261_2.png) [@nader.chinichian](https://forum.inductiveautomation.com/u/nader.chinichian)\
**Post date:** [March 3, 2024, 7:11pm UTC](https://forum.inductiveautomation.com/t/how-to-run-the-exported-ddl-sql-file-in-ignition/86733/1 "2024-03-03T19:11:47Z")

</div>

Hi,  
I want to create my whole DB schema in the Ignition. To do that I simply export my created schema from SQL IDE (Export To DDL) and it generates multiple SQL queries.  
As system.db.runPrepUpdate() doesn't allow to have multiple queries I split(";") and looped through all.

```auto
	db = "CMMS"
	queries = self.view.custom.queries.strip().split(";")

	for query in queries:
		system.db.runPrepUpdate(query, [], db)

```

This method works if I don't have any stored procedures or trigger code blocks in my exported DDL file. ( As the system.db.runPrepUpdate() doesn't execute stored procedures statement)  
So I want to know how can I run the whole SQL statements in Ignition.  
@pturmel Is it possible to do this by importing some JAVA classes?

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [March 3, 2024, 8:55pm UTC](https://forum.inductiveautomation.com/t/how-to-run-the-exported-ddl-sql-file-in-ignition/86733/2 "2024-03-03T20:55:21Z")

</div>

No, vanilla JDBC just does single statements.

However, system.db.runPrepUpdate should be able to run complete `CREATE TRIGGER` or `CREATE PROCEDURE` statement, even though they are composed of multiple statements, because the multiple statements are **not** executed at that point in time.

---

<div class="post-metadata">

**Author:** ![nader.chinichian](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/nader.chinichian/32/9261_2.png) [@nader.chinichian](https://forum.inductiveautomation.com/u/nader.chinichian)\
**Post date:** [March 3, 2024, 9:36pm UTC](https://forum.inductiveautomation.com/t/how-to-run-the-exported-ddl-sql-file-in-ignition/86733/3 "2024-03-03T21:36:48Z")

</div>

How does a company like Sepasoft do this then? They generate the whole schema with their module in Ignition.

This is a simple trigger example and as it uses IF we need to close it with END IF;  
and that ";" makes a problem with system.db.runPrepUpdate().

```auto
  CREATE OR REPLACE TRIGGER "IGNITION"."ASSETS_TRG1" 
BEFORE INSERT ON IGNITION.ASSETS 
FOR EACH ROW 
BEGIN
  <<COLUMN_SEQUENCES>>
  BEGIN
    IF INSERTING AND :NEW.ID IS NULL THEN
      SELECT ASSETS_SEQ2.NEXTVAL INTO :NEW.ID FROM SYS.DUAL;
    END IF;
  END COLUMN_SEQUENCES;
END;
/
ALTER TRIGGER "IGNITION"."ASSETS_TRG1" ENABLE;

```

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [March 3, 2024, 9:55pm UTC](https://forum.inductiveautomation.com/t/how-to-run-the-exported-ddl-sql-file-in-ignition/86733/4 "2024-03-03T21:55:28Z")

</div>

I don't see any `AS` clause the delimits the `CREATE` from the body. That usually includes unambiguous delimiters. What I mean is that your `CREATE` doesn't look complete.

---

<div class="post-metadata">

**Author:** ![nader.chinichian](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/nader.chinichian/32/9261_2.png) [@nader.chinichian](https://forum.inductiveautomation.com/u/nader.chinichian)\
**Post date:** [March 4, 2024, 4:27am UTC](https://forum.inductiveautomation.com/t/how-to-run-the-exported-ddl-sql-file-in-ignition/86733/5 "2024-03-04T04:27:38Z")

</div>

This is generated by Oracle SQL developer IDE. The AS clause is for MSSQL.

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [March 4, 2024, 12:57pm UTC](https://forum.inductiveautomation.com/t/how-to-run-the-exported-ddl-sql-file-in-ignition/86733/6 "2024-03-04T12:57:34Z")

</div>

Ok. I haven't played with Oracle in many years. I'm not sure what you should try next.

---

<div class="post-metadata">

**Author:** ![MMaynard](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/mmaynard/32/3366_2.png) [@MMaynard](https://forum.inductiveautomation.com/u/MMaynard)\
**Post date:** [March 4, 2024, 1:04pm UTC](https://forum.inductiveautomation.com/t/how-to-run-the-exported-ddl-sql-file-in-ignition/86733/7 "2024-03-04T13:04:56Z")

</div>

The AdHoc Trending Template has code in there for Oracle tables and does create triggers.

Have you tried wrapping it in triple quotes?

```auto

		elif event.source.parent.databaseType == "ORACLE":	
			system.db.runPrepUpdate("""CREATE TABLE chart_annotations (
			  id number(10) NOT NULL,
			  penname varchar2(45) NOT NULL,
			  xvalue date NOT NULL,
			  yvalue number NOT NULL,
			  note clob NOT NULL,
			  enteredby varchar2(45) NOT NULL,
			  lastupdated date NOT NULL,
			  PRIMARY KEY (id))""", [])
			system.db.runPrepUpdate("""CREATE SEQUENCE chart_annotations_seq START WITH 1 INCREMENT BY 1""", [])
			system.db.runUpdateQuery("""CREATE OR REPLACE TRIGGER chart_annotations_seq_tr
				 BEFORE INSERT ON chart_annotations FOR EACH ROW
				 WHEN (NEW.id IS NULL)
				BEGIN
				 SELECT chart_annotations_seq.NEXTVAL INTO :NEW.id FROM DUAL;
				END;""")
			system.db.runPrepUpdate("""CREATE INDEX idx_tstamp ON chart_annotations (xvalue)""", [])

```
