Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Which SQL Data Type can accommodate links

Tags:

sql

mysql

Which SQL data types can I use to accommodate links like www.google.com?

Which SQL data type can I use to store html codes?

<a href="www.google.com">Google</a>

I would like to store my links in the database, to use a for loop to automatically populate he links.

like image 348
Jervis Chionh Avatar asked Aug 07 '26 15:08

Jervis Chionh


1 Answers

Any of the string data types (e.g. varchar, nvarchar, etc) can accomodate the href attributes from links. And another string column can accommodate the inner text. So something like:

CREATE TABLE T (
    --Various columns
    LinkHref nvarchar(max) not null,
    LinkBody nvarchar(max) not null
)

Then, construct the surrounding anchor tag when you're extracting them for display. This also makes the links more searchable in the database in the future.

like image 165
Damien_The_Unbeliever Avatar answered Aug 10 '26 09:08

Damien_The_Unbeliever



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!