×
Clear all filters including search bar
Valeri Tandilashvili's Personal Professional Blog
AUTO_INCREMENT
featureCREATE TABLE note (
id int AUTO_INCREMENT,
note_id int AUTO_INCREMENT,
title varchar(50),
description varchar(50),
PRIMARY KEY(id, note_id)
);
The query generates the following error:#1075 - Incorrect table definition; there can be only one auto column and it must be defined as a key
CREATE TABLE note (
id int AUTO_INCREMENT,
note_id int,
title varchar(50),
description varchar(50),
PRIMARY KEY(id, note_id, title)
);
AUTO_INCREMENT
feature to a column that is not selected as a primary key.
If we want to add the feature to a column, we must make it primary keyCREATE TABLE note (
id int AUTO_INCREMENT,
title varchar(50),
description varchar(50)
);
After running the above query, the following error will be generated:#1075 - Incorrect table definition; there can be only one auto column and it must be defined as a key
The correct syntax of the query after adding primary key to the column id
:CREATE TABLE note (
id int AUTO_INCREMENT,
title varchar(50),
description varchar(50),
PRIMARY KEY (id)
);
notes
if exists.
It will not occur an error if it does not exist, because we are using IF EXISTS
keywordDROP TABLE IF EXISTS notes
The same goes when creating a new table.
It will not cause an error if a table with the same name already exists.
If the table does not exist, it will create one with the specified fields:CREATE TABLE IF NOT EXISTS students (
`id` int(11) NOT NULL,
`first_name` varchar(255) NOT NULL,
`last_name` varchar(255) NOT NULL
) ENGINE=InnoDB;
st
and copies only several fields from students
tableCREATE TABLE st AS
SELECT
id,
first_name AS name,
last_name AS surname
FROM students
USE university; -- we are looking at the database called: university
SET @grade = (SELECT MAX(points) FROM students);
SELECT @grade AS 'The highest grade'
grt
and assigns it Hello
SET @grt = 'Hello';
SELECT @grt AS greeting
SHOW VARIABLES
at signs
- @
.
Shows base directory of MySQLSELECT @@basedir
Shows whether query uses cache or notSELECT @@have_query_cache
Shows what size does query cache haveSELECT @@query_cache_size
...
Shows complete list of system variables with their valuesSHOW VARIABLES
Complete list of system variables using phpmyadmin
: phpmyadmin/server_variables.phpEXPLAIN
provides detailed information about the query result.
One of the information that EXPLAIN
gives us is how many rows will be affected after running the queryEXPLAIN UPDATE students SET mail = 'email@gmail.com' WHERE id > 39
Note: EXPLAIN
works with the following statements: SELECT
, DELETE
, INSERT
, REPLACE
, UPDATE