Advertisement
Guest User

Untitled

a guest
Jun 25th, 2019
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.47 KB | None | 0 0
  1. -- Create a new keyspace with the name 'cqlintro' and the SimpleStrategy as the
  2. -- replication strategy and a replication factor of 1. SimpleStrategy is fine for
  3. -- development or just playing but once you're setting up a keyspace in production
  4. -- be sure to switch to NetworkTopologyStrategy!
  5. CREATE KEYSPACE cqlintro
  6. WITH REPLICATION = {'class':'SimpleStrategy', 'replication_factor':1};
  7.  
  8. -- Start using the new keyspace as the default keyspace.
  9. -- You don't need to do this part as you can just refer to tables with the full
  10. -- name of 'cqlintro.table_name', this just makes it easier.
  11. USE cqlintro;
  12.  
  13. CREATE TABLE company (
  14. company_id INT,
  15. name VARCHAR,
  16. PRIMARY KEY (company_id)
  17. );
  18. INSERT INTO company (company_id, name) VALUES (1, 'ShoreTel');
  19. INSERT INTO company (company_id, name) VALUES (2, 'Erik''s Company');
  20.  
  21. CREATE TABLE employee (
  22. company_id INT,
  23. employee_id INT,
  24. first_name VARCHAR,
  25. last_name VARCHAR,
  26. PRIMARY KEY ((company_id), employee_id)
  27. );
  28. INSERT INTO employee (company_id, employee_id, first_name, last_name) VALUES (1, 1, 'John', 'Doe');
  29. INSERT INTO employee (company_id, employee_id, first_name, last_name) VALUES (1, 2, 'Jane', 'Doe');
  30. INSERT INTO employee (company_id, employee_id, first_name, last_name) VALUES (2, 3, 'Erik', 'Davidson');
  31. INSERT INTO employee (company_id, employee_id, first_name, last_name) VALUES (2, 4, 'Joe', 'Cool');
  32.  
  33. -- Returns all the employees for "Erik's Company"
  34. SELECT * FROM employee WHERE company_id = 2;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement