Here is the correction/update of my first post :)
I have a website where i can add news. If i add a news-entry, it will create a database entry on table "news" with a unique id for each news-entry.
In every news-entry, i can add multiple pictures and multiple text-sections. For each picture which i add, it will create a database entry on table "news_images" with a unique image_id (autoincrement) and with the id from the table "news" (so i know which image belongs to which news-entry) . Same procedure if i add a text-section.
The problem that i have: The pictures and the text-sections in each news-entry are draggable, so i can change their position (up and down). I must save each position for every object in the database. For this i added now a new Table "news_imgid_txtid". But i still don't know how to add a continuous id..
Example:
Thanks for your help, Misch
IMO for your case you should change tables' structure. First create a header table media_header
for instance. The media_header
table should contain an id
column. Than every table news_image
, news_text
should have an foreign key from news_text.text_id
and news_image.image_id
columns to media_header.id
column. Than the DB will preserve this id as continuous.
If you are trying to have an id column that is unique across tables, you want to use a GUID . The details on how to do that will depend on your sql engine.
However, it is not clear whether this is actually the best design for you. If you will give us more information on why you want to do this, we could probably point you in a better direction.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.