In this article I am going to discuss how to create MySQL database class 11? In the previous article, I have discussed the introduction to MySQL. So let’s start now!
Topics Covered
Comprehensive Notes on Create MySQL Database Class 11
SQL provides commands to work on the database objects. These commands are mainly categorized in DDL, DML commands. Let’s understand the DDL and DML commands.
DDL commands
DDL stands for Data Definition Language. Data definition refers to defining structure of the database objects. In this command the database following things will be specified:
- Schema
- The data type for each column
- Constraints
- Authorizations
Some examples of DDL commands are – Create, Alter, Drop
DML Commands
DML stands for Data Manipulation Language. It is used to perform tasks on data provided in the tables. You can insert, update and delete data from the table. Some examples are – insert, update, and delete.
Create a database
Create database is the first step towards working with MySQL database. To create a database open MySQL Server and type command in following manner:
create database <database_name>;
Every MySQL commands ends with semicolon. Type create database followed by the database name and press enter. Have a look at the following :
create database school;
Now when you complete this command check the database is created or not. To check this use the following command:
show databases;
Observe the following screenshot:
Now to access or open this database for work you can have use command. Observe this:
use school;
When you type this command use <databasename>, gives a message database changed.
In the next section of Create MySQL Database Class 11 you will learn about create table. After opening the database your database is ready for the next step is that is to create a table. Follow this syntax for table creation.
create table <tablename>
(column1 datatype(size) constraint,
column2 datatype(size) constraint,...);
Here in the syntax,
- create table – command to create a table
- tablename – provide the tablename which you are going to create
- column specification – column specification accepts columnname then datatype and size and contraint name
Example
create table students
(roll_no int(3) primary key,
sname varchar(20) not null,
dob datetime,
class varchar(10));
When the command is executed it will display the message – Query OK, 0 rows affected, 1 warning (1.99 sec). Observe the following screenshot:
Things to be remember while crating table:
- The size must be specified in the brackets
- Separate each column by a comma (,)
- The closing bracket must require the semicolon
- Provide a semicolon at the end of creating a table
Checking the structure of a table
Describe table command is used to check the structure of a table. Observe this command:
describe students;
You can also use desc instead of describe command. In the next section of Create MySQL Database Class 11 you will learn hot to check the table is exists or not!
Checking the table is exists or not
MySQL doesn’t allow to create a table if table is already created. For that you need to check that table is already exists or not, you can check it by using following command:
show tables;
Observe this screenshot:
So I hope now you are able to create database and create table in MySQL. So here I am concluding this article Create MySQL Database Class 11, if you have doubt or query feel free to ask in the comment section.
I am also waiting for your valuable views, feedback or suggestions regarding the contents, feel free to share in the comment section.
Thank you reading for the article Create MySQL Database Class 11.
To access the complete study material for class 11, follow this link: