-1

I’m designing a database with ERD for a Telegram Bot and I want to store the Users. Every user gets an id (primary key, int) and the chat id form Telegram (int).

The Telegram Bot API says this about the chat id: "Unique identifier for the target chat or username of the target channel" https://core.telegram.org/bots/api

Now is my question: is the chat id a second primary key or a foreign key or just NOT NULL and UNIQUE? (Or something I never heard before)

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Steffen Bauer
  • 145
  • 1
  • 10
  • 2
    You don't seem to know what a PK is since there can only be one. You don't seem to know what a FK is since whether something is a FK has nothing to do with whether it is a PK or UNIQUE. How is this question not just asking what all those terms mean? Explain where you are stuck applying definitions. See [ask] & the voting arrow mouseover texts. PS If your question requires anything at that link, put it in your question. Paraphrase or quote from other text. Make your post self-contained. PS These terms mean different things in the relational model & SQL. Which do you mean? – philipxy Jun 08 '19 at 21:43
  • i know that PK is for the id of a table and FK is there refer to a PK from another table. I didn´t know that the can only be one. But the question still stands: what is it if its not a PK? I qouted the important part from the URL just in front of the URL to explane what the characteristics of the chat id is. – Steffen Bauer Jun 08 '19 at 21:53
  • 2
    A PK is not "the id of a table"--& that doesn't even mean anything. Also I just said is it relational or SQL yet you don't say. You don't understand basic terms, you need to learn them. Please quote textbook or manual definitions. What is your textbook? When this is clear it will also be an SO faq. Before considering posting please always google any error message & many clear, concise & precise phrasings of your question/problem/goal, with & without your particular strings/names; read many answers.Beware basic DB notions are poorly explained in SO posts. PS Clarify via edits, not comments. – philipxy Jun 08 '19 at 22:05
  • Possible duplicate of [difference between primary key and unique key](https://stackoverflow.com/questions/9565996/difference-between-primary-key-and-unique-key) – philipxy Jun 08 '19 at 22:07
  • When we say that a value is a "unique identifier" for an entity in an application/interface we mean that that value identifies an entity & no other value identifies that entity. PS You don't say what "int" means but read the api re what a Chat id can be. Unfortunately the documentation is sloppy re what "Type" & "Integer" & its notion of "type" are. – philipxy Jun 09 '19 at 08:24

1 Answers1

1

This is a pretty straightforward spec.

My cursory reading of the link is that there are multiple different entities being returned, depending on the call. Each of them has an integer primary key which they refer to as the ID.

Its not clear from the spec how it returns references to other objects - for example the Chat definition refers to a UserName, while the Message object has a field called from which is of type user. This could be a name, the ID of the user, or the embedded object. If you are creating a database to support this then any embedded objects should be stored as foreign keys to the embedded object's ID, and you might have to do a lookup from whatever is returned in the call to find the correct ID.

I think some experimentation or sample calls would help - you might find it useful to experiment with Postman that will allow you to run the calls manually and inspect the results.

TomC
  • 2,759
  • 1
  • 7
  • 16