Exercise 2. Create table ProductGroup by using graphical tool
CREATE TABLE - example CREATE TABLE Class ( ID INT AUTO_INCREMENT PRIMARY KEY, name VARCHAR(10) UNIQUE NOT NULL ) TYPE=INNODB; CREATE TABLE tablename ( field1 datatype additional attributes, field2 datatype additional attributes, ) TYPE=INNODB; Example: Syntax:
Creating tables with SQL SQL-statements are NOT case-sensitive in MySQL (e. g. CREATE == create) There are many different syntax for doing things in SQL Naming tables and fields also varies
CREATE TABLE – data types Numbers – TINYINT, SMALLINT, MEDIUMINT, INT, BIGINT, FLOAT, DOUBLE Dates and time – DATE, TIME, DATETIME, TIMESTAMP, YEAR Strings and character – VARCHAR, CHAR, TEXT, BLOB, ENUM Boolean – TINYINT (0=false, 1=true), with new MySQL version BOOL and BOOLEAN is also available
Creating relationships CREATE TABLE Student ( ID INT AUTO_INCREMENT PRIMARY KEY,... class_ID INT NOT NULL, INDEX idx_class_ID (class_ID), FOREIGN KEY (class_ID) REFERENCES Class(ID) ON DELETE RESTRICT )
Exercise 4. Create table product using SQL-statement so that relationship between tables productgroup and product is created
Exercise 5. Create rest of the database Demox (tables Order and OrderRow) When creating table Order use syntax demox.Order (databasename.table), because order is reserved word in SQL (and therefore plain order won’t work).
Exercise 6. Create new database called guestbook Create table message with fields: – MessageID (primary key) – Message (text) – User (varchar) – Saved (timestamp)