如何使用一个查询删除多个表的列 [英] How to delete columns of multiple tables with one query

查看:78
本文介绍了如何使用一个查询删除多个表的列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

从empname = N'的员工中删除& TxtList.Item(Employee Name,TxtList.CurrentRow.Index).Value& '

这个我的删除查询我要删除多个表的列



我尝试了什么:



i已尝试使用begin但无法正常工作

"delete from employees where empname=N'" & TxtList.Item("Employee Name", TxtList.CurrentRow.Index).Value & "'"
this my delete query i want delete columns of multiple tables

What I have tried:

i have tried with begin but not working

推荐答案

这不会删除删除行的列。
That doesn't delete columns, that deletes rows.
Columns -->   ID    Name          Address
Rows v
                  1    Joe Smith     2 Bread Street
                  2    Mike Hunt     42, Ballard way
                 ...

删除一列,它删除该列中所有行的所有数据,你没有得到WHERE子句!



并且不要做你在查询中显示的任何事情!永远不要连接字符串来构建SQL命令。它让您对意外或故意的SQL注入攻击持开放态度,这可能会破坏您的整个数据库。总是使用参数化查询。



连接字符串时会导致问题,因为SQL会收到如下命令:

Delete a column, and it removes all the data in that column for all rows, you don't get a WHERE clause with that!

And don't do anything like you show in your query! Never concatenate strings to build a SQL command. It leaves you wide open to accidental or deliberate SQL Injection attack which can destroy your entire database. Always use Parameterized queries instead.

When you concatenate strings, you cause problems because SQL receives commands like:

SELECT * FROM MyTable WHERE StreetAddress = 'Baker's Wood'

就SQL而言,用户添加的引号会终止字符串,并且您会遇到问题。但情况可能更糟。如果我来并改为输入:x'; DROP TABLE MyTable; - 然后SQL收到一个非常不同的命令:

The quote the user added terminates the string as far as SQL is concerned and you get problems. But it could be worse. If I come along and type this instead: "x';DROP TABLE MyTable;--" Then SQL receives a very different command:

SELECT * FROM MyTable WHERE StreetAddress = 'x';DROP TABLE MyTable;--'

哪个SQL看作三个单独的命令:

Which SQL sees as three separate commands:

SELECT * FROM MyTable WHERE StreetAddress = 'x';

完全有效的SELECT

A perfectly valid SELECT

DROP TABLE MyTable;

完全有效的删除表格通讯和

A perfectly valid "delete the table" command

--'

其他一切都是评论。

所以它确实:选择任何匹配的行,从数据库中删除表,并忽略其他任何内容。



所以总是使用参数化查询!或者准备好经常从备份中恢复数据库。你经常定期备份,不是吗?



通过你的整个应用修复,然后考虑你要删除的表数据是如何组织和相关的:我们暂时无法帮助您,因为我们不知道您的数据库是如何布局的。

And everything else is a comment.
So it does: selects any matching rows, deletes the table from the DB, and ignores anything else.

So ALWAYS use parameterized queries! Or be prepared to restore your DB from backup frequently. You do take backups regularly, don't you?

Fix that through your whole app, and then think about how the table data you want to delete is organised and related: we can't help you at the moment because we have no idea how your DB is laid out.


这篇关于如何使用一个查询删除多个表的列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆