Reputation: 329
I have a table user_activity.
user_activity
{
user_id text
user_name text
email_id text
password text
activity1 text}
Is it possible to add column dynamically?
for ex -
user1(user_id : Rowkey)
user_name, emai_id, password, activity1, activity2
user2(user_id : Rowkey)
user_name, emai_id, password, activity1, activity2, activity3
user3(user_id : Rowkey)
user_name, emai_id, password, activity1
since activities could be of any number.
thanks in advance :)
Upvotes: 1
Views: 131
Reputation: 12830
You can use Map
For example :
CREATE TABLE user_activity (
user_id text primary key,
emai_id text,
password text,
activity map<text,text>
);
Insert :
INSERT INTO user_activity (user_id, emai_id, password, activity) VALUES ('1', '[email protected]','password1', {'activity1' : 'test activity 1', 'activity2' : 'test acitivty 2' });
Update :
UPDATE user_activity SET activity['activity1'] = 'updated test activity 1' where user_id = '1';
Delete :
DELETE activity['activity2'] FROM user_activity WHERE user_id = '1';
Note : Keep the collection (map) size small, In Cassandra for map Maximum number of keys: 65535 and values size: 65535
Upvotes: 1