TheKeySetclass is a regular type that represents a collection ofKeys.
Users can construct aKeySetinstance, then addKeys and ranges ofKeys to the set. The caller is responsible for ensuring that all keys in a givenKeySetinstance contain the same number and types of values.
Users may also optionally construct an instance that represents all keys withKeySet::All().
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Hard to understand","hardToUnderstand","thumb-down"],["Incorrect information or sample code","incorrectInformationOrSampleCode","thumb-down"],["Missing the information/samples I need","missingTheInformationSamplesINeed","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-09-04 UTC."],[[["\u003cp\u003eThis webpage details the \u003ccode\u003eKeySet\u003c/code\u003e class within the Google Cloud Spanner C++ library, focusing on its role in managing collections of \u003ccode\u003eKey\u003c/code\u003es for database operations.\u003c/p\u003e\n"],["\u003cp\u003eThe \u003ccode\u003eKeySet\u003c/code\u003e class allows users to construct an instance and add individual \u003ccode\u003eKey\u003c/code\u003es or ranges of \u003ccode\u003eKey\u003c/code\u003es, ensuring that all \u003ccode\u003eKey\u003c/code\u003es within a \u003ccode\u003eKeySet\u003c/code\u003e share the same number and types of values.\u003c/p\u003e\n"],["\u003cp\u003eA \u003ccode\u003eKeySet\u003c/code\u003e can be created to represent all keys by using the \u003ccode\u003eKeySet::All()\u003c/code\u003e method, offering a convenient way to target all data in a table, such as in deletion operations.\u003c/p\u003e\n"],["\u003cp\u003eThe page provides a list of versioned links to the \u003ccode\u003eKeySet\u003c/code\u003e class documentation, from version 2.16.0 all the way to the most recent version of 2.37.0-rc, to accommodate different project dependencies.\u003c/p\u003e\n"],["\u003cp\u003eThe documentation also details its constructors, the assignment operators, and functions like \u003ccode\u003eAddKey\u003c/code\u003e and \u003ccode\u003eAddRange\u003c/code\u003e, providing methods to manipulate instances of the \u003ccode\u003eKeySet\u003c/code\u003e class.\u003c/p\u003e\n"]]],[],null,["# Class KeySet (2.16.0)\n\nVersion 2.16.0keyboard_arrow_down\n\n- [2.42.0-rc (latest)](/cpp/docs/reference/spanner/latest/classgoogle_1_1cloud_1_1spanner_1_1KeySet)\n- [2.41.0](/cpp/docs/reference/spanner/2.41.0/classgoogle_1_1cloud_1_1spanner_1_1KeySet)\n- [2.40.0](/cpp/docs/reference/spanner/2.40.0/classgoogle_1_1cloud_1_1spanner_1_1KeySet)\n- [2.39.0](/cpp/docs/reference/spanner/2.39.0/classgoogle_1_1cloud_1_1spanner_1_1KeySet)\n- [2.38.0](/cpp/docs/reference/spanner/2.38.0/classgoogle_1_1cloud_1_1spanner_1_1KeySet)\n- [2.37.0](/cpp/docs/reference/spanner/2.37.0/classgoogle_1_1cloud_1_1spanner_1_1KeySet)\n- [2.36.0](/cpp/docs/reference/spanner/2.36.0/classgoogle_1_1cloud_1_1spanner_1_1KeySet)\n- [2.35.0](/cpp/docs/reference/spanner/2.35.0/classgoogle_1_1cloud_1_1spanner_1_1KeySet)\n- [2.34.0](/cpp/docs/reference/spanner/2.34.0/classgoogle_1_1cloud_1_1spanner_1_1KeySet)\n- [2.33.0](/cpp/docs/reference/spanner/2.33.0/classgoogle_1_1cloud_1_1spanner_1_1KeySet)\n- [2.32.0](/cpp/docs/reference/spanner/2.32.0/classgoogle_1_1cloud_1_1spanner_1_1KeySet)\n- [2.31.0](/cpp/docs/reference/spanner/2.31.0/classgoogle_1_1cloud_1_1spanner_1_1KeySet)\n- [2.30.0](/cpp/docs/reference/spanner/2.30.0/classgoogle_1_1cloud_1_1spanner_1_1KeySet)\n- [2.29.0](/cpp/docs/reference/spanner/2.29.0/classgoogle_1_1cloud_1_1spanner_1_1KeySet)\n- [2.28.0](/cpp/docs/reference/spanner/2.28.0/classgoogle_1_1cloud_1_1spanner_1_1KeySet)\n- [2.27.0](/cpp/docs/reference/spanner/2.27.0/classgoogle_1_1cloud_1_1spanner_1_1KeySet)\n- [2.26.0](/cpp/docs/reference/spanner/2.26.0/classgoogle_1_1cloud_1_1spanner_1_1KeySet)\n- [2.25.1](/cpp/docs/reference/spanner/2.25.1/classgoogle_1_1cloud_1_1spanner_1_1KeySet)\n- [2.24.0](/cpp/docs/reference/spanner/2.24.0/classgoogle_1_1cloud_1_1spanner_1_1KeySet)\n- [2.23.0](/cpp/docs/reference/spanner/2.23.0/classgoogle_1_1cloud_1_1spanner_1_1KeySet)\n- [2.22.1](/cpp/docs/reference/spanner/2.22.1/classgoogle_1_1cloud_1_1spanner_1_1KeySet)\n- [2.21.0](/cpp/docs/reference/spanner/2.21.0/classgoogle_1_1cloud_1_1spanner_1_1KeySet)\n- [2.20.0](/cpp/docs/reference/spanner/2.20.0/classgoogle_1_1cloud_1_1spanner_1_1KeySet)\n- [2.19.0](/cpp/docs/reference/spanner/2.19.0/classgoogle_1_1cloud_1_1spanner_1_1KeySet)\n- [2.18.0](/cpp/docs/reference/spanner/2.18.0/classgoogle_1_1cloud_1_1spanner_1_1KeySet)\n- [2.17.0](/cpp/docs/reference/spanner/2.17.0/classgoogle_1_1cloud_1_1spanner_1_1KeySet)\n- [2.16.0](/cpp/docs/reference/spanner/2.16.0/classgoogle_1_1cloud_1_1spanner_1_1KeySet)\n- [2.15.1](/cpp/docs/reference/spanner/2.15.1/classgoogle_1_1cloud_1_1spanner_1_1KeySet)\n- [2.14.0](/cpp/docs/reference/spanner/2.14.0/classgoogle_1_1cloud_1_1spanner_1_1KeySet)\n- [2.13.0](/cpp/docs/reference/spanner/2.13.0/classgoogle_1_1cloud_1_1spanner_1_1KeySet)\n- [2.12.0](/cpp/docs/reference/spanner/2.12.0/classgoogle_1_1cloud_1_1spanner_1_1KeySet)\n- [2.11.0](/cpp/docs/reference/spanner/2.11.0/classgoogle_1_1cloud_1_1spanner_1_1KeySet) \nThe [`KeySet`](/cpp/docs/reference/spanner/2.16.0/classgoogle_1_1cloud_1_1spanner_1_1KeySet) class is a regular type that represents a collection of `Key`s. \nUsers can construct a [`KeySet`](/cpp/docs/reference/spanner/2.16.0/classgoogle_1_1cloud_1_1spanner_1_1KeySet) instance, then add `Key`s and ranges of `Key`s to the set. The caller is responsible for ensuring that all keys in a given [`KeySet`](/cpp/docs/reference/spanner/2.16.0/classgoogle_1_1cloud_1_1spanner_1_1KeySet) instance contain the same number and types of values.\n\nUsers may also optionally construct an instance that represents all keys with [`KeySet::All()`](/cpp/docs/reference/spanner/2.16.0/classgoogle_1_1cloud_1_1spanner_1_1KeySet#classgoogle_1_1cloud_1_1spanner_1_1KeySet_1a3796d3d86841ed54837c25376a810302).\n\n###### Example\n\n auto delete_albums = spanner::DeleteMutationBuilder(\n \"Albums\", spanner::KeySet()\n .AddKey(spanner::MakeKey(2, 1))\n .AddKey(spanner::MakeKey(2, 3)))\n .Build();\n\n###### Example\n\n void DeleteAll(google::cloud::spanner::Client client) {\n namespace spanner = ::google::cloud::spanner;\n\n // Delete all the performances, venues, albums and singers.\n auto commit = client.Commit(spanner::Mutations{\n spanner::MakeDeleteMutation(\"Performances\", spanner::KeySet::All()),\n spanner::MakeDeleteMutation(\"Venues\", spanner::KeySet::All()),\n spanner::MakeDeleteMutation(\"Albums\", spanner::KeySet::All()),\n spanner::MakeDeleteMutation(\"Singers\", spanner::KeySet::All()),\n });\n if (!commit) throw std::move(commit).status();\n std::cout \u003c\u003c \"delete-all was successful\\n\";\n }\n\nConstructors\n------------\n\n### KeySet()\n\nConstructs an empty [`KeySet`](/cpp/docs/reference/spanner/2.16.0/classgoogle_1_1cloud_1_1spanner_1_1KeySet).\n\n### KeySet(KeySet const \\&)\n\n### KeySet(KeySet \\&\\&)\n\nOperators\n---------\n\n### operator=(KeySet const \\&)\n\n### operator=(KeySet \\&\\&)\n\nFunctions\n---------\n\n### static All()\n\nReturns a [`KeySet`](/cpp/docs/reference/spanner/2.16.0/classgoogle_1_1cloud_1_1spanner_1_1KeySet) that represents the set of \"All\" keys for the index. \n\n###### Example\n\n void DeleteAll(google::cloud::spanner::Client client) {\n namespace spanner = ::google::cloud::spanner;\n\n // Delete all the performances, venues, albums and singers.\n auto commit = client.Commit(spanner::Mutations{\n spanner::MakeDeleteMutation(\"Performances\", spanner::KeySet::All()),\n spanner::MakeDeleteMutation(\"Venues\", spanner::KeySet::All()),\n spanner::MakeDeleteMutation(\"Albums\", spanner::KeySet::All()),\n spanner::MakeDeleteMutation(\"Singers\", spanner::KeySet::All()),\n });\n if (!commit) throw std::move(commit).status();\n std::cout \u003c\u003c \"delete-all was successful\\n\";\n }\n\n### AddKey(Key)\n\nAdds the given `key` to the [`KeySet`](/cpp/docs/reference/spanner/2.16.0/classgoogle_1_1cloud_1_1spanner_1_1KeySet). \n\n###### Example\n\n auto delete_albums = spanner::DeleteMutationBuilder(\n \"Albums\", spanner::KeySet()\n .AddKey(spanner::MakeKey(2, 1))\n .AddKey(spanner::MakeKey(2, 3)))\n .Build();\n\n### AddRange(KeyBound, KeyBound)\n\nAdds a range of keys defined by the given [`KeyBound`](/cpp/docs/reference/spanner/2.16.0/classgoogle_1_1cloud_1_1spanner_1_1KeyBound)s. \n\n###### Example\n\n auto delete_albums = spanner::DeleteMutationBuilder(\n \"Albums\", spanner::KeySet()\n .AddKey(spanner::MakeKey(2, 1))\n .AddKey(spanner::MakeKey(2, 3)))\n .Build();"]]