Vertica資料庫操作,vertica資料庫

來源:互聯網
上載者:User

Vertica資料庫操作,vertica資料庫

  刪除主鍵(Vertica資料庫的主鍵值並不是唯一的):
SELECT ANALYZE_CONSTRAINTS('fb_s.c_log');

找到key名,再:

ALTER TABLE fb_s.c_log DROP CONSTRAINT C_PRIMARY;

SELECT ANALYZE_CONSTRAINTS('fb_s.user_info');

ALTER TABLE fb_s.user_info DROP CONSTRAINT C_PRIMARY;

建使用者和SCHEMA :

CREATE user fb_s_sql IDENTIFIED BY 'password';
CREATE SCHEMA fb_s_sql;

給許可權:
GRANT ALL ON SCHEMA fb_s_sql TO fb_s_sql;
GRANT ALL ON SCHEMA fb_s TO fb_s_sql;

GRANT ALL ON TABLE fb_s_sql.sqllog TO fb_s_sql;

建表:

CREATE TABLE fb_s.c_log (
uid int NOT NULL,
cash int,
gold int,
level int,
rtime datetime,
tid varchar(20),
act varchar(50),
item varchar(500),
value int,
value2 int,
time datetime
);

CREATE TABLE fb_s.new_c_log (
uid integer PRIMARY KEY NOT NULL,
cash integer,
gold integer,
level integer,
rtime datetime,
tid varchar(20),
act varchar(50),
item varchar(500),
value integer,
value2 integer,
time datetime NOT NULL
)
PARTITION BY EXTRACT(year FROM time)*100 + EXTRACT(month FROM time);

後一個是按time欄位分區

增加及修改欄位:

ALTER TABLE fb_s.c_logADD COLUMN value2 integer default 0;
ALTER TABLE fb_s.c_log ALTER COLUMN duration SET DEFAULT 0;
ALTER TABLE fb_s.c_log ALTER COLUMN mesg SET DEFAULT '';


兩表之間導資料:
insert into fb_s.c_log (uid,cash,gold,level,rtime,tid,act,item,value,value2,time)
(select * from fb_s.c_logbak);

兩庫之間導資料:

在源庫匯出:

vsql -d topcity -U dbadmin -w password -F ',' -At -o fs_user_info.csv -c "SELECT * FROM fb_s.user_info;" &
vsql -d topcity -U dbadmin -w password -F ',' -At -o fs_c_log.csv -c "SELECT * FROM fb_s.c_log;" &

目的庫匯入:
COPY fb_s.user_info FROM '/opt/fs_user_info.csv' EXCEPTIONS '/tmp/exp.log' DELIMITER ',';

COPY fb_s.c_log FROM '/opt/fs_c_log.csv' EXCEPTIONS '/tmp/exp.log' DELIMITER ',';

著作權聲明:本文為博主原創文章,未經博主允許不得轉載。

相關文章

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.