DDL (Data Definition Language) Queries
A data definition language (DDL) is a computer language used to create and modify the structure of database objects in a database. These database objects include views, schemas, tables, indexes, etc.
This term is also known as data description language in some contexts, as it describes the fields and records in a database table.
- To Get the list of all the database in MySql
show databases;
- To select a specific Database in MySql
Use <Database_Name>;
ex: Use Demo;
- To Get the list of table in the MYSQL
show tables;
- To create your own database
Create <ObjectName> <DB_Name>;
Example: create database demo;
- To create any object inside MySQL you can use a Create command
- The Object in database are Database, Table, Constraints, Index, View, Tigger, Procedure, Function, Cursor.
- Create table query
Syntax: create table <table_name> (column1 datatype, column2 datatype, column2 datatype, ….);
Example: CREATE TABLE employee (
id int primary key,
name varchar(20) not null,
contact varchar(10) Unique,
salary double check (salary>=100000 and salary<=5000000),
gender char(1) check (gender in (‘M’,’F’,’O’)),
isActive Boolean,
doj date );
- Alter table
- Is use to modify the table or column.
- 3 types of alter query
- Add for adding new column Ex: ALTER TABLE employee ADD age int; You can also define where you want to add column by using FIRST or AFTER existing_column_name if you not use first or after the new add column to a table automatically adds those column to the end of the table.
- Modify for modifying the data type and the size ALTER TABLE employee MODIFY COLUMN age float;
- Drop for deleting the column from table ALTER TABLE employee DROP COLUMN age;
- Rename Table and column
Rename Table: ALTER TABLE employee RENAME TO empInfo;
Rename Column: ALTER TABLE empinfo RENAME COLUMN contact TO phone;
- Drop Object in DB
- Drop is nothing but deleting the object from the DB.
- When you drop Database and table, the data in the table will also be deleted.
- The object means datable & table.
- Syntax
Drop <object> <Objectname>
- Example
Drop database demo;
Join Telegram : Click Here
All Full Stack Java Study Material
Job’s For Fresher