⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 rollforwardrecovery.sql

📁 derby database source code.good for you.
💻 SQL
📖 第 1 页 / 共 2 页
字号:
-- reusing container id caserun resource 'createTestProcedures.subsql';call SYSCS_UTIL.SYSCS_BACKUP_DATABASE_AND_ENABLE_LOG_ARCHIVE_MODE(    'extinout/mybackup', 0);create table t1(a int not null primary key) ;insert into t1 values(1) ;insert into t1 values(2) ;insert into t1 values(3 ) ;drop table t1;connect 'jdbc:derby:wombat;shutdown=true';disconnect;connect 'jdbc:derby:wombat';--checkpoint to make sure that --the stub is dropped and we use the --the same container id which we dropped earlierCALL SYSCS_UTIL.SYSCS_CHECKPOINT_DATABASE();create table t1(a int not null primary key) ;insert into t1 values(4) ;insert into t1 values(5);insert into t1 values(6);select * from t1;connect 'jdbc:derby:wombat;shutdown=true';disconnect;--performa rollforward recoveryconnect 'jdbc:derby:wombat;rollForwardRecoveryFrom=extinout/mybackup/wombat';select * from t1 ;--drop the above tables and create--again tables with foreign key references and--make surte they are properly recovereddrop table t1;create table t1(a int not null);insert into t1 values(1) ;insert into t1 values(2) ;insert into t1 values(3 ) ;insert into t1 values(4 ) ;insert into t1 values(5 ) ;alter table t1 add constraint uk1 unique(a);create table t2(b int);insert into t2 values(1);insert into t2 values(2);insert into t2 values(3);alter table t2 add constraint c1 foreign key (b)                             references t1(a);connect 'jdbc:derby:wombat;shutdown=true';disconnect;connect 'jdbc:derby:wombat;rollForwardRecoveryFrom=extinout/mybackup/wombat';insert into t2 values(4);insert into t2 values(5);select * from t1;select * from t2;--add a duplicate value to make sure index is intactinsert into t1 values(1);--add a value that does not exits in the parent table--to make reference indexes are fine.insert into t2 values(999);---REGULAR UNLOGGED CASES , BUT LOGGED WHEN ARCHIVE MODE IS ENABLED.--compress table call SYSCS_UTIL.SYSCS_COMPRESS_TABLE('APP', 'T1', 0);select * from t1;create table t3(c1 int not null);create table t4(c1 int not null);--insertinsert into t3 (c1) values(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);insert into t4 values(101) ,(102) , (103), (104), (105), (106), (107) , (108), (109) , (110) , (111), (112) , (113), (114),(115), (116), (117), (118) , (119) , (120) , (121) , (122) , (123) , (124) , (125) , (126) , (127) , (128), (129), (130);insert into t4 values(1001);alter table t3 add column c2 char(20);--add constraint--alter table t3 add column c2 int not null primary key;--alter table t4 add column c2 int not null;--alter table t3 add column c3 int not null unique;connect 'jdbc:derby:wombat;shutdown=true';disconnect;connect 'jdbc:derby:wombat;rollForwardRecoveryFrom=extinout/mybackup/wombat';select * from t1;select * from t2;select * from t3;select * from t4;insert into t3 (c1) values(101) ,(102) , (103), (104), (105), (106), (107) , (108), (109) , (110) , (111), (112) , (113), (114),(115), (116), (117), (118) , (119) , (120) , (121) , (122) , (123) , (124) , (125) , (126) , (127) , (128), (129), (130);insert into t3 (c1) values(1001), (1000);--unlogged primary key add constraintalter table t3 add constraint pk1 primary key(c1);--unlogged foreign key addalter table t4 add constraint fk1 foreign key (c1) references t3(c1);--unlogged add unique constraintalter table t4 add constraint uk2 unique(c1);connect 'jdbc:derby:wombat;shutdown=true';disconnect;connect 'jdbc:derby:wombat;rollForwardRecoveryFrom=extinout/mybackup/wombat';--following insert should throw duplicate error.insert into t4 values(101);insert into t3 (c1) values(101);--folowing should throw foreign key violations error.insert into t4 values(9999);connect 'jdbc:derby:wombat;shutdown=true';disconnect;connect 'jdbc:derby:wombat;rollForwardRecoveryFrom=extinout/mybackup/wombat';select * from t1;select * from t2;select c1 from t3;select * from t4;autocommit off;insert into t3 (c1) values(100), 99, 999;insert into t3 (c1) values(0), (-1);--let's do some updates .update t4 set c1 = c1 -1;update t3 set c1 = c1 + 1;update t3 set c2 = 'rollforward';commit;delete from t2;delete from t2;delete from t4;delete from t3;rollback;connect 'jdbc:derby:wombat;shutdown=true';disconnect;connect 'jdbc:derby:wombat;rollForwardRecoveryFrom=extinout/mybackup/wombat';select * from t1;select * from t2;select * from t3;select * from t4;create table t5(c1 int );--unlogged add column because of primary keyalter table t5 add column c2 int not null primary key default 0;--logged add columnalter table t5 add column c3 int not null default 0;--unlogged add columnalter table t5 add column c4 char(100) not null default '0';alter table t5 add constraint uconst UNIQUE(c4);insert into t5 values ( 1 , 2, 3 , 'one'), (11 , 22, 33, 'eleven'), (111, 222, 333, 'one hundred eleven');connect 'jdbc:derby:wombat;shutdown=true';disconnect;connect 'jdbc:derby:wombat;rollForwardRecoveryFrom=extinout/mybackup/wombat';select * from t5 ;--check if constraits are intact.--following insert  should throw error because they violate constraints;insert into t5 values ( 1 , 2, 3 , 'one');insert into t5 values ( 1111 , 2222, null , 'one again');insert into t5 values ( 1111 , 2222, 3333 , 'one');insert into t5 values ( 1111 , 2222, 3333 , 'four ones ..');select * from t5;connect 'jdbc:derby:wombat;shutdown=true';disconnect;connect 'jdbc:derby:wombat;rollForwardRecoveryFrom=extinout/mybackup/wombat';select * from t5;--- Have to check long varchar/binary  recovery stuff.-- create a table with 5 rows, with 4K pageSize,-- this should expand over 3 pagescreate table testing 	(a varchar(2024), b varchar(1024), c varchar(1024), d varchar(2048), e varchar(300)) ;-- insert 9 rows into the tableinsert into testing values (PADSTRING('1',2024),	PADSTRING('2',1024),        PADSTRING('3',1024),         PADSTRING('4',2048),         PADSTRING('5',300));insert into testing values (PADSTRING('10',2024),	PADSTRING('20',1024),	    PADSTRING('30',1024),        PADSTRING('40',2048),        PADSTRING('50',300));insert into testing values (PADSTRING('100',2024),	PADSTRING('200',1024),	    PADSTRING('300',1024),       PADSTRING('400',2048),       PADSTRING('500',300));insert into testing values (PADSTRING('1000',2024),	PADSTRING('2000',1024),     PADSTRING('3000',1024),      PADSTRING('4000',2048),      PADSTRING('5000',300));insert into testing values (PADSTRING('10000',2024),	PADSTRING('20000',1024),    PADSTRING('30000',1024),     PADSTRING('40000',2048),     PADSTRING('50000',300));insert into testing values (PADSTRING('100000',2024),	PADSTRING('200000',1024),   PADSTRING('300000',1024),    PADSTRING('400000',2048),    PADSTRING('500000',300));insert into testing values (PADSTRING('1000000',2024),  PADSTRING('2000000',1024),  PADSTRING('3000000',1024),   PADSTRING('4000000',2048),   PADSTRING('5000000',300));insert into testing values (PADSTRING('10000000',2024), PADSTRING('20000000',1024), PADSTRING('30000000',1024),  PADSTRING('40000000',2048),  PADSTRING('50000000',300));insert into testing values (PADSTRING('100000000',2024),PADSTRING('200000000',1024), PADSTRING('300000000',1024), PADSTRING('400000000',2048), PADSTRING('500000000',300));connect 'jdbc:derby:wombat;shutdown=true';disconnect;connect 'jdbc:derby:wombat;rollForwardRecoveryFrom=extinout/mybackup/wombat';-- select the whole row, or individual columns.-- 9 rows should be returned from each of the following selectsselect * from testing;select a from testing;select b from testing;select c from testing;select d from testing;select e from testing;-- insert some partial rows. insert into testing (a) values (PADSTRING('a',2024));insert into testing (a, b) values (PADSTRING('a',2024), PADSTRING('b',1024));insert into testing (a, b, c) values (PADSTRING('a',2024), PADSTRING('b',1024), PADSTRING('c',1024));insert into testing (a, b, c, d) values (PADSTRING('a',2024), PADSTRING('b',1024), PADSTRING('c',1024), PADSTRING('d',2048));insert into testing (a, b, c, d, e) values (PADSTRING('a',2024), PADSTRING('b',1024), PADSTRING('c',1024), PADSTRING('d',2048), PADSTRING('e',300));connect 'jdbc:derby:wombat;shutdown=true';disconnect;connect 'jdbc:derby:wombat;rollForwardRecoveryFrom=extinout/mybackup/wombat';-- select some partial rows.-- should select 14 rowsselect * from testing;-- should select 5 rowsselect * from testing where a = PADSTRING('a',2024);-- should select 4 rowsselect a,c,d from testing where b = PADSTRING('b',1024);-- should select 1 rowselect b, e from testing where e = PADSTRING('e',300);-- should select 14 rowsselect a,c,e from testing order by a;-- update 5 rows on the main data pageupdate testing set a = PADSTRING('aa',2024) where a = PADSTRING('a',2024);-- following select should return 0 rowsselect * from testing where a = PADSTRING('a',2024);-- following select should return 5 rowsselect * from testing where a = PADSTRING('aa',2024);-- update 3 rows on the overflow pageupdate testing set c = PADSTRING('cc',1024) where c = PADSTRING('c',1024);-- following should return 0 rowsselect * from testing where c = PADSTRING('c',1024);-- followign should return 3 rowsselect a, b, c, d, e from testing where c = PADSTRING('cc',1024);-- update 1 row on second overflow pageupdate testing set e = PADSTRING('ee',300) where e = PADSTRING('e',300);-- following select should return 0 rowsselect e from testing where e = PADSTRING('e',300);-- following should return 1 rowselect e from testing where e = PADSTRING('ee',300);-- update all columns for 2 rowsupdate testing set a = PADSTRING('aaa',2024), b = PADSTRING('bbb',1024), c = PADSTRING('ccc',1024), d = PADSTRING('ddd',2048), e = PADSTRING('eee',300)	where d = PADSTRING('d',2048);connect 'jdbc:derby:wombat;shutdown=true';disconnect;connect 'jdbc:derby:wombat;rollForwardRecoveryFrom=extinout/mybackup/wombat';-- following select should return 0 rowsselect * from testing where d = PADSTRING('d',2048);-- following select should return 2 rowsselect * from testing where d = PADSTRING('ddd',2048);-- create a table with 6 rowsdrop table testing;create table testing (a varchar(500), b varchar (500), c varchar(500), d varchar(500),	e varchar(500), f varchar(500), g varchar(500), z varchar(3900)) ;insert into testing values (PADSTRING('1',500), PADSTRING('2',500), PADSTRING('3',500), PADSTRING('4',500), PADSTRING('5',500), PADSTRING('6',500), PADSTRING('7',500), PADSTRING('1000',3900));insert into testing values (PADSTRING('1',500), PADSTRING('2',500), PADSTRING('3',500), PADSTRING('4',500), PADSTRING('5',500), PADSTRING('6',500), PADSTRING('7',500), PADSTRING('2000',3900));select * from testing;select e from testing;select g from testing;select z from testing;-- create long rows which expand over 3 or more pages. Test that various

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -