In the initial database, I would like to create four tables to store the shape data for the annotated characters.
A: tbl_image(id[int], category[string], width[int], height[int])
B: tbl_body(id[int], name[string])
C: tbl_record(id[int], userId[int], imageId[int], time[timestamp])
D: tbl_shape(recordId[int], bodyId[int], xPosition[float], yPosition[float], width[float], height[float], refWidth[float], refHeight[float], wTriangle[float], wRectangle[float], wInvertTriangle[float], wCircle[float], rotation[float])
E: tbl_user(id[int], name[string], password[string])
MySQL
Now() - return current date and time;
current_date - only current date;
current_time - only current time;
show databases - list all the databases
use databaseName - change the current database
show tables - list all the tables in the current database
describe table name - list the definition of the table
Database creation code:
1: drop database if exists db_character;
2:
3: create database db_character character set "utf8";
4:
5: use db_character;
6:
7: /* tbl_image creation */
8: /*the category of the image contains: 'cartoon', 'human', 'animal'. The file name is id+'.jpg' */
9: create table tbl_image(
10: id int unsigned auto_increment,
11: category varchar(20) not null,
12: width smallint unsigned not null,
13: height smallint unsigned not null,
14: primary key(id));
15:
16: insert into tbl_image(category, width, height)
17: values
18: ('cartoon',100,100),
19: ('human', 40,50),
20: ('human', 100, 100),
21: ('animal', 200,300),
22: ('cartoon',40,40);
23:
24: select * from tbl_image;
25: /* get the maximun id */
26: select max(id) from tbl_image;
27:
28:
29: /* tbl_body creation */
30: create table tbl_body(
31: id int unsigned auto_increment,
32: name varchar(50) not null,
33: primary key (id));
34:
35: insert into tbl_body(name)
36: values
37: ('upperSilhouette'),
38: ('lowerSilhouette'),
39: ('head'),
40: ('torso'),
41: ('pelvis'),
42: ('neck'),
43: ('leftUpperArm'),
44: ('rightUpperArm'),
45: ('leftLowerArm'),
46: ('rightLowerArm'),
47: ('leftUpperLeg'),
48: ('rightUpperLeg'),
49: ('leftLowerLeg'),
50: ('rightLowerLeg'),
51: ('leftHand'),
52: ('rightHand'),
53: ('leftFoot'),
54: ('rightFoot');
55:
56: select * from tbl_body;
57:
58: /* tbl_user creation */
59: create table tbl_user(
60: id int unsigned auto_increment,
61: name varchar(100) not null,
62: password varchar(100) not null,
63: primary key (id));
64:
65: insert into tbl_user(name,password)
66: values
67: ('anonymouse','123');
68:
69: select * from tbl_user;
70:
71: /* tbl_record creation */
72: create table tbl_record(
73: id int unsigned auto_increment,
74: userId int unsigned,
75: imageId int unsigned,
76: time timestamp not null default Now(),
77: primary key (id),
78: foreign key (userId) references tbl_user(id) on delete set null,
79: foreign key (imageId) references tbl_image(id) on delete set null);
80:
81: insert into tbl_record(userId,imageId)
82: select tbl_user.id,tbl_image.id from tbl_user,tbl_image
83: where tbl_user.name='anonymouse' and tbl_image.category='cartoon';
84:
85: insert into tbl_record(userId,imageId)
86: select tbl_user.id,2 from tbl_user
87: where tbl_user.name='anonymouse';
88:
89: select * from tbl_record;
90:
91: /* tbl_shape creation */
92: create table tbl_shape(
93: recordId int unsigned,
94: bodyId int unsigned,
95: xPosition float (10,2) unsigned not null,
96: yPosition float (10,2) unsigned not null,
97: width float (10,2) unsigned not null,
98: height float (10,2) unsigned not null,
99: refWidth float (10,2) unsigned,
100: refHeight float (10,2) unsigned,
101: wTriangle float (5,2) unsigned not null,
102: wRectangle float (5,2) unsigned not null,
103: wInvertTriangle float (5,2) unsigned not null,
104: wCircle float (5,2) unsigned not null,
105: rotation float (5,2) not null,
106: primary key (bodyId,recordId),
107: constraint foreign key (bodyId) references tbl_body(id),
108: constraint foreign key (recordId) references tbl_record(id));
109:
110:
111:
112:
113:
114:
115: