Primary Key : Example...

cqlsh> // Primary Key : A row is identified by Primary Key
cqlsh>
cqlsh> // Primary Key is Mandatory
cqlsh> use ks;
cqlsh:ks> drop table student
      ... create table student(
      ...    name text,
      ...    class text);
SyntaxException: line 2:0 no viable alternative at input 'create' (drop table [student]create...)
cqlsh:ks>
cqlsh:ks> // Create table with Primary Key
cqlsh:ks> drop table student;
cqlsh:ks> create table student(
      ...    name text,
      ...    class text,
      ...    primary key(name));
cqlsh:ks>
cqlsh:ks> // Insert Data
cqlsh:ks> insert into student(name, class) values('Bob', '1st');
cqlsh:ks>
cqlsh:ks> // Select query only works on a Key
cqlsh:ks> select * from student where class='1st';
InvalidRequest: Error from server: code=2200 [Invalid query] message="Cannot execute this query as it might involve data filtering and thus may have unpredictable performance. If you want to execute this query despite the performance unpredictability, use ALLOW FILTERING"
cqlsh:ks>
cqlsh:ks> // Using  Primary Key to select a Row
cqlsh:ks> select * from student where name='Bob';

 name | class
------+-------
  Bob |   1st

(1 rows)

No comments:

Post a Comment