Linked List in SQL

Question :

Linked List in SQL,

Answer :

What’s the best way to store a linked list in a MySQL database so that inserts are simple (i.e. you don’t have to re-index a bunch of stuff every time) and such that the list can easily be pulled out in order?

,

create a table with two self referencing columns PreviousID and NextID. If the item is the first thing in the list PreviousID will be null, if it is the last, NextID will be null. The SQL will look something like this:

create table tblDummy  {       PKColumn     int     not null,        PreviousID     int     null,        DataColumn1     varchar(50)     not null,        DataColumn2     varchar(50)     not null,         DataColumn3     varchar(50)     not null,        DataColumn4     varchar(50)     not null,        DataColumn5     varchar(50)     not null,        DataColumn6     varchar(50)     not null,        DataColumn7     varchar(50)     not null,        NextID     int     null  }  

That’s the answer Linked List in SQL, Hope this helps those looking for an answer. Then we suggest to do a search for the next question and find the answer only on our site.

Read More  Algorithm to generate anagrams

Disclaimer :

The answers provided above are only to be used to guide the learning process. The questions above are open-ended questions, meaning that many answers are not fixed as above. I hope this article can be useful, Thank you