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

STUDENT_SQL_Examples

The document provides SQL examples for managing a STUDENT table, including DDL commands for creating, altering, and dropping tables, as well as DML commands for inserting, updating, and deleting records. It also includes DQL commands for querying data and counting students. Key DDL commands are summarized, highlighting their functions in table management.

Uploaded by

nagaranivo2003
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)
3 views2 pages

STUDENT_SQL_Examples

The document provides SQL examples for managing a STUDENT table, including DDL commands for creating, altering, and dropping tables, as well as DML commands for inserting, updating, and deleting records. It also includes DQL commands for querying data and counting students. Key DDL commands are summarized, highlighting their functions in table management.

Uploaded by

nagaranivo2003
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/ 2

STUDENT Table SQL Examples

1. DDL - Data Definition Language

-- CREATE TABLE
CREATE TABLE STUDENT (
StudentID INT PRIMARY KEY,
Name VARCHAR(100),
Age INT,
Department VARCHAR(50),
Grade CHAR(1)
);

2. DML - Data Manipulation Language

-- INSERT INTO STUDENT


INSERT INTO STUDENT (StudentID, Name, Age, Department, Grade) VALUES
(1, 'Alice', 20, 'CSE', 'A'),
(2, 'Bob', 21, 'ECE', 'B'),
(3, 'Charlie', 19, 'CSE', 'A');

-- UPDATE STUDENT
UPDATE STUDENT
SET Grade = 'A'
WHERE StudentID = 2;

-- DELETE FROM STUDENT


DELETE FROM STUDENT
WHERE StudentID = 3;

3. DQL - Data Query Language

-- SELECT ALL
SELECT * FROM STUDENT;

-- SELECT Specific Columns


SELECT Name, Grade
FROM STUDENT
WHERE Department = 'CSE';
STUDENT Table SQL Examples

-- COUNT Students
SELECT COUNT(*) AS Total_Students FROM STUDENT;

4. ALTER, DROP, TRUNCATE Examples

-- ALTER TABLE
ALTER TABLE STUDENT ADD Email VARCHAR(100);
ALTER TABLE STUDENT MODIFY Age SMALLINT;
ALTER TABLE STUDENT DROP COLUMN Grade;

-- TRUNCATE TABLE
TRUNCATE TABLE STUDENT;

-- DROP TABLE
DROP TABLE STUDENT;

5. Summary of DDL Commands

Summary of DDL Commands:

CREATE - Create a new table


ALTER - Modify table structure (add/remove/modify columns)
DROP - Delete a table from the database
TRUNCATE - Delete all data from a table quickly

You might also like