0% found this document useful (0 votes)
3 views2 pages

Program 1

The document outlines DDL (Data Definition Language) commands in SQL, specifically focusing on CREATE TABLE, ALTER TABLE, and DROP TABLE commands. It provides syntax examples for creating a new table, modifying an existing table by adding, modifying, or dropping columns, and permanently deleting a table. Additionally, it includes specific examples related to a 'Student' table to illustrate the commands in action.

Uploaded by

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

Program 1

The document outlines DDL (Data Definition Language) commands in SQL, specifically focusing on CREATE TABLE, ALTER TABLE, and DROP TABLE commands. It provides syntax examples for creating a new table, modifying an existing table by adding, modifying, or dropping columns, and permanently deleting a table. Additionally, it includes specific examples related to a 'Student' table to illustrate the commands in action.

Uploaded by

danishprakash576
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

Program 1:

DDL (Data Definition Language) Commands in SQL


DDL commands are used to define, modify, and remove database objects such as tables.
1. CREATE TABLE
The CREATE TABLE command is used to create a new table in a database.
Syntax: CREATE TABLE Student (
Student_ID INT PRIMARY KEY,
CREATE TABLE table_name ( Name VARCHAR(50),
column1 datatype constraint, Age INT,
column2 datatype constraint, Course VARCHAR(30)
... );
);
Output:
A table named Student is created with four columns:
 Student_ID
 Name
 Age
 Course
2. ALTER TABLE
The ALTER TABLE command is used to modify the structure of an existing table.
(a) Add a New Column

ALTER TABLE table_name ALTER TABLE Student


ADD column_name datatype; ADD Email VARCHAR(100);

Result:
A new column Email is added to the Student table.
(b) Modify a Column
Example:

ALTER TABLE Student ALTER TABLE Student


MODIFY column name data type(100); MODIFY Name VARCHAR(100);

(c) Drop a Column


Example:

ALTER TABLE Student


DROP COLUMN Age;
Result:
The Age column is removed from the Student table.
3. DROP TABLE
The DROP TABLE command is used to permanently delete a table and all its data from
the database.
Syntax:

DROP TABLE table_name; DROP TABLE Student;

Result:
The Student table and all records stored in it are permanently removed from the
database.

Command Purpose Example

CREATE TABLE Creates a new table CREATE TABLE Student (...);

ALTER TABLE Student ADD Email


ALTER TABLE Modifies an existing table
VARCHAR(100);

DROP TABLE Deletes a table permanently DROP TABLE Student;

CREATE TABLE Students ( StudentID INT PRIMARY KEY, FirstName VARCHAR(50) NOT
NULL,
LastName VARCHAR(50), EnrollmentDate DATE );

ALTER TABLE Students ADD Email VARCHAR(100);

ALTER TABLE Students DROP COLUMN LastName;

ALTER TABLE Students MODIFY COLUMN FirstName VARCHAR(100);

DROP TABLE Students;

You might also like