删除数据库中的行

发布于 2024-10-10 04:02:19 字数 309 浏览 2 评论 0原文

我正在使用 Visual Studio 2008 和 SQL Server 2005 中的数据库。 我创建了一个在线聊天应用程序。一旦用户在线,他/她就可以聊天,他/她的聊天数据将进入我的具有此模式的消息数据库。

  1. MessageID(pk)
  2. RoomID
  3. UserID
  4. ToUserID
  5. Text

聊天者结束聊天后,他会退出并 由“UserID”发送的消息或者该UserID的消息表中的聊天数据必须被删除。

所以 我想一次从数据库中删除多行。

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 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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

ι不睡觉的鱼゛ 2024-10-17 04:02:19

嗯,这是我在《SO》中的第一次回应,所以我希望我能答对。

SQL语言中删除更多行的常用方法是:

delete from (table_name) where userID = (ID_of_the_user_that_signed_off)

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)
巷雨优美回忆 2024-10-17 04:02:19

类似以下内容应该有所帮助:

DELETE FROM [YOUR TABLENAME] WHERE UserId = [UserID]

注意:您可以在删除语句中使用 where 子句,使用它可以指定删除条件。

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.

深白境迁sunset 2024-10-17 04:02:19

如果您想删除所有房间和所有用户的整个聊天会话。
使用以下查询。

DELETE FROM [TABLENAME] WHERE UserId = @UserID

如果您想删除与特定房间的聊天,则必须指定房间 ID 并

使用以下查询。

DELETE FROM [TABLENAME] WHERE UserId = @UserID AND RoomID = @RoomID

如果要删除与特定用户会话的聊天,则必须指定聊天人用户 ID,还

可以使用以下查询。

DELETE FROM [TABLENAME] WHERE UserId = @UserID AND ToUserID = @ToUserID

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
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文