[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

how to add a sqlite trigger?

Posted on 2010-11-16
2
Medium Priority
?
898 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

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

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

In this blog post, we’ll look at how using thread_statistics can cause high memory usage.
One of the most important things in an application is the query performance. This article intends to give you good tips to improve the performance of your queries.
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…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…

656 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