Creating a table

Create the tables and set the data schema for them using the statement CREATE TABLE.

Note

Keywords are case-insensitive and written in capital letters for clarity only.

  1. CREATE TABLE series -- series is the table name.
  2. ( -- Must be unique within the folder.
  3. series_id Uint64,
  4. title Utf8,
  5. series_info Utf8,
  6. release_date Uint64,
  7. PRIMARY KEY (series_id) -- The primary key is a column or
  8. -- combination of columns that uniquely identifies
  9. -- each table row (contains only
  10. -- non-repeating values). A table can have
  11. -- only one primary key. For every table
  12. -- in YDB, the primary key is required.
  13. );
  14. CREATE TABLE seasons
  15. (
  16. series_id Uint64,
  17. season_id Uint64,
  18. title Utf8,
  19. first_aired Uint64,
  20. last_aired Uint64,
  21. PRIMARY KEY (series_id, season_id)
  22. );
  23. CREATE TABLE episodes
  24. (
  25. series_id Uint64,
  26. season_id Uint64,
  27. episode_id Uint64,
  28. title Utf8,
  29. air_date Uint64,
  30. PRIMARY KEY (series_id, season_id, episode_id)
  31. );
  32. COMMIT;

Creating a table - 图1