C-Sharp | Java | Python | Swift | GO | WPF | Ruby | Scala | F# | JavaScript | SQL | PHP | Angular | HTML
Cassandra CollectionsCassandra collections are used to handle tasks. You can store multiple elements in collection. There are three types of collection supported by Cassandra:
Set CollectionA set collection stores group of elements that returns sorted elements when querying. Syntax: Create table table_name ( id int, Name text, Email set<text>, Primary key(id) ); Example: Let's take an example to demonstrate set collection. Create a table "employee" having the three columns id, name and email. The table is created like this: Insert values in the table: INSERT INTO employee (id, email, name) VALUES(1, {'ajeetraj4u@gmail.com'}, 'Ajeet'); INSERT INTO employee (id, email, name) VALUES(2,{'kanchan@gmail.com'}, 'Kanchan'); INSERT INTO employee (id, email, name) VALUES(3, {'kunwar4u@gmail.com'}, 'Kunwar'); Output: List CollectionThe list collection is used when the order of elements matters. Let's take the above example of "employee" table and a new column name "department" in the table employee. Now the new column is added. Insert some value in the new column "department". Output: Map CollectionThe map collection is used to store key value pairs. It maps one thing to another. For example, if you want to save course name with its prerequisite course name, you can use map collection. See this example: Create a table named "course". Now table is created. Insert some data in map collection type. Output:
Next TopicCassandra Interview Questions
|