kingbase数据库建表及插数据

kingbase数据库建表及插数据

一、建表

 CREATE TABLE   KB表名(

    T_ID                  bigint,

    T_NUMERIC     numeric(10,5),

    T_DATE             date,

    T_TIMESTAMP    timestamp,

    T_VARCHAR    varchar(20),

    T_CHAR    char(20),

    T_CLOB  clob,

    T_TEXT text,

    T_BLOB  blob,

    T_XML xml,

    T_REAL real,

    T_BIT  bit(2000),

    T_BOOL  bool,

PRIMARY KEY (T_ID)

);

二、插入数据

CREATE PROCEDURE  PRO_KB表名() as

DECLARE

v_id integer :=1;

i_date bigint  :=200101010000;

I_time bigint  :=200101010000;

v_date  date;

v_time  timestamp;

BEGIN

FOR i IN 1..10 LOOP

   SELECT to_date(to_char(i_date),'yyyymmddhh24miss') into v_date from dual;

   SELECT to_timestamp(to_char(i_time),'yyyymmddhh24miss') into v_time from dual;

   INSERT INTO KB表名 VALUES (

  v_id,v_id,v_date,v_time,concat('a@项目',v_id),'您好',

 '1010101010101','1010101010101','58354F2150','1010101010101',

 atan2(1,v_id),B'101011101010110'::bit(2000),'1'

 );

 v_id := v_id+1;

 i_date := i_date+10000;

 i_time := i_time+1;

END LOOP;

END;

CALL PRO_KB表名();

DROP PROCEDURE PRO_KB表名;

三、主从表

CONSTRAINT PK_从表() FOREIGN KEY(从表外键字段) REFERENCES 主表(主键字段)

四、主键自增

CREATE TABLE KB_AUTO(

t_bigint bigint IDENTITY(1,1),

t_integer integer,

PRIMARY KEY(t_bigint)

);


CREATE PROCEDURE  PRO_KB_AUTO() as

DECLARE

v_id integer :=1;

BEGIN

FOR i IN 1..10 LOOP

INSERT INTO KB_AUTO (t_integer)  VALUES(v_id);

 v_id := v_id+1;

END LOOP;

END;

CALL PRO_KB_AUTO();

DROP PROCEDURE PRO_KB_AUTO;

五、操作界面









你可能感兴趣的:(数据库)