锘??xml version="1.0" encoding="utf-8" standalone="yes"?>亚洲精品人成电影网,国产精品亚洲A∨天堂不卡
,久久久青草青青国产亚洲免观
http://m.tkk7.com/WshmAndLily/articles/173442.htmlsemovysemovyMon, 07 Jan 2008 12:14:00 GMThttp://m.tkk7.com/WshmAndLily/articles/173442.htmlhttp://m.tkk7.com/WshmAndLily/comments/173442.htmlhttp://m.tkk7.com/WshmAndLily/articles/173442.html#Feedback0http://m.tkk7.com/WshmAndLily/comments/commentRss/173442.htmlhttp://m.tkk7.com/WshmAndLily/services/trackbacks/173442.html-------------------------------------------
----- teckotooling database schema --------
----- hsqldb-------------------------------
-------------------------------------------
drop table page if exists ;
--欏甸潰琛?br />
create table page
(
page_id int not null identity primary key ,
page_name varchar(12) not null,
title_en varchar(128) default '',
title_cn varchar(128) default '',
title_hk varchar(128) default '',
keyword_en varchar(128) default '',
keyword_cn varchar(128) default '',
keyword_hk varchar(128) default '',
title_content_en varchar(64) default '',
title_content_cn varchar(64) default '',
title_content_hk varchar(64) default '',
content_en longvarchar default '',
content_cn longvarchar default '',
content_hk longvarchar default '',
readTimes int default 0,
unique(page_name)
);
drop table if exists comment;
drop table if exists advancedInfo;
drop table if exists basicInfoDoc;
drop table if exists basicInfoImg;
drop table if exists basicInfoText;
drop table item if exists ;
drop table category if exists ;
--綾誨埆緋誨垪綾?br />
create table category
(
category_id int not null identity primary key ,
categoryName_en varchar(64) not null,-- unique ,
categoryName_cn varchar(64) not null,-- unique ,
categoryName_hk varchar(64) not null,-- unique ,
description_en longvarchar default '',
description_cn longvarchar default '',
description_hk longvarchar default '',
img varchar(32) default '',
unique(category_id),
unique(categoryName_en),
unique(categoryName_cn),
unique(categoryName_hk)
);
--欏圭洰琛?br />
create table item
(
item_id int not null identity primary key ,
item_no varchar(6) not null,
category_id int not null ,
itemName_en varchar(64) not null,-- unique ,
itemName_cn varchar(64) not null,-- unique ,
itemName_hk varchar(64) not null,-- unique ,
img varchar(64),
publishedDt timestamp,
lastOne char(1) default 'n',
visible char(1) default 'y',
readTimes int default 0,
unique(item_no),
unique(itemname_en),
unique(itemname_cn),
unique(itemname_hk),
foreign key(category_id) references category(category_id) on update cascade on delete cascade
);
--鍩烘湰鏂囨湰灞炴ц〃
create table basicInfoText
(
id int not null identity primary key ,
item_id int not null,
propertyName_en varchar(128) not null,
propertyName_cn varchar(128) not null,
propertyName_hk varchar(128) not null,
propertyValue_en varchar(256) default '',
propertyValue_cn varchar(256) default '',
propertyValue_hk varchar(256) default '',
unit_en varchar(32) default '',
unit_cn varchar(32) default '',
unit_hk varchar(32) default '',
visible char(1) default 'y',
foreign key(item_id) references item(item_id) on update cascade on delete cascade
);
--鍩烘湰鍥劇墖灞炴ц〃
create table basicInfoImg
(
id int not null identity primary key ,
item_id int not null ,
imgName_en varchar(64),
imgName_cn varchar(64),
imgName_hk varchar(64),
imgUrl varchar(64),
visible char(1) default 'y',
foreign key(item_id) references item(item_id) on update cascade on delete cascade
);
--鍩烘湰鍥劇墖灞炴ц〃
create table basicInfoDoc
(
id int not null identity primary key ,
item_id int not null ,
docName_en varchar(128),
docName_cn varchar(128),
docName_hk varchar(128),
docUrl varchar(64),
size varchar(16) default '',
contentType varchar(32) default '',
readTimes int,
enable char(1) default 'y',
password varchar(32),
visible char(1) default 'y',
foreign key(item_id) references item(item_id) on update cascade on delete cascade
);
--璇︾粏灞炴ц〃
create table advancedInfo
(
id int not null identity primary key ,
item_id int not null ,
content_en longvarchar ,
content_cn longvarchar ,
content_hk longvarchar ,
visible char(1) default 'y',
foreign key(item_id) references item(item_id) on update cascade on delete cascade
);
--璇勮琛?br />
create table comment
(
id int not null identity primary key,
item_id int not null ,
commenter varchar(32) not null,
dateTime timestamp,
content longvarchar default '',
visible char(1) default 'y',
foreign key(item_id) references item(item_id) on update cascade on delete cascade
);
drop table if exists leadWord;
--鐣欒█琛?br />
create table leadWord
(
id int not null identity primary key ,
leadWorder varchar(32) not null,
dateTime timestamp,
content longvarchar default '',
visible char(1) default 'y'
);
drop table if exists otherConfig;
--鍒涘緩鍏跺畠璁劇疆琛?br />
create table otherConfig
(
id int not null primary key,
enablePress char(1) default 'y',
isImagePress char(1) default 'y',
textPress varchar(32) default '',
imagePress varchar(32) default '',
userFaceStyle varchar(32) default '',
afficheEn longvarchar default '',
afficheCn longvarchar default '',
afficheHk longvarchar default ''
);
drop table if exists user_auth;
drop table if exists user;
drop table if exists authority;
--鐢ㄦ埛琛?br />
create table user
(
user_id int not null identity primary key ,
user_name varchar(32) not null,
password varchar(32),
ENABLED tinyint default 0
);
--鐢ㄦ埛鏉冮檺琛ㄨ繛鎺ヨ〃
create table user_auth
(
user_id int not null,
auth_id int not null,
primary key(user_id,auth_id),
foreign key(user_id) references user(user_id) on update cascade on delete cascade
);
--鍒涘緩鏉冮檺琛?br />
create table authority
(
auth_id int not null identity primary key ,
authority varchar(255) not null,
auth_type varchar(32) not null,
protected_res varchar(128) not null,
display varchar(64) not null,
note varchar(64) default null
) ;
--鍒濆鍖栬〃
--鐢ㄦ埛琛?br />
insert into user values(1,'admin','21232f297a57a5a743894a0e4a801fc3',1);
--欏甸潰琛?br />
insert into page
values(1,'home','home','home','home','home','home','home','home','home','home','home','home','home',0);
insert into page
values (2,'about','about','about','about','about','about','about','about','about','about','about','about','about',0);
insert into page
values(3,'product','product','product','product','product','product','product','product','product','product','product','product','product',0);
insert into page
values(4,'services','services','services','services','services','services','services','services','services','services','services','services','services',0);
insert into page
values(5,'contactUs','contactUs','contactUs','contactUs','contactUs','contactUs','contactUs','contactUs','contactUs','contactUs','contactUs','contactUs','contactUs',0);
--鍏跺畠璁劇疆
insert into otherConfig values(1,'y','y','semovy@gmail.com','logo.gif','blue.css','affiche here...','鍏憡鍦ㄦ……','鍏憡鍦ㄦ……');
--鍒濆璧勬簮閴村畾琛?/p>
--欏圭洰璧勬簮淇濇姢閴村畾
INSERT INTO authority (AUTH_ID, AUTHORITY, AUTH_TYPE, PROTECTED_RES, DISPLAY, NOTE) VALUES
(1,'AUTH_FUNC_ItemManager.saveItem','FUNCTION','com.semovy.service.IItemService.saveItem','鍒涘緩欏圭洰',NULL);
INSERT INTO authority (AUTH_ID, AUTHORITY, AUTH_TYPE, PROTECTED_RES, DISPLAY, NOTE) VALUES
(2,'AUTH_FUNC_ItemManager.updateItem','FUNCTION','com.semovy.service.IItemService.updateItem','鏇存柊欏圭洰',NULL);
INSERT INTO authority (AUTH_ID, AUTHORITY, AUTH_TYPE, PROTECTED_RES, DISPLAY, NOTE) VALUES
(3,'AUTH_FUNC_ItemManager.deleteItemById','FUNCTION','com.semovy.service.IItemService.deleteItemById','鍒犻櫎欏圭洰',NULL);
INSERT INTO authority (AUTH_ID, AUTHORITY, AUTH_TYPE, PROTECTED_RES, DISPLAY, NOTE) VALUES
(4,'AUTH_FUNC_ItemManager.outPutXMLItem','FUNCTION','com.semovy.service.IItemService.outPutXMLItem','璁塊棶欏圭洰綆$悊',NULL);
--欏甸潰璧勬簮
INSERT INTO authority (AUTH_ID, AUTHORITY, AUTH_TYPE, PROTECTED_RES, DISPLAY, NOTE) VALUES
(5,'AUTH_FUNC_PageManager.updatePage','FUNCTION','com.semovy.service.IPageService.updatePage','淇敼欏甸潰',NULL);
INSERT INTO authority (AUTH_ID, AUTHORITY, AUTH_TYPE, PROTECTED_RES, DISPLAY, NOTE) VALUES
(6,'AUTH_FUNC_PageManager.outPutPageXML','FUNCTION','com.semovy.service.IPageService.outPutPageXML','璁塊棶綆$悊欏甸潰',NULL);
--鍏跺畠綆$悊
INSERT INTO authority (AUTH_ID, AUTHORITY, AUTH_TYPE, PROTECTED_RES, DISPLAY, NOTE) VALUES
(7,'AUTH_FUNC_OtherconfigManager.updateOtherconfig','FUNCTION','com.semovy.service.IOtherconfigService.updateOtherconfig','淇敼鍏跺畠綆$悊',NULL);
INSERT INTO authority (AUTH_ID, AUTHORITY, AUTH_TYPE, PROTECTED_RES, DISPLAY, NOTE) VALUES
(8,'AUTH_FUNC_OtherconfigManager.outPutOtherconfigXML','FUNCTION','com.semovy.service.IOtherconfigService.outPutOtherconfigXML','璁塊棶鍏跺畠綆$悊',NULL);
--鐢ㄦ埛綆$悊
INSERT INTO authority (AUTH_ID, AUTHORITY, AUTH_TYPE, PROTECTED_RES, DISPLAY, NOTE) VALUES
(9,'AUTH_FUNC_UserManager.updateUser','FUNCTION','com.semovy.service.IUserService.updateUser','淇敼鐢ㄦ埛',NULL);
INSERT INTO authority (AUTH_ID, AUTHORITY, AUTH_TYPE, PROTECTED_RES, DISPLAY, NOTE) VALUES
(10,'AUTH_FUNC_UserManager.outPutUsersListXML','FUNCTION','com.semovy.service.IUserService.outPutUsersListXML','璁塊棶鐢ㄦ埛綆$悊',NULL);
--鐣欒█綆$悊
INSERT INTO authority (AUTH_ID, AUTHORITY, AUTH_TYPE, PROTECTED_RES, DISPLAY, NOTE) VALUES
(11,'AUTH_FUNC_LeadwordManager.updateUser','FUNCTION','com.semovy.service.ILeadwordService.updateLeadword','淇敼鐣欒█',NULL);
INSERT INTO authority (AUTH_ID, AUTHORITY, AUTH_TYPE, PROTECTED_RES, DISPLAY, NOTE) VALUES
(12,'AUTH_FUNC_LeadwordManager.outPutUsersListXML','FUNCTION','com.semovy.service.ILeadwordService.deleteLeadwordById','鍒犻櫎涓鏉$暀璦',NULL);
INSERT INTO authority (AUTH_ID, AUTHORITY, AUTH_TYPE, PROTECTED_RES, DISPLAY, NOTE) VALUES
(13,'AUTH_FUNC_LeadwordManager.getLeadWordsOfPageByCriteria','FUNCTION','com.semovy.service.ILeadwordService.getLeadWordsOfPageByCriteria','鑾峰彇鍒嗛〉鐣欒█',NULL);
INSERT INTO authority (AUTH_ID, AUTHORITY, AUTH_TYPE, PROTECTED_RES, DISPLAY, NOTE) VALUES
(14,'AUTH_FUNC_LeadwordManager.outPutXMLLeadword','FUNCTION','com.semovy.service.ILeadwordService.outPutXMLLeadword','璁塊棶鐣欒█綆$悊',NULL);
--璇勮綆$悊
INSERT INTO authority (AUTH_ID, AUTHORITY, AUTH_TYPE, PROTECTED_RES, DISPLAY, NOTE) VALUES
(15,'AUTH_FUNC_CommentManager.updateComment','FUNCTION','com.semovy.service.ICommentService.updateComment','淇敼璇勮',NULL);
INSERT INTO authority (AUTH_ID, AUTHORITY, AUTH_TYPE, PROTECTED_RES, DISPLAY, NOTE) VALUES
(16,'AUTH_FUNC_CommentManager.deleteCommentById','FUNCTION','com.semovy.service.ICommentService.deleteCommentById','鍒犻櫎涓鏉¤瘎璁?,NULL);
INSERT INTO authority (AUTH_ID, AUTHORITY, AUTH_TYPE, PROTECTED_RES, DISPLAY, NOTE) VALUES
(17,'AUTH_FUNC_CommentManager.outPutXMLComment','FUNCTION','com.semovy.service.ICommentService.outPutXMLComment','璁塊棶璇勮綆$悊',NULL);
--欏圭洰鍩烘湰鏂囨湰綆$悊
INSERT INTO authority (AUTH_ID, AUTHORITY, AUTH_TYPE, PROTECTED_RES, DISPLAY, NOTE) VALUES
(18,'AUTH_FUNC_BasicinfotextManager.getBasicinfotextById','FUNCTION','com.semovy.service.IBasicinfotextService.getBasicinfotextById','鑾峰彇涓涓」鐩熀鏈枃鏈睘鎬?,NULL);
INSERT INTO authority (AUTH_ID, AUTHORITY, AUTH_TYPE, PROTECTED_RES, DISPLAY, NOTE) VALUES
(19,'AUTH_FUNC_BasicinfotextManager.saveBasicinfotext','FUNCTION','com.semovy.service.IBasicinfotextService.saveBasicinfotext','淇濆瓨欏圭洰鍩烘湰鏂囨湰灞炴?,NULL);
INSERT INTO authority (AUTH_ID, AUTHORITY, AUTH_TYPE, PROTECTED_RES, DISPLAY, NOTE) VALUES
(20,'AUTH_FUNC_BasicinfotextManager.deleteBasicinfotextById','FUNCTION','com.semovy.service.IBasicinfotextService.deleteBasicinfotextById','鍒犻櫎欏圭洰鍩烘湰鏂囨湰灞炴?,NULL);
INSERT INTO authority (AUTH_ID, AUTHORITY, AUTH_TYPE, PROTECTED_RES, DISPLAY, NOTE) VALUES
--(21,'AUTH_FUNC_BasicinfotextManager.outPutLocaleUnitXML','FUNCTION','com.semovy.service.IBasicinfotextService.outPutLocaleUnitXML','璁塊棶鍩烘湰鏂囨湰灞炴у崟浣?,NULL),
(22,'AUTH_FUNC_BasicinfotextManager.outPutBasicinfotextXMLOfItem','FUNCTION','com.semovy.service.IBasicinfotextService.outPutBasicinfotextXMLOfItem','璁塊棶鍩烘湰鏂囨湰灞炴х鐞?,NULL);
--欏圭洰鍩烘湰鍥劇墖綆$悊
INSERT INTO authority (AUTH_ID, AUTHORITY, AUTH_TYPE, PROTECTED_RES, DISPLAY, NOTE) VALUES
(23,'AUTH_FUNC_BasicinfoimgManager.getBasicinfoimgById','FUNCTION','com.semovy.service.IBasicinfoimgService.getBasicinfoimgById','鑾峰彇涓涓」鐩熀鏈浘鐗囧睘鎬?,NULL);
INSERT INTO authority (AUTH_ID, AUTHORITY, AUTH_TYPE, PROTECTED_RES, DISPLAY, NOTE) VALUES
(24,'AUTH_FUNC_BasicinfoimgManager.saveBasicinfoimg','FUNCTION','com.semovy.service.IBasicinfoimgService.saveBasicinfoimg','淇濆瓨欏圭洰鍩烘湰鍥劇墖灞炴?,NULL);
INSERT INTO authority (AUTH_ID, AUTHORITY, AUTH_TYPE, PROTECTED_RES, DISPLAY, NOTE) VALUES
(25,'AUTH_FUNC_BasicinfoimgManager.updateBasicinfoimg','FUNCTION','com.semovy.service.IBasicinfoimgService.updateBasicinfoimg','淇敼欏圭洰鍩烘湰鍥劇墖灞炴?,NULL);
INSERT INTO authority (AUTH_ID, AUTHORITY, AUTH_TYPE, PROTECTED_RES, DISPLAY, NOTE) VALUES
(26,'AUTH_FUNC_BasicinfoimgManager.deleteBasicinfoimgById','FUNCTION','com.semovy.service.IBasicinfoimgService.deleteBasicinfoimgById','鍒犻櫎鍩烘湰鍥劇墖灞炴?,NULL);
INSERT INTO authority (AUTH_ID, AUTHORITY, AUTH_TYPE, PROTECTED_RES, DISPLAY, NOTE) VALUES
(27,'AUTH_FUNC_BasicinfoimgManager.outputBasicinfoimgXML','FUNCTION','com.semovy.service.IBasicinfoimgService.outputBasicinfoimgXML','璁塊棶鍩烘湰鍥劇墖灞炴х鐞?,NULL);
--欏圭洰鍩烘湰鏂囨。綆$悊
--(28,'AUTH_FUNC_BasicinfodocManager.getBasicinfodocById','FUNCTION','com.semovy.service.IBasicinfodocService.getBasicinfodocById','鑾峰彇涓涓」鐩熀鏈枃妗e睘鎬?,NULL),
INSERT INTO authority (AUTH_ID, AUTHORITY, AUTH_TYPE, PROTECTED_RES, DISPLAY, NOTE) VALUES
(29,'AUTH_FUNC_BasicinfodocManager.saveBasicinfodoc','FUNCTION','com.semovy.service.IBasicinfodocService.saveBasicinfodoc','淇濆瓨欏圭洰鍩烘湰鏂囨。灞炴?,NULL);
INSERT INTO authority (AUTH_ID, AUTHORITY, AUTH_TYPE, PROTECTED_RES, DISPLAY, NOTE) VALUES
(30,'AUTH_FUNC_BasicinfodocManager.updateBasicinfodoc','FUNCTION','com.semovy.service.IBasicinfodocService.updateBasicinfodoc','淇敼欏圭洰鍩烘湰鏂囨。灞炴?,NULL);
INSERT INTO authority (AUTH_ID, AUTHORITY, AUTH_TYPE, PROTECTED_RES, DISPLAY, NOTE) VALUES
(31,'AUTH_FUNC_BasicinfodocManager.deleteBasicinfodocById','FUNCTION','com.semovy.service.IBasicinfodocService.deleteBasicinfodocById','鍒犻櫎鍩烘湰鏂囨。灞炴?,NULL);
INSERT INTO authority (AUTH_ID, AUTHORITY, AUTH_TYPE, PROTECTED_RES, DISPLAY, NOTE) VALUES
(32,'AUTH_FUNC_BasicinfodocManager.outputBasicinfodocXML','FUNCTION','com.semovy.service.IBasicinfodocService.outputBasicinfodocXML','璁塊棶鍩烘湰鍥劇墖鏂囨。綆$悊',NULL);
--欏圭洰楂樼駭鏂囨湰綆$悊
INSERT INTO authority (AUTH_ID, AUTHORITY, AUTH_TYPE, PROTECTED_RES, DISPLAY, NOTE) VALUES
(33,'AUTH_FUNC_AdvancedinfoManager.getAdvancedinfoById','FUNCTION','com.semovy.service.IAdvancedinfoService.getAdvancedinfoById','鑾峰彇涓涓」鐩珮綰ф枃鏈睘鎬?,NULL);
INSERT INTO authority (AUTH_ID, AUTHORITY, AUTH_TYPE, PROTECTED_RES, DISPLAY, NOTE) VALUES
(34,'AUTH_FUNC_AdvancedinfoManager.saveAdvancedinfo','FUNCTION','com.semovy.service.IAdvancedinfoService.saveAdvancedinfo','淇濆瓨欏圭洰欏圭洰楂樼駭鏂囨湰',NULL);
INSERT INTO authority (AUTH_ID, AUTHORITY, AUTH_TYPE, PROTECTED_RES, DISPLAY, NOTE) VALUES
(35,'AUTH_FUNC_AdvancedinfoManager.updateAdvancedinfo','FUNCTION','com.semovy.service.IAdvancedinfoService.updateAdvancedinfo','淇敼欏圭洰欏圭洰楂樼駭鏂囨湰',NULL);
INSERT INTO authority (AUTH_ID, AUTHORITY, AUTH_TYPE, PROTECTED_RES, DISPLAY, NOTE) VALUES
(36,'AUTH_FUNC_AdvancedinfoManager.deleteAdvancedinfoById','FUNCTION','com.semovy.service.IAdvancedinfoService.deleteAdvancedinfoById','鍒犻櫎欏圭洰楂樼駭鏂囨湰',NULL);
--欏圭洰綾誨埆綆$悊
INSERT INTO authority (AUTH_ID, AUTHORITY, AUTH_TYPE, PROTECTED_RES, DISPLAY, NOTE) VALUES
(37,'AUTH_FUNC_CategoryManager.saveCategory','FUNCTION','com.semovy.service.ICategoryService.saveCategory','淇濆瓨欏圭洰綾誨埆',NULL);
INSERT INTO authority (AUTH_ID, AUTHORITY, AUTH_TYPE, PROTECTED_RES, DISPLAY, NOTE) VALUES
(38,'AUTH_FUNC_CategoryManager.updateCategory','FUNCTION','com.semovy.service.ICategoryService.updateCategory','淇敼欏圭洰綾誨埆',NULL);
INSERT INTO authority (AUTH_ID, AUTHORITY, AUTH_TYPE, PROTECTED_RES, DISPLAY, NOTE) VALUES
(39,'AUTH_FUNC_CategoryManager.deleteCategoryById','FUNCTION','com.semovy.service.ICategoryService.deleteCategoryById','鍒犻櫎欏圭洰綾誨埆',NULL);
INSERT INTO authority (AUTH_ID, AUTHORITY, AUTH_TYPE, PROTECTED_RES, DISPLAY, NOTE) VALUES
(40,'AUTH_FUNC_CategoryManager.outputCategoriesXML','FUNCTION','com.semovy.service.ICategoryService.outputCategoriesXML','璁塊棶綆$悊欏圭洰綾誨埆',NULL);
--鍒濆鍖杣ser_auth琛?br />
insert into user_auth values (1,1);
insert into user_auth values (1,2);
insert into user_auth values (1,3);
insert into user_auth values (1,4);
insert into user_auth values (1,5);
insert into user_auth values (1,6);
insert into user_auth values (1,7);
insert into user_auth values (1,8);
insert into user_auth values (1,9);
insert into user_auth values (1,10);
insert into user_auth values (1,11);
insert into user_auth values (1,12);
insert into user_auth values (1,13);
insert into user_auth values (1,14);
insert into user_auth values (1,15);
insert into user_auth values (1,16);
insert into user_auth values (1,17);
insert into user_auth values (1,18);
insert into user_auth values (1,19);
insert into user_auth values (1,20);
insert into user_auth values (1,21);
insert into user_auth values (1,22);
insert into user_auth values (1,23);
insert into user_auth values (1,24);
insert into user_auth values (1,25);
insert into user_auth values (1,26);
insert into user_auth values (1,27);
insert into user_auth values (1,28);
insert into user_auth values (1,29);
insert into user_auth values (1,30);
insert into user_auth values (1,31);
insert into user_auth values (1,32);
insert into user_auth values (1,33);
insert into user_auth values (1,34);
insert into user_auth values (1,35);
insert into user_auth values (1,36);
insert into user_auth values (1,37);
insert into user_auth values (1,38);
insert into user_auth values (1,39);
insert into user_auth values (1,40);
3. sql 鍛戒護(hù)
3.1. sql 鏀寔
select top 1 * from test;
select limit 0 2 * from test;
DROP TABLE test IF EXISTS;
3.2. Constraints and Indexes
涓誨仴綰︽潫錛歅RIMARY KEY
鍞竴綰︽潫錛?br />
鍞竴绱㈠紩錛?br />
澶栧仴錛?br />
CREATE TABLE child(c1 INTEGER, c2 VARCHAR, FOREIGN KEY (c1, c2) REFERENCES parent(p1, p2));
3.3. 绱㈠紩鍜屾煡璇㈤熷害
绱㈠紩鎻愰珮鏌ヨ閫熷害錛屾瘮鎻愰珮鎺掑簭閫熷害銆?br />
涓誨仴鍜屽敮涓鎵鍒楄嚜鍔ㄥ垱寤虹儲寮曪紝鍚﹀垯闇瑕佽嚜宸卞垱寤篊REATE INDEX command銆?br />
绱㈠紩錛?鍞竴绱㈠紩鍜岄潪鍞竴绱㈠紩
澶氬垪鐨勭儲寮曪紝濡傛灉鍙槸浣跨敤鍚庨潰鐨勶紝涓嶄嬌鐢ㄧ涓涓紝灝嗕笉浼?xì)鏉℃煡璇㈤熷害銆?br />
(TB is a very large table with only a few rows where TB.COL3 = 4)
SELECT * FROM TA JOIN TB ON TA.COL1 = TB.COL2 AND TB.COL3 = 4;
SELECT * FROM TB JOIN TA ON TA.COL1 = TB.COL2 AND TB.COL3 = 4;(faster)
鍘熷洜鏄?TB.COL3 鍙互琚揩閫熺殑浼拌,濡傛灉TB 琛ㄦ斁鍒板墠闈?index on TB.COL3):
涓鑸鍒欐槸鎶婄緝?yōu)畯鏉′欢鐨勫垪鐨勮〃鏀惧湪鍓嶉?br />
3.4. 浣跨敤where 榪樻槸join
浣跨敤 WHERE 鏉′歡閾炬帴琛ㄥ彲鑳戒細(xì)闄嶄綆榪愯閫熷害.
涓嬮潰鐨勪緥瀛愬皢浼?xì)姣旇緝鎱?鍗充嬌浣跨敤浜嗙儲寮?
SELECT ... FROM TA, TB, TC WHERE TC.COL3 = TA.COL1 AND TC.COL3=TB.COL2 AND TC.COL4 = 1
榪欎釜鏌ヨ闅愬惈TA.COL1 = TB.COL2 ,浣嗘槸娌℃湁鐩存帴璁懼畾榪欎釜鏉′歡.濡傛灉 TA 鍜?TB 姣忎釜琛ㄩ兘鍖呭惈100 鏉¤褰?10000 緇勫悎灝嗗拰 TC 鍏寵仈,鐢ㄤ簬TC榪欎釜鍒楃殑鏉′歡,灝界鏈夌儲寮曞湪榪欎釜鍒椾笂.浣跨敤JOIN 鍏抽敭瀛? 鍦ㄧ粍鍚圱C 涔嬪墠,TA.COL1 = TB.COL2 鏉′歡鐩存帴騫剁緝?yōu)畯缁勫?TA 鍜?TB 鐨勮鏁? 鍦ㄨ繍琛屽ぇ鏁版嵁閲忕殑琛ㄧ殑緇撴灉鏄?灝嗕細(xì)寰堝揩:
SELECT ... FROM TA JOIN TB ON TA.COL1 = TB.COL2 JOIN TC ON TB.COL2 = TC.COL3 WHERE TC.COL4 = 1
榪欎釜鏌ヨ鍙互鎻愰珮涓澶ф,濡傛灉鏀瑰彉琛ㄧ殑欏哄簭, 鎵浠?TC.COL1 = 1 灝嗘渶鍏堜嬌鐢?榪欐牱鏇村皬鐨勯泦鍚堝皢緇勫悎鍦ㄤ竴璧?
SELECT ... FROM TC JOIN TB ON TC.COL3 = TB.COL2 JOIN TA ON TC.COL3 = TA.COL1 WHERE TC.COL4 = 1
浠ヤ笂渚嬪瓙,鏁版嵁寮曟搸鑷姩搴旂敤浜嶵C.COL4 = 1 緇勫悎灝忕殑闆嗗悎浜庡叾瀹冭〃鍏寵仈. Indexes TC.COL4, TB.COL2 TA.COL1 閮藉皢浣跨敤绱㈠紩,鎻愰珮鏌ヨ閫熷害.
3.5. Subqueries and Joins
浣跨敤join 鍜岃皟鏁磋〃鐨勯『搴忔彁楂樻晥鐜?
渚嬪:, 絎簩涓煡璇㈢殑閫熷害灝嗘洿蹇竴浜?TA.COL1 鍜孴B.COL3閮芥湁绱㈠紩):
Example 2.2. Query comparison
SELECT ... FROM TA WHERE TA.COL1 = (SELECT MAX(TB.COL2) FROM TB WHERE TB.COL3 = 4)
SELECT ... FROM (SELECT MAX(TB.COL2) C1 FROM TB WHERE TB.COL3 = 4) T2 JOIN TA ON TA.COL1 = T2.C1
絎簩涓煡璇㈠皢 MAX(TB.COL2) 涓庝竴涓崟璁板綍琛ㄧ浉鍏寵仈. 騫朵嬌鐢═A.COL1绱㈠紩,榪欏皢鍙樺緱闈炲父蹇? 絎竴涓煡璇㈡槸灝?TA 琛ㄤ腑鐨勬瘡涓鏉¤褰曚笉鏂湴涓嶮AX(TB.COL2)鍖歸厤.
3.6. 鏁版嵁綾誨瀷
TINYINT, SMALLINT, INTEGER, BIGINT, NUMERIC and DECIMAL (without a decimal point) are supported integral types and map to byte, short, int, long and BigDecimal in Java.
Integral Types:
TINYINT, SMALLINT, INTEGER, BIGINT, NUMERIC and DECIMAL
Other Numeric Types:
REAL, FLOAT or DOUBLE
Bit and Boolean Types:
BOOLEAN: UNDEFINED,TRUE,FALSE
NULL values are treated as undefined.
Storage and Handling of Java Objects
Sequences and Identity
Identity Auto-Increment Columns:
The next IDENTITY value to be used can be set with the
ALTER TABLE ALTER COLUMN RESTART WITH ;
Sequences:
SELECT NEXT VALUE FOR mysequence, col1, col2 FROM mytable WHERE ...
3.7. 浜嬪姟闂:
SET PROPERTY "sql.tx_no_multi_rewrite" TRUE
4. Connections
閫氱敤椹卞姩jdbc:hsqldb: 涓嬪垪鍗忚鏍囪瘑(mem: file: res: hsql: http: hsqls: https:)
Table 4.1. Hsqldb URL Components
Driver and Protocol Host and Port Database
jdbc:hsqldb:mem:
not available accounts
jdbc:hsqldb:mem:.
jdbc:hsqldb:file:
not available mydb
/opt/db/accounts
C:/data/mydb
鏁版嵁搴撹礬寰?
jdbc:hsqldb:res:
not available /adirectory/dbname
jars files are accessed in Java programs. The /adirectory above stands for a directory in one of the jars.
jdbc:hsqldb:hsql:
jdbc:hsqldb:hsqls:
jdbc:hsqldb:http:
jdbc:hsqldb:https:
//localhost
//192.0.0.10:9500
//dbserver.somedomain.com
/an_alias
/enrollments
/quickdb
鍒悕鍦╯erver.properties or webserver.properties鏂囦歡涓寚瀹?br />
database.0=file:/opt/db/accounts
dbname.0=an_alias
database.1=file:/opt/db/mydb
dbname.1=enrollments
database.2=mem:adatabase
dbname.2=quickdb
In the example below, the database files lists.* in the /home/dbmaster/ directory are associated with the empty alias:
database.3=/home/dbmaster/lists
dbname.3=
4.1.Connection properties
Connection properties are specified either by establishing the connection via the:
DriverManager.getConnection (String url, Properties info);
method call, or the property can be appended to the full Connection URL.
Table 4.2. Connection Properties
get_column_name true column name in ResultSet
This property is used for compatibility with other JDBC driver implementations. When true (the default), ResultSet.getColumnName(int c) returns the underlying column name
When false, the above method returns the same value as ResultSet.getColumnLabel(int column) Example below:
jdbc:hsqldb:hsql://localhost/enrollments;get_column_name=false
When a ResultSet is used inside a user-defined stored procedure, the default, true, is always used for this property.
ifexists false connect only if database already exists
Has an effect only with mem: and file: database. When true, will not create a new database if one does not already exist for the URL.
When false (the default), a new mem: or file: database will be created if it does not exist.
Setting the property to true is useful when troubleshooting as no database is created if the URL is malformed. Example below:
jdbc:hsqldb:file:enrollments;ifexists=true
shutdown false shut down the database when the last connection is closed
This mimics the behaviour of 1.7.1 and older versions. When the last connection to a database is closed, the database is automatically shut down. The property takes effect only when the first connection is made to the database. This means the connection that opens the database. It has no effect if used with subsequent, simultaneous connections.
This command has two uses. One is for test suites, where connections to the database are made from one JVM context, immediately followed by another context. The other use is for applications where it is not easy to configure the environment to shutdown the database. Examples reported by users include web application servers, where the closing of the last connection conisides with the web app being shut down.
4.2. Properties Files
澶у皬鍐欐晱鎰?(e.g. server.silent=FALSE will have no effect, but server.silent=false will work).
灞炴ф枃浠跺拰璁懼畾瀛樺偍濡備笅 :
Table 4.3. Hsqldb Server Properties Files
File Name Location Function
server.properties the directory where the command to run the Server class is issued settings for running HSQLDB as a database server communicating with the HSQL protocol
webserver.properties the directory where the command to run the WebServer class is issued settings for running HSQLDB as a database server communicating with the HTTP protocol .properties the directory where all the files for a database are located settings for each particular database
Properties files for running the servers are not created automatically. You should create your own files that contain server.property=value pairs for each property.
4.2.1. Server and Web Server Properties
server.properties and webserver.properties 鏂囦歡鏀寔濡備笅璁懼畾:
Table 4.4. Property File Properties
Value Default Description
server.database.0 test the path and file name of the first database file to use
server.dbname.0 "" lowercase server alias for the first database file
server.urlid.0 NONE SqlTool urlid used by UNIX init script. (This property is not used if your are running Server/Webserver on a platform other than UNIX, or of you are not using our UNIX init script).
server.silent true no extensive messages displayed on console
server.trace false JDBC trace messages displayed on console
In 1.8.0, 姣忎釜鏈嶅姟鍣ㄦ敮鎸佸悓鏃跺惎鍔?0涓笉鍚岀殑鏁版嵁搴? The server.database.0 property defines the filename / path whereas the server.dbname.0 defines the lowercase alias used by clients to connect to that database. The digit 0 is incremented for the second database and so on. Values for the server.database.{0-9} property can use the mem:, file: or res: prefixes and properties as discussed above under CONNECTIONS. For example,
database.0=mem:temp;sql.enforce_strict_size=true;
Values specific to server.properties are:
Table 4.5. Server Property File Properties
Value Default Description
server.port 9001 TCP/IP port used for talking to clients. All databases are served on the same port.
server.no_system_exit true no System.exit() call when the database is closed
Values specific to webserver.properties are:
Table 4.6. WebServer Property File Properties
Value Default Description
server.port 80 TCP/IP port used for talking to clients
server.default_page index.html the default web page for server
server.root ./ the location of served pages
. ? multiple entries such as .html=text/html define the mime types of the static files served by the web server. See the source for WebServer.java for a list.
All the above values can be specified on the command line to start the server by omitting the server. prefix.
5. SqlTool
Mem 鏁版嵁搴?
E:\hsqldb>java -jar ./lib/hsqldb.jar mem
Hsql Server:
(鍓嶆彁鏄痻db server 宸茬粡鍚姩):
(java -cp ../lib/hsqldb.jar org.hsqldb.Server -database.0 file:mydb -dbname.0 xdb)
java -jar ./hsqldb.jar xdb
鎵цsql 璇彞:
1)
Mydb.sql :
CREATE MEMORY TABLE TEST(ID INTEGER,NAME VARCHAR(20));
INSERT INTO TEST VALUES(1,'aaa');
INSERT INTO TEST VALUES(2,'bbb');
E:\hsqldb>java -jar ./lib/hsqldb.jar mem mydb.sql
1 row updated
1 row updated
2)
testuser.sql:
CREATE MEMORY TABLE userTEST(ID INTEGER,NAME VARCHAR(20));
INSERT INTO userTEST VALUES(1,'aaa');
INSERT INTO userTEST VALUES(2,'bbb');
commit; //榪欐牱鎵嶈兘鎻愪氦鍒版暟鎹簱
E:\hsqldb>java -jar ./hsqldb.jar xdb testuser.sql > file.txt 2>&1
杈撳嚭緇撴灉鍒癴ile.txt 鏂囦歡涓?
6.1.1. ALTER INDEX[1]
ALTER INDEX RENAME TO ;
6.1.2. ALTER SEQUENCE[1]
ALTER SEQUENCE RESTART WITH ;
6.1.3. ALTER SCHEMA[1]
ALTER SCHEMA RENAME TO ;
6.1.4. ALTER TABLE[1]
ALTER TABLE
ADD [COLUMN] Datatype
[(columnSize[,precision])] [{DEFAULT |
GENERATED BY DEFAULT AS IDENTITY (START WITH [, INCREMENT BY ])}] |
[[NOT] NULL] [IDENTITY] [PRIMARY KEY]
[BEFORE ];
ALTER TABLE
DROP [COLUMN] ;
ALTER TABLE
ALTER COLUMN RENAME TO
ALTER TABLE
ALTER COLUMN SET DEFAULT };
ALTER TABLE
ALTER COLUMN SET [NOT] NULL
ALTER TABLE
ALTER COLUMN ;
ALTER TABLE
ALTER COLUMN
RESTART WITH
ALTER TABLE
ADD [CONSTRAINT ]
CHECK ();
ALTER TABLE
ADD [CONSTRAINT ] UNIQUE ();
ALTER TABLE
ADD [CONSTRAINT ]
PRIMARY KEY ();
ALTER TABLE
ADD [CONSTRAINT ] FOREIGN KEY ()
REFERENCES ()
[ON {DELETE | UPDATE} {CASCADE | SET DEFAULT | SET NULL}];
ALTER TABLE
DROP CONSTRAINT ;
ALTER TABLE
RENAME TO ;
6.1.5. ALTER USER[1]
ALTER USER SET PASSWORD
;
ALTER USER SET INITIAL SCHEMA ;
6.1.6. CALL
CALL Expression;
See also: Stored Procedures / Functions, SQL Expression.
6.1.7. CHECKPOINT
CHECKPOINT [DEFRAG[1]];
See also: SHUTDOWN, SET LOGSIZE.
6.1.8. COMMIT
COMMIT [WORK];
See also: ROLLBACK, SET AUTOCOMMIT, SET LOGSIZE.
6.1.9. CONNECT
CONNECT USER PASSWORD
;
See also: GRANT, REVOKE.
6.1.10. CREATE ALIAS
CREATE ALIAS FOR ;
See also: CALL, Stored Procedures / Functions.
6.1.11. CREATE INDEX
CREATE [UNIQUE] INDEX ON ( [DESC] [, ...]) [DESC];
6.1.12. CREATE ROLE[1]
CREATE ROLE ;
6.1.13. CREATE SCHEMA[1]
CREATE SCHEMA AUTHORIZATION
[ [] [...];
CREATE SCHEMA ACCOUNTS AUTHORIZATION DBA
CREATE TABLE AB(A INTEGER, ...)
CREATE TABLE CD(C CHAHR, ...)
CREATE VIEW VI AS SELECT ...
GRANT SELECT TO PUBLIC ON AB
GRANT SELECT TO JOE ON CD;
6.1.14. CREATE SEQUENCE[1]
CREATE SEQUENCE [AS {INTEGER | BIGINT}]
[START WITH ] [INCREMENT BY ];
SELECT [...,] NEXT VALUE FOR [, ...] FROM
;
6.1.15. CREATE TABLE
CREATE [MEMORY | CACHED | [GLOBAL] TEMPORARY | TEMP [1] | TEXT[1]] TABLE
( [, ...] [, ...] )
[ON COMMIT {DELETE | PRESERVE} ROWS];
6.1.16. CREATE TRIGGER[1]
CREATE TRIGGER {BEFORE | AFTER} {INSERT | UPDATE | DELETE} ON
[FOR EACH ROW] [QUEUE n] [NOWAIT] CALL
;
6.1.17. CREATE USER
CREATE USER PASSWORD
[ADMIN];
6.1.18. CREATE VIEW[1]
CREATE VIEW [(,..) AS SELECT ... FROM ... [WHERE Expression]
[ORDER BY orderExpression [, ...]]
[LIMIT
[OFFSET ]];
CREATE VIEW mealsjv AS
SELECT m.mid mid, m.name name, t.mealtype mt, a.aid aid,
a.gname + ' ' + a.sname author, m.description description,
m.asof asof
FROM meals m, mealtypes t, authors a
WHERE m.mealtype = t.mealtype
AND m.aid = a.aid;
CREATE VIEW mealswebv AS SELECT name, author FROM mealsjv;
CREATE VIEW aview (new_name, new_author) AS
SELECT name, author
FROM mealsjv
6.1.19. DELETE
DELETE FROM table [WHERE Expression];
6.1.20. DISCONNECT
DISCONNECT;
6.1.21. DROP INDEX
DROP INDEX index [IF EXISTS];
6.1.22. DROP ROLE[1]
DROP ROLE ;
6.1.23. DROP SEQUENCE[1]
DROP SEQUENCE [IF EXISTS] [RESTRICT | CASCADE];
6.1.24. DROP SCHEMA[1]
DROP SCHEMA [RESTRICT | CASCADE];
6.1.25. DROP TABLE
DROP TABLE [IF EXISTS] [RESTRICT | CASCADE];
6.1.26. DROP TRIGGER
DROP TRIGGER
;
6.1.27. DROP USER
DROP USER ;
6.1.28. DROP VIEW[1]
DROP VIEW [IF EXISTS] [RESTRICT | CASCADE];
6.1.29. EXPLAIN PLAN
EXPLAIN PLAN FOR { SELECT ... | DELETE ... | INSERT ... | UPDATE ..};
6.1.30. GRANT
GRANT { SELECT | DELETE | INSERT | UPDATE | ALL } [,...]
ON { table | CLASS "package.class" } TO ;
GRANT [,...] TO [1];
GRANT SELECT ON Test TO GUEST;
GRANT ALL ON CLASS "java.lang.Math.abs" TO PUBLIC;
6.1.31. INSERT
INSERT INTO table [( column [,...] )]
{ VALUES(Expression [,...]) | SelectStatement};
6.1.32. REVOKE
REVOKE { SELECT | DELETE | INSERT | UPDATE | ALL } [,...]
ON { table | CLASS "package.class" } FROM ;
REVOKE [,...] FROM [1];
6.1.33. ROLLBACK
ROLLBACK [TO SAVEPOINT [1] | WORK}];
6.1.34. SAVEPOINT[1]
SAVEPOINT ;
6.1.35. SCRIPT
SCRIPT ['file'];
6.1.36. SELECT[1]
SELECT [{LIMIT
| TOP
}[1]][ALL | DISTINCT]
{ selectExpression | table.* | * } [, ...]
[INTO [CACHED | TEMP | TEXT][1] newTable]
FROM tableList
[WHERE Expression]
[GROUP BY Expression [, ...]]
[HAVING Expression]
[{ UNION [ALL | DISTINCT] | {MINUS [DISTINCT] | EXCEPT [DISTINCT] } |
INTERSECT [DISTINCT] } selectStatement]
[ORDER BY orderExpression [, ...]]
[LIMIT
[OFFSET ]];
tableList
table [{CROSS | INNER | LEFT OUTER | RIGHT OUTER}
JOIN table ON Expression] [, ...]
table
{ (selectStatement) [AS] label | tableName}
selectExpression
{ Expression | COUNT(*) | {
COUNT | MIN | MAX | SUM | AVG | SOME | EVERY |
VAR_POP | VAR_SAMP | STDDEV_POP | STDDEV_SAMP
} ([ALL | DISTINCT][1]] Expression) } [[AS] label]
If CROSS JOIN is specified no ON expression is allowed for the join.
orderExpression
{ columnNr | columnAlias | selectExpression }
[ASC | DESC]
LIMIT n m
LIMIT n m
LIMIT m OFFSET n
TOP m
UNION and other set operations
6.1.37. SET AUTOCOMMIT
SET AUTOCOMMIT { TRUE | FALSE };
6.1.38. SET DATABASE COLLATION[1]
SET DATABASE COLLATION ;
6.1.39. SET CHECKPOINT DEFRAG[1]
SET CHECKPOINT DEFRAG ;
6.1.40. SET IGNORECASE
SET IGNORECASE { TRUE | FALSE };
6.1.41. SET INITIAL SCHEMA [1]
Users may change their base default schema name with the comand
SET INITIAL SCHEMA ;
6.1.42. SET LOGSIZE
SET LOGSIZE ;
6.1.43. SET PASSWORD
SET PASSWORD
;
6.1.44. SET PROPERTY[1]
SET PROPERTY ;
6.1.45. SET REFERENTIAL INTEGRITY
SET REFERENTIAL_INTEGRITY { TRUE | FALSE };
6.1.46. SET SCHEMA[1]
SET SCHEMA ;
6.1.47. SET SCRIPTFORMAT[1]
SET SCRIPTFORMAT {TEXT | BINARY | COMPRESSED};
6.1.48. SET TABLE INDEX
SET TABLE tableName INDEX 'index1rootPos index2rootPos ... ';
6.1.49. SET TABLE READONLY[1]
SET TABLE
READONLY {TRUE | FALSE};
6.1.50. SET TABLE SOURCE[1]
SET TABLE
SOURCE [DESC];
SET TABLE mytable SOURCE "myfile;fs=|;vs=.;lvs=~"
Supported Properties
quoted = { true | false }
default is true. If false, treats double quotes as normal characters
all_quoted = { true | false }
default is false. If true, adds double quotes around all fields.
encoding =
character encoding for text and character fields, for example, encoding=UTF-8
ignore_first = { true | false }
default is false. If true ignores the first line of the file
cache_scale=
exponent to calculate rows of the text file in cache. Default is 8, equivalent to nearly 800 rows
cache_size_scale = r
exponent to calculate average size of each row in cache. Default is 8, equivalent to 256 bytes per row.
fs =
field separator
vs =
varchar separator
lvs =
long varchar separator
Special indicators for Hsqldb Text Table separators
\semi
semicolon
\quote
quote
\space
space character
\apos
apostrophe
\n
newline - Used as an end anchor (like $ in regular expressions)
\r
carriage return
\t
tab
\\
backslash
\u####
a Unicode character specified in hexadecimal
Only an administrator may do this.
6.1.51. SET WRITE DELAY[1]
SET WRITE_DELAY {{ TRUE | FALSE } | | MILLIS};
6.1.52. SHUTDOWN
SHUTDOWN [IMMEDIATELY | COMPACT | SCRIPT[1]];
6.2. Data Types
Table 9.1. Data Types. The types on the same line are equivalent.
Name Range Java Type
INTEGER | INT as Java type int | java.lang.Integer
DOUBLE [PRECISION] | FLOAT as Java type double | java.lang.Double
VARCHAR as Integer.MAXVALUE java.lang.String
VARCHAR_IGNORECASE as Integer.MAXVALUE java.lang.String
CHAR | CHARACTER as Integer.MAXVALUE java.lang.String
LONGVARCHAR as Integer.MAXVALUE java.lang.String
DATE as Java type java.sql.Date
TIME as Java type java.sql.Time
TIMESTAMP | DATETIME as Java type java.sql.Timestamp
DECIMAL No limit java.math.BigDecimal
NUMERIC No limit java.math.BigDecimal
BOOLEAN | BIT as Java type boolean | java.lang.Boolean
TINYINT as Java type byte | java.lang.Byte
SMALLINT as Java type short | java.lang.Short
BIGINT as Java type long | java.lang.Long
REAL as Java type double | java.lang.Double[1]
BINARY as Integer.MAXVALUE byte[]
VARBINARY as Integer.MAXVALUE byte[]
LONGVARBINARY as Integer.MAXVALUE byte[]
OTHER | OBJECT as Integer.MAXVALUE java.lang.Object
The uppercase names are the data types names defined by the SQL standard or commonly used by RDMS's. The data types in quotes are the Ja
6.2.1. 鑷姩澧為暱:
create table user(id IDENTITY,name varchar(20));
sql> create table dept(id int GENERATED BY DEFAULT AS IDENTITY(start with 10,increment by 5) not null PRIMARY KEY,name v
archar(20));
sql> insert into dept(name) values('asc');
1 row updated
sql> insert into dept(name) values('security');
1 row updated
sql> select * from dept;
ID NAME
-- --------
10 asc
15 security
2 rows
6.3. SQL Comments
-- SQL style line comment
// Java style line comment
/* C style line comment */
7. Hsqldb Test Utility
鎷瘋礉 junit.jar 鍒?lib 鐩綍涓?br />
榪愯: ant hsqldbtest
鐢熸垚 hsqldbtest.jar
榪愯: \hsqldb\testrun\hsqldb>runtest TestSelf