2014-08-28 54 views
1

如何從所有行中刪除某些值,例如我有一個表CustomerImage。我在下面的表格中有數據。如何從SQL中刪除一些值查詢

+---------+--------------------------------+ 
| 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 /。例如上面的表格,我有一個大型的數據庫。

+4

你到目前爲止嘗試了什麼? – 2014-08-28 14:36:35

+0

@MikeCheel你的意思是? – 2014-08-28 14:37:37

+0

我的意思是你希望幫助哪些sql? – 2014-08-28 14:38:05

回答

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 
+0

如何在開始行中添加一些值 – 2014-08-28 15:25:01

+0

@skgacharya - 我不明白你在問什麼。你需要將「鏈接」列更改爲其他內容嗎?更新另一個字段?你問兩個不同的問題嗎? – 2014-08-28 15:28:16

+0

是的,我在問第二個問題。我已經取代了所有行的值,現在我想在每一行的開頭添加..product /。 – 2014-08-28 15:31:53