fork download
  1. -- Create a new keyspace called 'library'
  2. CREATE KEYSPACE library WITH REPLICATION = { 'class' : 'SimpleStrategy', 'replication_factor' : 1 };
  3. USE library;
  4.  
  5. -- Create a table for authors
  6. CREATE TABLE authors (
  7. author_id uuid PRIMARY KEY,
  8. firstname varchar,
  9. lastname varchar,
  10. email varchar
  11. );
  12.  
  13. -- Insert an author
  14. INSERT INTO authors (author_id, firstname, lastname, email) VALUES (uuid(), 'Jane', 'Austen', 'janeausten@gmail.com');
  15.  
  16. -- Drop the email column
  17. ALTER TABLE authors DROP email;
  18.  
  19. -- Add a new column 'age'
  20. ALTER TABLE authors ADD age int;
  21.  
  22. -- Insert another author with the new age column
  23. INSERT INTO authors (author_id, firstname, lastname, age) VALUES (uuid(), 'Mark', 'Twain', 45);
  24.  
  25. -- Create a table for books
  26. CREATE TABLE books (
  27. book_id uuid PRIMARY KEY,
  28. title varchar,
  29. author_id uuid,
  30. publication_date date
  31. );
  32.  
  33. -- Insert a book
  34. INSERT INTO books (book_id, title, author_id, publication_date) VALUES (uuid(), 'Pride and Prejudice', (SELECT author_id FROM authors WHERE firstname='Jane' AND lastname='Austen'), '1813-01-28');
  35.  
  36. -- Querying all authors
  37. SELECT * FROM authors;
  38.  
  39. -- Querying all books
  40. SELECT * FROM books;
  41.  
Success #stdin #stdout #stderr 0s 5304KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
Error: near line 2: near "KEYSPACE": syntax error
Error: near line 3: near "USE": syntax error
Error: near line 14: no such function: uuid
Error: near line 17: near "DROP": syntax error
Error: near line 23: no such function: uuid
Error: near line 34: no such function: uuid