![]() ![]() The following statement creates a new table named tasks: CREATE TABLE IF NOT EXISTS tasks (Ĭreated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP Let’s take some examples of creating new tables. Each table has a maximum one AUTO_INCREMENT column.Īfter the column list, you can define table constraints such as UNIQUE, CHECK, PRIMARY KEY and FOREIGN KEY.įor example, if you want to set a column or a group of columns as the primary key, you use the following syntax: PRIMARY KEY (col1,col2.) Code language: SQL (Structured Query Language) ( sql ) MySQL CREATE TABLE statement examples The AUTO_INCREMENT indicates that the value of the column is incremented by one automatically whenever a new row is inserted into the table.The DEFAULT specifies a default value for the column.Besides the NOT NULL constraint, a column may have additional constraint such as CHECK, and UNIQUE. The NOT NULL constraint ensures that the column will not contain NULL. ![]() Each column has a specific data type and optional size e.g., VARCHAR(255)
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |