Solved

Trigger in SqlLite

Posted on 2011-03-07
6
414 Views
Last Modified: 2012-05-11
I try to update the DateModified field of the updated record in sql lite but I can't find the syntex to do so.
I tried this one that works for MSSql:
CREATE TRIGGER [TableName]LastModifiedDate ON [TableName] FOR UPDATE AS UPDATE [TableName] SET [TableName].LastModified=getdate() FROM [TableName] INNER JOIN Inserted ON [TableName].[UniqueID]= Inserted.[UniqueID]

the problem is that in sqllite is says theres no table Inserted...
Currantly when I update one row all the rows datemodified are updated.. that's no good. I want just the one updated now should be changed.

Is there any other way to do it?

Thanks
0
Comment
Question by:Mr_Ezi
[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
  • 3
  • 2
6 Comments
 
LVL 75

Expert Comment

by:Anthony Perkins
ID: 35065594
>>Zones: Databases Miscellaneous, MS SQL Server, SQL Query Syntax<<
This question has nothing to do with MS SQL Server, please request that zone be removed.
0
 
LVL 29

Expert Comment

by:Olaf Doschke
ID: 35066939
See the SQLite language refernce:
http://www.sqlite.org/lang_createtrigger.html

SQLite has no table inserted, it has "new" and "old"

Also getdate() is not a function available in SQLite, you have date('now') there.

T-SQL is T-SQL SQLite is SQLite. Learn SQLite, don't just copy and paste, this won't work of course.

Bye, Olaf.
0
 

Author Comment

by:Mr_Ezi
ID: 35068868
Thanks for the link I have a SqlLite book and I know the getdate function, but I can't find a solution for my problem.
I tried 'where new.oid = old.oid' but still all rows get affected!
Please help...
0
Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

 
LVL 29

Expert Comment

by:Olaf Doschke
ID: 35129034
INNER JOIN Inserted ON [TableName].[UniqueID]= Inserted.[UniqueID] need to be replaced by
WHERE [TableName].[UniqueID]= new.[UniqueID] to limit the update on the single new record.

Bye, Olaf.
0
 
LVL 29

Accepted Solution

by:
Olaf Doschke earned 500 total points
ID: 35129067
Also see: http://linuxgazette.net/109/chirico1.html

Sample code
     -- ********************************************************************
     --   Creating a trigger for timeEnter
     --     Run as follows:
     --            $ sqlite3 test.db < trigger1
     -- ********************************************************************
     CREATE TRIGGER insert_t1_timeEnter AFTER  INSERT ON t1
     BEGIN
      UPDATE t1 SET timeEnter = DATETIME('NOW')  WHERE rowid = new.rowid;
     END;
     -- ********************************************************************

Open in new window


Should be easy enough to adapt to your situation.

Bye, Olaf.
0
 

Author Closing Comment

by:Mr_Ezi
ID: 35129277
Thnaks your the best.
0

Featured Post

How To Install Bash on Windows 10

Windows’ budding partnership with Canonical has certainly led to some great improvements. One of them being the ability to use Bash on your Windows machine without third party applications! This might be one of the greatest things a cloud engineer in a Windows environment can do!

Question has a verified solution.

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

Recently we ran in to an issue while running some SQL jobs where we were trying to process the cubes.  We got an error saying failure stating 'NT SERVICE\SQLSERVERAGENT does not have access to Analysis Services. So this is a way to automate that wit…
This post contains step-by-step instructions for setting up alerting in Percona Monitoring and Management (PMM) using Grafana.
Via a live example, show how to extract information from SQL Server on Database, Connection and Server properties
Via a live example, show how to shrink a transaction log file down to a reasonable size.

617 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