Solved

how to add a sqlite trigger?

Posted on 2010-11-16
2
855 Views
Last Modified: 2012-05-10
I'm trying to add a sqlite trigger to my android database.  I have 2 tables:
Courses(courseId, courseName,courseSection,courseLocation)
CourseGrade(courseId, courseName, courseGrade)

What I would like is when an insert is done on Courses, I would like to setup a trigger to insert courseId, and courseName into CourseGrade table.  Also when I delete a course from Courses table I would like to delete it from the courseGrade table.  Is this possible?
0
Comment
Question by:dmalovich
2 Comments
 
LVL 62

Accepted Solution

by:
gheist earned 500 total points
ID: 34154174
Almost the same as on other databases: http://www.sqlite.org/lang_createtrigger.html
If you try to establish 1:1 relation it might be better to alter first table instead (course grade is a very small field)
0
 

Author Comment

by:dmalovich
ID: 34154330
In have a database package with a createTables method.  How can I add the trigger to this code?
The page you gave is helpful but i'm looking for the syntax to add the trigger to this method.

private void createAllTables(SQLiteDatabase db) {

db.execSQL("CREATE TABLE Courses (CourseId varchar(10) NOT NULL PRIMARY KEY, CourseName varchar(25) NOT NULL, Section varchar(4), Location varchar(25))");

db.execSQL("CREATE TABLE CourseGrade(CourseId varchar(10),CourseName varchar(25),CourseGrade varchar(3),PRIMARY KEY(CourseId),FOREIGN KEY (CourseId) REFERENCES Courses(CourseId),FOREIGN KEY (CourseName) REFERENCES Courses(CourseName))");
0

Featured Post

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
Shadow IT is coming out of the shadows as more businesses are choosing cloud-based applications. It is now a multi-cloud world for most organizations. Simultaneously, most businesses have yet to consolidate with one cloud provider or define an offic…
Video by: Steve
Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

776 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question