SQL- DDL, DML, DCL, DTL, DQL- SQL Commands With Examples

SQL- DDL, DML, DCL, DTL, DQL- SQL Commands With Examples

SQL, Structured Query Language, is a programming language designed to manage data stored in relational databases.

SQL Commands:-

SQL commands are instructions. It is used to communicate with the database.

Types of SQL Commands:-

sql commands- pywix

Data Definition Language (DDL):-

DDL changes the structure of the table like creating a table, deleting a table, altering a table, etc.

  • CREATE
  • ALTER
  • DROP
  • TRUNCATE

This statement is used to create a table or a database.

‘CREATE DATABASE’ Statement:- this statement is used to create a database.
Syntax:-
CREATE DATABASE DatabaseName;
Example:-
CREATE DATABASE School;

‘CREATE TABLE’ Statement:-This statement is used to create a table.
Syntax:-
CREATE TABLE TableName (
Column1 datatype,Column2 datatype,
….
ColumnN datatype
);
Example:-

Tid INT NOT NULL AUTO_INCREMENT,
Tname VARCHAR(255),
Tmob VARCHAR(255),
Address VARCHAR(255),
City VARCHAR(255),
Country VARCHAR(255),
PRIMARY KEY(Tid)
);

This statement is used to drop an existing table or a database. It is used to delete both the structure and record stored in the table or a database.

‘DROP DATABASE’ Statement:-This statement is used to drop an existing database.
Syntax:-
DROP DATABASE DatabaseName;
Example:-
DROP DATABASE School;

‘DROP TABLE’ Statement:-This statement is used to drop an existing table.
Syntax:-
DROP TABLE TableName;
Example:-
DROP Table Teacher_Info;

It is used to delete all the rows from the table and free the space containing the table( it also deleted the index file of that table).
Syntax:-
TRUNCATE TABLE TableName;
Example:-
TRUNCATE Table Teacher_Info;

This command is used to delete, modify or add constraints or columns in an existing table.
ADD/DROP COLUMN:-we can use the ALTER TABLE statement with ADD/DROP Column command according to our need.
Syntax:-
ALTER TABLE TableName ADD ColumnName Datatype;
Example:-
ALTER TABLE Teacher_Info ADD Salary varchar(255);
Syntax:-

ALTER TABLE TableName DROP COLUMN ColumnName;

ALTER TABLE Statement with ALTER COLUMN:-This statement is used to change the data type of an existing column in a table.
Syntax:-
ALTER TABLE TableName MODIFY COLUMN ColumnName Datatype;
Example:-
ALTER TABLE Teacher_Info MODIFY COLUMN salary INT;

Data Manipulation Language:-

DML commands are used to modify the database. It is responsible for all form of changes in the database. commands that come under DML are:-

  • INSERT
  • UPDATE
  • DELETE

Read Complete Article click here

Originally published at https://pywix.blogspot.com.

Love podcasts or audiobooks? Learn on the go with our new app.

Building a Rule-Based Platform to Manage Netflix Membership SKUs at Scale

How can I use SNAP to improve my estimation practices?

Dynamic analysis of iOS app with Hookify

How to Deal with (Your) Unsatisfying Code

A year of Digital Delivery

Setup LVM and Share via NFS in Lab ENV

Connect to Linux EC2 instances in a private subnet on AWS - by Session Manager instead of bastion

Shortcuts to WCAG 2.0 AA Compliance

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Digital Classes

Digital Classes

More from Medium

Brush up my python skills

Import stock data from Alpha Vantage into SQL database

HOW TO RESPOND TO BUSINESS CASE QUESTIONS USING BASIC SQL QUERIES

SQL and Data Science: Why is SQL important? — Part 1