Solved

how to add a sqlite trigger?

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

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
AWS RDS Backups? 3 52
How to Implement Two Event Listeners in Android 2 46
Create a MySQL table as easily as possible 6 46
VMWare environment audit 8 68
A short article about problems I had with the new location API and permissions in Marshmallow
Read about achieving the basic levels of HRIS security in the workplace.
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…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

828 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