Solved

how to add a sqlite trigger?

Posted on 2010-11-16
2
830 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 61

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

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

I annotated my article on ransomware somewhat extensively, but I keep adding new references and wanted to put a link to the reference library.  Despite all the reference tools I have on hand, it was not easy to find a way to do this easily. I finall…
The case of the missing phone talks about the way a small electronic gadget (the mobile phone) has penetrated into our lives and has made us addicted to it.
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…
This video is in connection to the article "The case of a missing mobile phone (https://www.experts-exchange.com/articles/28474/The-Case-of-a-Missing-Mobile-Phone.html)". It will help one to understand clearly the steps to track a lost android phone.

743 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now