Tutorial by Examples

The CREATE TABLE statement is used to create a table in a MySQL database. CREATE TABLE Person ( `PersonID` INTEGER NOT NULL PRIMARY KEY, `LastName` VARCHAR(80), `FirstName` VARCHAR(80), `Address` TEXT, `City` VARCHAR(100) ) Engine=InnoDB; Ev...
CREATE TABLE Person ( PersonID INT UNSIGNED NOT NULL, LastName VARCHAR(66) NOT NULL, FirstName VARCHAR(66), Address VARCHAR(255), City VARCHAR(66), PRIMARY KEY (PersonID) ); A primary key is a NOT NULL single or a multi-column identifier whic...
CREATE TABLE Account ( AccountID INT UNSIGNED NOT NULL, AccountNo INT UNSIGNED NOT NULL, PersonID INT UNSIGNED, PRIMARY KEY (AccountID), FOREIGN KEY (PersonID) REFERENCES Person (PersonID) ) ENGINE=InnoDB; Foreign key: A Foreign Key (FK) is either a single col...
A table can be replicated as follows: CREATE TABLE ClonedPersons LIKE Persons; The new table will have exactly the same structure as the original table, including indexes and column attributes. As well as manually creating a table, it is also possible to create table by selecting data from anot...
You can create one table from another by adding a SELECT statement at the end of the CREATE TABLE statement: CREATE TABLE stack ( id_user INT, username VARCHAR(30), password VARCHAR(30) ); Create a table in the same database: -- create a table from another table in the same data...
If you want to see the schema information of your table, you can use one of the following: SHOW CREATE TABLE child; -- Option 1 CREATE TABLE `child` ( `id` int(11) NOT NULL AUTO_INCREMENT, `fullName` varchar(100) NOT NULL, `myParent` int(11) NOT NULL, PRIMARY KEY (`id`), KEY `momm...
The TIMESTAMP column will show when the row was last updated. CREATE TABLE `TestLastUpdate` ( `ID` INT NULL, `Name` VARCHAR(50) NULL, `Address` VARCHAR(50) NULL, `LastUpdate` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP ) COMMENT='Last Update' ;

Page 1 of 1