开发者

Deleting rows in database

开发者 https://www.devze.com 2023-02-02 05:37 出处:网络
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

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.

  1. MessageID(pk)
  2. RoomID
  3. UserID
  4. ToUserID
  5. 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
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号