Search notes:

Power Query M formula language standard library: Table.AddKey

Table.AddKey(TABLE as table, COLUMNS as list, ISPRIMARY as logical) as table

Primary keys

The following Power Query program creates a table with a primary key:
let
   tab = #table(
     {"id", "val 1", "val 2"}, {
     {  1 , "one"  , "foo"  },
     {  2 , "two"  , "bar"  },
     {  3 , "three", "baz"  }
   }),
   tab_pk = Table.AddKey(
     tab,
     {"id"},
     true
   )
in
   tab_pk

PKs are not enforced

Unfortunately, Power Query does not enforce (or check) primary keys. The last record should be rejected, imho, because the id 2 is already used. However, the program just runs fine:
let
   tab = #table(
     {"id", "val 1", "val 2"}, {
     {  1 , "one"  , "foo"  },
     {  2 , "two"  , "bar"  },
     {  3 , "three", "baz"  },
     {  2 , "uh oh", "!"    }
   }),
   tab_pk = Table.AddKey(
     tab,
     {"id"},
     true
   )
in
   tab_pk

See also

The Power Query standard library, especially the function Table.Keys

Index

Fatal error: Uncaught PDOException: SQLSTATE[HY000]: General error: 8 attempt to write a readonly database in /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php:78 Stack trace: #0 /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php(78): PDOStatement->execute(Array) #1 /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php(30): insert_webrequest_('/notes/Microsof...', 1758209677, '216.73.216.150', 'Mozilla/5.0 App...', NULL) #2 /home/httpd/vhosts/renenyffenegger.ch/httpsdocs/notes/Microsoft/Power-Query/M-formula/standard-library/Table/AddKey(74): insert_webrequest() #3 {main} thrown in /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php on line 78