Most of us at least know how to query the data from a table using a Select statement. But when it comes to creating a database then some of us may not know How to create DB from scratch?
In this article, I will show you how you can create a DB from scratch and create or alter tables.
Follow these steps:
Step1: Open MySQL Workbench or CMD Prompt.
Step2: Use the below cmd to create a Database.
Syntax: Create Database <Database name>;
Query : Create Database NeptuneDB;
Note : Run the below cmd to select DB if you have more than one DB.
Syntax : Use <database name>;
Query: Use NeptuneDB;
Step3: Now Create a tables in the newly created database.
Syntax: Create table <table name> (column1 data_type, column2 data_type,...);
Query: Create table Users (
UserID int,
FirstName varchar(255),
LastName varchar(255),
Email varchar(255),
Address varchar(255) );
Step4: Now insert the values into the table we just created.
Syntax : INSERT INTO <table name> VALUES (column1, column2,...);
Query : INSERT INTO Users VALUES (
'1','Neptune','World','neptuneworld. [email protected]',
'https://neptuneworld.in');
Note: Above syntax work when you pass all the column values.
Just like that you can create other tables in the same DB.
Example of another table:
Articles table created.
If you want to add new column in table then you can use ALTER cmd.
Example : New column added in Articles table.
Finally, we create a database and also create and alter table. This will definitely help you if you are starting to learn MySQL Server.
Thanks for Reading !!!