1
I would like to know how to create a database in Mysql using SQL commands, which I can run in Mysql Workbench, phpMyAdmin or any other software.
What SQL commands are needed to create a database and its tables?
1
I would like to know how to create a database in Mysql using SQL commands, which I can run in Mysql Workbench, phpMyAdmin or any other software.
What SQL commands are needed to create a database and its tables?
10
The Mysql Workbench and the phpMyAdmin are only visual tools that offer convenience/ease in handling a database, SQL commands are independent of it.
That way, assuming you are using some version of Mysql, to create a database the command is CREATE DATABASE
CREATE DATABASE meu_banco_de_dados
To create tables, use the command CREATE TABLE
:
CREATE TABLE minha_tabela (
id INT PRIMARY KEY AUTO_INCREMENT,
campo1 VARCHAR(50),
campo2 INT,
campo3 FLOAT
)
4
It’s easy:
You create the database
CREATE DATABASE NOME_DA_BASE_DE_DADOS
You use the database
USE NOME_DA_BASE_DE_DADOS
You create the table
CREATE TABLE NOME_DA_TABELA (
NOME_DO_CAMPO_ID INT PRIMARY KEY AUTO_INCREMENT,
NOME_DE_OUTRO_CAMPO INT,
NOME_DE_OUTRO_CAMPO VARCHAR(255)
)
Note that there are several types, I’m the one who only used here the INT and the VARCHAR.
Browser other questions tagged mysql sql
You are not signed in. Login or sign up in order to post.
Very good answer, showed the commands questioned, explained and exemplified succinctly and objectively.+ 1
– user28595