I am using visual studio 2008 with my database in sql server 2005. I have created a chat online app. Once the user is online he/she can chat and his/her chat data will go in my message database which has this schema.
- MessageID(pk)
- RoomID
- UserID
- ToUserID
- Text
After the chatter finishes chat he log's开发者_如何学Python out and the messages sent by the "UserID" or say chat data in message table of that USerID must be deleted.
So I want to delete multiple rows from the database at once.
Well, this is my first response in SO, so I hope I get it right.
The usual way to delete more rows in SQL languages is:
delete from (table_name) where userID = (ID_of_the_user_that_signed_off)
Something like the following should help:
DELETE FROM [YOUR TABLENAME] WHERE UserId = [UserID]
Note: You can have a where clause in your delete statement using which you can specify the delete criteria.
If you want to delete the entire chat sessions in all rooms and with all users. Use the following query.
DELETE FROM [TABLENAME] WHERE UserId = @UserID
If you want to delete the chat with specific room then you have to specify room id also
Use the following query.
DELETE FROM [TABLENAME] WHERE UserId = @UserID AND RoomID = @RoomID
If you want to delete the chat with specific user session then you have to specify chat person user id also
Use the following query.
DELETE FROM [TABLENAME] WHERE UserId = @UserID AND ToUserID = @ToUserID
精彩评论