-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathChapter1_CQL_Keyspace.cql
More file actions
68 lines (47 loc) · 2.24 KB
/
Chapter1_CQL_Keyspace.cql
File metadata and controls
68 lines (47 loc) · 2.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
-- keyspace : Is is similar to concept of database in relational model... it holds tables and defines replication strategies.
-- Creating keyspace :
create keyspace if not exists students with replication = {'class': 'SimpleStrategy' ,'r
eplication_factor' : 3};
-- class : replication strategy that is used in data model...
-- SimpleStrategy : It is used when layout of datacentre is unknown . It is a simple strategy that is recommended for multiple nodes over multiple racks in a single data center.
-- NetworkTopologyStrategy : It is the strategy in which we can store multiple copies of data on different data centers as per need.
-- replication_factor : It tells the no of nodes that hold the copies of data sent by client
-- Creating Simple Strategy Based Keyspace
create keyspace if not exists simp_strat_keyspace with replication = {
'class' : 'SimpleStrategy',
'replication_factor' : 3
};
-- Creating NetworkTopology Strategy Keyspace
create keyspace if not exists net_topo_strat_keyspace with replication = {
'class' : 'NetworkTopologyStrategy',
'dc1' : 3, -- it says that there is a replication factor of 3 in datacentre1.
'dc2' : 2 -- it says that there is a replication factor of 2 in datacentre2.
};
-- to ensure data engrity (data must write in commit log)
create keyspace temp with replication = {
'class' : 'NetworkTopologyStrategy',
'dc1' : 2,
'dc2' : 3
} with durable_writes = true;
-- to use a certain keyspace : to be in a certain keyspace , entre name of keyspace using 'use' keyword
USE temp;
use net_topo_strat_keyspace;
-- alter keyspace : any modification to kespace strategies and attributes
alter keyspace if exists net_topo_strat_keyspace with replication = {
'class' : 'NetworkTopologyStrategy'
'dc1' : 3,
'dc2' : 2,
'dc3' : 3
}with durable_writes = false;
-- defining transient replication :
create keyspace some_keyspace with replication = {
'class' : 'NetworkTopologyStrategy',
'dc1' : '3/1',
'dc2' : '5/2'
} with durable_writes = true;
-- to delete certain keyspace : 'drop'
drop keyspace temp;
-- to understand the keyspace:
desc keyspace_name;
-- to get list of al keyspaces :
desc keyspaces;