如何通过查询从SQL表中删除一些值

时间:2014-08-28 14:34:25

标签: sql sql-server sql-server-2008 tsql

如何从所有行中删除一些值,例如我有一个表CustomerImage。我在该表中有以下数据。

+---------+--------------------------------+
| Serial  | Link                           |
+---------+--------------------------------+
| 001     | pages/small/image001.jpg       |
| 002     | pages/small/image002.jpg       |
| 003     | pages/small/image003.jpg       |
| 004     | pages/small/image004.jpg       |
| 005     | pages/small/image005.jpg       |
| 006     | pages/small/image006.jpg       |
| 007     | pages/small/image007.jpg       |
| 008     | pages/small/image008.jpg       |
| 009     | pages/small/image009.jpg       |
| 010     | pages/small/image010.jpg       |
+---------+--------------------------------+

在上表中,我想从所有行中删除pages / small /。上面的例子我只有一个大型数据库。

1 个答案:

答案 0 :(得分:6)

你可能想要在事务中包装这一切并选择结果以确保你做对了。

BEGIN TRAN
UPDATE CustomerImage SET Link = REPLACE(Link, 'pages/small/', '')
SELECT * FROM CustomerImage
ROLLBACK  --change this to a commit after you're sure it's working the way you want
相关问题