0% found this document useful (0 votes)
7 views4 pages

Experiment 1 DDL and DML

The document provides an overview of SQL commands related to Data Definition Language (DDL) and Data Manipulation Language (DML). It explains how to create, alter, and drop tables, as well as how to insert, update, and delete records in a database. Various SQL syntax examples are included to illustrate the usage of these commands.

Uploaded by

ssp6392215841
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views4 pages

Experiment 1 DDL and DML

The document provides an overview of SQL commands related to Data Definition Language (DDL) and Data Manipulation Language (DML). It explains how to create, alter, and drop tables, as well as how to insert, update, and delete records in a database. Various SQL syntax examples are included to illustrate the usage of these commands.

Uploaded by

ssp6392215841
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

https://www.programiz.

com/sql/online-compiler/

https://www.geeksforgeeks.org/sql-ddl-dql-dml-dcl-tcl-commands/

DDL (Data Definition Language)

SQL CREATE TABLE Statement

A Table is a combination of rows and columns. For creating a table we have to define the structure of
a table by adding names to columns and providing data type and size of data to be stored in columns.

CREATE table table_name

Column1 datatype (size),

column2 datatype (size),

columnN datatype(size)

);

EX- create table student(

Roll_No int(2),

Name varchar(20)

);

ALTER TABLE ADD Column Statement in SQL

ADD is used to add columns to the existing table. Sometimes we may require to add additional
information, in that case, we do not require to create the whole database again, ADD comes to our
rescue.

ALTER TABLE ADD Column Statement Syntax:

ALTER TABLE table_name ADD (Columnname_1 datatype,


Columnname_2 datatype, …Columnname_n datatype);

EX- Alter table student add phone_num int(10);

DROP

DROP is used to delete a whole database or just a table.

In this article, we will be learning about the DROP statement which destroys objects like an existing
database, table, index, or view. A DROP statement in SQL removes a component from a relational
database management system (RDBMS).

DROP TABLE table_name;

Drop table student;

DML (Data Manipulation Language)

Insert Data into Table

To add data to the table, we use INSERT INTO, the syntax is as shown below:

//Below query adds data in specific column, (like Column1=Value1)//

Insert into Table_name(Column1, Column2, Column3)

Values (Value1, value2, value3);

//Below query adds data in table in sequence of column name(Value1 will be

added in Column1 and so on)//

Insert into Table_name

Values (Value1, value2, value3);


//Adding multiple data in the table in one go//

Insert into Table_name

Values (Value01, value02, value03),

(Value11, value12, value13),

(Value21, value22, value23),

(ValueN1, valueN2, valueN3)

EX- Insert into student Values(1, ‘Akash’);

Insert into student Values(2, ‘Ram’),(3, ‘Saroj’);

SQL | UPDATE Statement

The UPDATE statement in SQL is used to update the data of an existing table in the database. We can
update single columns as well as multiple columns using the UPDATE statement as per our
requirement.

In a very simple way, we can say that SQL commands(UPDATE and DELETE) are used to change the
data that is already in the database. The SQL DELETE command uses a WHERE clause.

Syntax

UPDATE table_name SET column1 = value1, column2 = value2,…

WHERE condition;

table_name: name of the table

column1: name of first , second, third column….

value1: new value for first, second, third column….

condition: condition to select the rows for which the

values of columns needs to be updated.

EX- UPDATE student set phone_no = 11111111 where roll_no = 1;

UPDATE student set phone_no = 11111111;

SQL | DELETE Statement

Existing records in a table can be deleted using the SQL DELETE Statement. We can delete a single
record or multiple records depending on the condition we specify in the WHERE clause.
DELETE FROM table_name WHERE some_condition;

EX- Delete from student where phone_no=1111111

You might also like