Sql sentencias creación de datos (DDL)

Crear tabla:

http://www.mysqltutorial.org/mysql-create-table/

http://www.mysqltutorial.org/mysql-foreign-key/

http://www.mysqltutorial.org/mysql-index/mysql-create-index/

 

CREATE TABLE [IF NOT EXISTS] table_name(
    column_list
) ENGINE=storage_engine

column_name data_type(length) [NOT NULL] [DEFAULT value] [AUTO_INCREMENT]

	
PRIMARY KEY (col1,col2,...)

INDEX `index_name` (`index_col`)


FOREIGN KEY foreign_key_name(columns)
REFERENCES parent_table(columns)
ON DELETE action
ON UPDATE action;

CREATE INDEX index_name
ON table_name (column1, column2, ...);

CREATE TABLE IF NOT EXISTS tasks (
    task_id INT AUTO_INCREMENT,
    employee_id INT NOT NULL,
    title VARCHAR(255) NOT NULL,
    start_date DATE,
    due_date DATE,
    status TINYINT NOT NULL,
    priority TINYINT NOT NULL,
    description TEXT,
    PRIMARY KEY (task_id),
    INDEX ix_title (title),
    FOREIGN KEY fk_employee(employee_id )
    REFERENCES employee (employee_id )
    ON DELETE RESTRICT
    ON UPDATE CASCADE
)  ENGINE=INNODB;