0% found this document useful (0 votes)
10 views5 pages

Classwork 69103 2

This document provides an overview of database concepts and Structured Query Language (SQL) commands, specifically focusing on Data Definition Language (DDL) commands. It details the syntax and usage of commands such as 'Show tables', 'Desc', 'Alter Table', and 'Drop Table', along with examples for adding, modifying, and deleting columns in a table. The document also includes practical examples related to a 'Hotel' table to illustrate the application of these commands.

Uploaded by

erictsam58
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)
10 views5 pages

Classwork 69103 2

This document provides an overview of database concepts and Structured Query Language (SQL) commands, specifically focusing on Data Definition Language (DDL) commands. It details the syntax and usage of commands such as 'Show tables', 'Desc', 'Alter Table', and 'Drop Table', along with examples for adding, modifying, and deleting columns in a table. The document also includes practical examples related to a 'Hotel' table to illustrate the application of these commands.

Uploaded by

erictsam58
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/ 5

UNIT IV

DATABASE CONCEPTS

AND

THE STRUCTURED QUERY


LANGUAGE

SESSION 07

Page 1 of 5
DDL Commands:
Show tables:To list tables in a database

Example:Show tables;

Desc TableName: To view the structure of the table

Syntax:

desc <tablename>;

or

describe <tablename>;

Alter Table Command:


It is used to change the definition of an existing table. It can be used to add a
new column, delete an existing column, and change the data type, size and name
of the existing column.
It has four clauses
1. ADD

2. MODIFY

3. CHANGE

4. DROP

Adding columns:To add a new column to an existing table.

Syntax:

Alter table <Table Name> Add <Column Name><Data type>[<Size>];

Note: If you want to add more than one column the add clause has to be
repeated according to the number of columns to be added.

Page 2 of 5
Modifying Column Definitions:

To either change the data type or size of an existing column, we make use of the
modify clause Alter table command.

Syntax:

Alter table <table name> modify <column Name><data type>(<size>);

Note: If you want to modify more than one column the modify clause has to be
repeated according to the number of columns to be modified.

To change the existing column names: The change clause of alter table
command is used to change the name of an existing column.

Syntax:

Alter table<table name>change<old column name><new column name>

<data type>[<size>];

Note: If you want to change more than one column the change clause has to be
repeated according to the number of columns to be changed.

Deleting columns: To remove the columns from an existing table, we make use
of the drop clause of the Alter table command.

Syntax:

Alter table<table name> drop <column name>,drop<column name>………;

Note: The Drop clause has to be repeated as many as the number of columns
has to be removed from the table.

Page 3 of 5
Drop Table Command:

This is a DDL command which is used to remove the table structure from a
database.

Syntax:

Drop table<table name>;

Eg: Drop table Emp;

Example:

Create the table Hotel with the following specifications and write commands for
the following:

Column Name Data Type Size

No Int 5

Name char 25

Type varchar 15

Price float 8,2

1. To display the structure of the above table

Ans: desc hotel;

2. To add a new column qty of float type with size 4,2

Ans: Alter table hotel add qty float (4,2);

3. To delete the attribute name from the above table

Ans: Alter table hotel drop name;

Page 4 of 5
4. To change the data type of Type field to char

Ans:Alter table hotel modify Type char (15);

5. To rename the attribute Type to Food_Type

Ans: Alter table hotel change Type Food_Type char (15);

6. To delete the table Hotel

Ans: Drop table hotel;

Page 5 of 5

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy