Learn Java for Web Development

(Tina Meador) #1

22 CHAPTER 1: Introducing Java Web Development


CREATE TABLE BOOK (
ID INT NOT NULL AUTO_INCREMENT,
CATEGORY_ID INT NOT NULL ,
BOOK_TITLE VARCHAR(60) NOT NULL,
PUBLISHER VARCHAR(60) NOT NULL ,
PRIMARY KEY (ID) ,
CONSTRAINT FK_BOOK_1 FOREIGN KEY (CATEGORY_ID) REFERENCES CATEGORY(ID)


);


CREATE TABLE AUTHOR (
ID INT NOT NULL AUTO_INCREMENT ,
BOOK_ID INT NOT NULL ,
FIRST_NAME VARCHAR(20) NOT NULL ,
LAST_NAME VARCHAR(20) NOT NULL ,
PRIMARY KEY (ID) ,
CONSTRAINT FK_AUTHOR_1 FOREIGN KEY (BOOK_ID) REFERENCES BOOK (ID)
);


You can verify the created tables using the show tables command, as illustrated in Figure 1-14.


Figure 1-14. All tables in the database


You can also check the structure of the tables using the command describe or
desc, as illustrated in Figure 1-15.

Free download pdf