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

📄 bestrowidentifier.sql

📁 derby database source code.good for you.
💻 SQL
字号:
---- test java.sql.Connection.DatabaseMetaData.getBestRowIdentifier()---- create a java procedure to do the metadata callcreate procedure getBestRowID(in schema_param Char(10), in tableName_param Char(10), in scope_param int, in nullable_param Char(5)) parameter style java reads sql data dynamic result sets 1 language java external name 'org.apache.derbyTesting.functionTests.util.metadataHelperProcs.getBestRowId'; prepare bestrow as 'call getBestRowID(?,?,?,?)';autocommit off;-- each one of these have only one choicecreate table t1 (i int not null primary key, j int);create table t2 (i int not null unique, j int);-- adding not null unique to j - otherwise t2 & t3 would be same.create table t3 (i int not null unique, j int not null unique);create table t4 (i int, j int);create unique index t4i on t4(i);create table t5 (i int, j int);-- result: column iexecute bestrow using 'values(''APP'',''T1'',0,''true'')';-- result: column iexecute bestrow using 'values(''APP'',''T2'',0,''true'')';-- result: column iexecute bestrow using 'values(''APP'',''T3'',0,''true'')';-- result: column iexecute bestrow using 'values(''APP'',''T4'',0,''true'')';-- result: columns i and jexecute bestrow using 'values(''APP'',''T5'',0,''true'')';rollback work;-- PK preferred to uniquecreate table t6 (i int not null unique, j int not null primary key);-- result: column jexecute bestrow using 'values(''APP'',''T6'',0,''true'')';-- PK preferred to unique indexcreate table t7 (i int not null, j int not null primary key);create unique index t7i_index on t7(i);-- result: column jexecute bestrow using 'values(''APP'',''T7'',0,''true'')';-- unique con preferred to unique indexcreate table t8 (i int not null, j int not null unique);create unique index t8i_index on t8(i);-- result: column jexecute bestrow using 'values(''APP'',''T8'',0,''true'')';-- non-unique index just ignoredcreate table t9 (i int, j int);create index t9i_index on t9(i);-- result: columns i,jexecute bestrow using 'values(''APP'',''T9'',0,''true'')';rollback work;-- fewer cols unique con still ignored over primary keycreate table t10 (i int unique not null , j int not null , primary key (i,j));-- result: columns i,jexecute bestrow using 'values(''APP'',''T10'',0,''true'')';-- fewer cols unique index still ignored over primary keycreate table t11 (i int not null, j int not null, primary key (i,j));create unique index t11i_index on t11(i);-- result: columns i,jexecute bestrow using 'values(''APP'',''T11'',0,''true'')';-- fewer cols unique index still ignored over unique concreate table t12 (i int not null, j int not null, unique (i,j));create unique index t12i_index on t12(i);-- result: columns i,jexecute bestrow using 'values(''APP'',''T12'',0,''true'')';rollback work;-- REMIND: we aren't handling nullOk flag correctly-- we just drop nullable cols, we should skip an answer-- that has nullable cols in it instead and look for another one.create table t13 (i int not null, j int not null, k int, unique (i,j));-- result: columns i, j (WRONG) -- the correct answer is k: the non-null columns of the tableexecute bestrow using 'values(''APP'',''T13'',0,''false'')';-- fewest cols unique con is the one picked of severalcreate table t14 (i int not null unique, j int not null, k int, unique (i,j));-- result: columns iexecute bestrow using 'values(''APP'',''T14'',0,''true'')';-- fewest cols unique index is the one picked of severalcreate table t15 (i int not null, j int not null, k int);create unique index t15ij on t15(i,j);create unique index t15i on t15(i);-- result: columns iexecute bestrow using 'values(''APP'',''T15'',0,''true'')';-- we don't do anything with SCOPE except detect bad valuescreate table t16 (i int not null primary key, j int);-- result: columns iexecute bestrow using 'values(''APP'',''T16'',1,''true'')';-- result: columns iexecute bestrow using 'values(''APP'',''T16'',2,''true'')';-- result: no rowsexecute bestrow using 'values(''APP'',''T16'',-1,''true'')';-- result: no rowsexecute bestrow using 'values(''APP'',''T16'',3,''true'')';rollback work;

⌨️ 快捷键说明

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