DDL (Data Definition Language) Queries

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.

  1. To Get the list of all the database in MySql

show databases;

 

  1. To select a specific Database in MySql

Use <Database_Name>;

ex: Use Demo;

 

  1. To Get the list of table in the MYSQL

show tables;

 

  1. To create your own database

Create <ObjectName> <DB_Name>;

 

               Example: create database demo;

 

  1. To create any object inside MySQL you can use a Create command
  2. The Object in database are Database, Table, Constraints, Index, View, Tigger, Procedure, Function, Cursor.

 

  1. 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 );

 

 

  1. Alter table
    1. Is use to modify the table or column.
    2. 3 types of alter query
      1. 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.
      2.  Modify for modifying the data type and the size  ALTER TABLE employee MODIFY COLUMN age float;
      3. Drop  for deleting the column from table  ALTER TABLE employee DROP COLUMN age;

 

  1. Rename Table and column

Rename Table: ALTER TABLE employee RENAME TO empInfo;

Rename Column: ALTER TABLE empinfo RENAME COLUMN contact TO phone;

 

 

 

  1. Drop Object in DB
    1. Drop is nothing but deleting the object from the DB.
    2. When you drop Database and table, the data in the table will also be deleted.
    3. The object means datable & table.
    4. Syntax

Drop <object> <Objectname>

  1. Example

Drop database demo; 

 

Join Telegram : Click Here

 

All Full Stack Java Study Material

 

Structured Query Language

 

Job’s For Fresher

 

Share This Information To Your Friends and Your College Group’s, To Help Them !