?
Solved

how to add a sqlite trigger?

Posted on 2010-11-16
2
Medium Priority
?
888 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 62

Accepted Solution

by:
gheist earned 2000 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

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

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

These days software publishers make it possible to move all the possible applications on smartphones, tablets, smartwatches, and more. Although behind every logic and decision is a gross doubt: how do they make it possible? In this blog post, we sha…
In this article, I’ll look at how you can use a backup to start a secondary instance for MongoDB.
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…
Suggested Courses

752 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