MySQL-class-4
MySQL-class-4
use db1;
3) MySQL Create Query
MySQL create query is used to create a table, view, procedure and
function. For example:
The constraint in MySQL is used to specify the rule that allows or restricts
what values/data will be stored in the table.
table that limits the type of data for the whole table.
CREATE TABLE new_table_name (
col_name1 datatype constraint,
col_name2 datatype constraint,
col_name3 datatype constraint,
.........
);
Constraints used in MySQL
The following are the most common constraints used in the
MySQL:
NOT NULL
CHECK
DEFAULT
PRIMARY KEY
AUTO_INCREMENT
UNIQUE
INDEX
ENUM
FOREIGN KEY
NOT NULL Constraint
This constraint specifies that the column cannot have NULL or empty
values. The below statement creates a table with NOT NULL constraint.
mysql> CREATE TABLE Student(Id INTEGER, LastName TEXT NOT NULL, Fi
rstName TEXT NOT NULL, City VARCHAR(35));
Execute the queries listed below to understand how it works:
mysql> INSERT INTO Student VALUES(1, 'Hanks', 'Peter', 'New York');