|
-
May 15th, 2010, 08:59 AM
#1
Thread Starter
Hyperactive Member
-
May 15th, 2010, 09:12 AM
#2
Re: SQL Server - Notified when a new entry is added?
Did you look at Insert triggers on the tables?
Sometimes the Programmer
Sometimes the DBA
Mazz1
-
May 15th, 2010, 09:19 AM
#3
Re: SQL Server - Notified when a new entry is added?
You should look at WCF to fix that problem.
it's possible to push to clients with this technology.
 why can't programmers keep and 31 Oct and 25 dec apart. Why Rating is Useful
for every question you ask provide an answer on another thread.
-
May 15th, 2010, 09:26 AM
#4
Thread Starter
Hyperactive Member
-
May 15th, 2010, 10:01 AM
#5
Re: SQL Server - Notified when a new entry is added?
I don't think a DB is a proper place for what you are looking for - a DB is more of a repository for data. A place to store the chat log from a chat session. There are other "pc-to-pc" communication methods that more closely match what you are looking for here.
With that said - if you really want to do it in a table in SQL - it's all as simple as having your "chat" table have a simple integer type primary key that is an identity value.
And then having your client program call a query that asks for all rows with a PK value greater then the last "max" PK value that was SELECTED.
And you can also protect your "INSERT's" of new rows into this table so that they do not INSERT if a "newer" row is already in place - that way you would "know" to hold that INSERT until you did your SELECT (as noted above) and shown that "new post" to your client.
There is no need for triggers or notification events (I've read that notification is not the "great" feature that you would think it to be).
-
May 15th, 2010, 11:31 AM
#6
Thread Starter
Hyperactive Member
-
May 15th, 2010, 11:52 AM
#7
Re: SQL Server - Notified when a new entry is added?
btw - to do an INSERT that will fail if someone else has "since added a new row" do the following.
Assume a table with two columns - ChatId as int and ChatText as varchar(100)
And assume that you "know" the last "max" ChatId is 15.
You are expecting to insert 16.
This query will NOT INSERT if the "current max" ChatId is greater then 15.
Note that with IDENTITY columns they auto-number - so you don't specify them in the INSERT statement - just the text.
Code:
Insert into ChatTable
Select 'New Chat Text'
Where (Select Max(ChatId) From ChatTable)=15
This INSERT-from-a-SELECT trick allows you to put a WHERE clause. The WHERE clause only passes a new row if the current max chatid is still 15.
You check the RowCount after the INSERT and now your client program knows if the ChatTable changed since you last "read" from it.
Last edited by szlamany; May 15th, 2010 at 12:22 PM.
-
May 15th, 2010, 11:59 AM
#8
Thread Starter
Hyperactive Member
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|