0

I have a database table that contains a column named: "shortLink". This column contains a short link of an address of each row in the table. I use the tinyurl.com services for the short links. The short link looks like this: https://tinyurl .com/randomletters.

Recently I figured out that I need to change the shortlinks to their preview short link version: https://preview.tinyurl .com/randomletters.

The only difference between the two link formats is that there is a prefix preview. between https:// and tinyurl.

Since I have hundreds of rows in the sql table I cannot fix this manually. Is there any way to convert each shortlink (by adding the prefix preview. in the address) to its preview format with code in sql?

Thanks.

PS - Notice that there is a gap between tinyurl and .com in the link formats above. This gap is added intentionally because the forum would not let me publish the question otherwise.

1

3 Answers 3

1

-- this will update the field for you where it does not already have the preview. in it.

UPDATE YourTable
SET  shortlinks= REPLACE( shortlinks, 'https://tinyurl .com', 'https://preview.tinyurl .com')
WHERE  shortlinks NOT LIKE 'https://preview.tinyurl%'
Sign up to request clarification or add additional context in comments.

Comments

0

You can just use an update:

update t
    set shortlink = concat('http://preview.', substring(shortlink, 8))
    where shorlink like 'http://tinyurl%';

Comments

0

Bro try this. first, remove all spaces in URL on anywhere then replace 'tinyurl' to 'preview'

UPDATE [Table_Name]
SET  shortLink=  REPLACE(REPLACE( shortLink, ' ', ''),'tinyurl', 'preview')

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.