CLASS Demonstration - STEP 2

docx

School

Conestoga College *

*We aren’t endorsed by this school

Course

DATA MODEL

Subject

Information Systems

Date

Feb 20, 2024

Type

docx

Pages

3

Uploaded by AdmiralTeam13438

Report
Practice 2: Getting Started with Cassandra Commands (Case Study: Employee Management) (THIS DOCUMENT SHOULD BE USED DURING THE DEMONSTRATION BY THE PROFESSOR) Introduction: In this lab, we will explore the basics of using Cassandra commands through a case study focused on employee management. You will learn how to create a keyspace, define a table schema, insert data, query the data, update records, delete data, and finally, drop the keyspace. These steps will help you understand the fundamental operations in Cassandra and how they can be applied in a real-world scenario. Case Study Scenario: You have been assigned the task of creating an employee management system using Cassandra. The system will store employee details such as ID, name, age, and department. You will utilize Cassandra commands to set up the necessary keyspace, create a table, insert sample employee data, perform queries to retrieve employee information, update employee records, delete specific employee data, and finally, drop the keyspace to clean up the environment. Now, let's proceed with the step-by-step lab instructions. Step 1: Start Cassandra - Start the Cassandra service or launch the Cassandra server on your local machine. Step 2: Launch the Cassandra Query Language Shell (cqlsh) - Open a terminal or command prompt and launch the cqlsh tool to interact with Cassandra. Step 3: Create a Keyspace - You have already created the Keyspace, o use the ones you created. Step 4: Use the Keyspace - Switch to the newly created keyspace using the following command: USE my_keyspace; This sets the active keyspace for your subsequent queries. Step 5: Create a Table - Create a table within the keyspace to store employee information. Use the following command: CREATE TABLE employees (id INT PRIMARY KEY, name TEXT, age INT, department TEXT);
This creates a table named "employees" with columns for employee ID, name, age, and department. Step 6: List all the tables in the keyspace DESCRIBE TABLES; You will be able to see all your tables within that keyspace. Step 7: Describe the content of a table DESC <name of table> Step 8: Insert Data - Insert sample data into the table using the following command: INSERT INTO employees (id, name, age, department) VALUES (1, 'John Doe', 30, 'Engineering'); INSERT INTO employees (id, name, age, department) VALUES (2, 'Jane Smith', 35, 'Marketing'); INSERT INTO employees (id, name, age, department) VALUES (3, 'Mike Johnson', 28, 'Sales'); This inserts three rows of employee data into the table. Step 9: Query Data - Retrieve employee data from the table using the following command: SELECT * FROM employees; This fetches all rows and columns from the "employees" table. <capture screenshot for submission – Screenshot 1> Step 10: Update Data - Update an employee's age using the following command: UPDATE employees SET age = 31 WHERE id = 1; This modifies the age of the employee with ID 1 to 31. <capture screenshot for submission – Screenshot 2> Step 11: Delete Data - Delete an employee's record from the table using the following command: DELETE FROM employees WHERE id = 3;
This removes the employee with ID 3 from the table. Step 12: Drop the Keyspace - Drop the keyspace and all its associated tables using the following command: DROP KEYSPACE my_keyspace; Exercise caution as this permanently deletes the keys pace and its data. Note: Ensure you have a local Cassandra instance or a remote Cassandra cluster accessible to complete this lab.
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help