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

10) Advanced Data Definition Commands

The document discusses advanced data definition commands in SQL, including how to use ALTER to change data types and characteristics of columns, add and drop columns, add primary and foreign keys, delete tables, and more. It also covers advanced select queries, creating views, and joining tables with aliases.
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)
64 views2 pages

10) Advanced Data Definition Commands

The document discusses advanced data definition commands in SQL, including how to use ALTER to change data types and characteristics of columns, add and drop columns, add primary and foreign keys, delete tables, and more. It also covers advanced select queries, creating views, and joining tables with aliases.
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
You are on page 1/ 2

10)Advanced Data Definition Commands

• All changes in table structure are made by using ALTER command

– Followed by keyword that produces specific change

– Following three options are available:

• ADD

• MODIFY

• DROP

Changing a Column’s Data Type

• ALTER can be used to change data type

• Some RDBMSs (such as Oracle) do not permit changes to data types unless column to be
changed is empty

Changing a Column’s Data Characteristics

• Use ALTER to change data characteristics

• If column to be changed already contains data, changes in column’s characteristics are


permitted if those changes do not alter the data type

Adding a Column

• Use ALTER to add column

– Do not include the NOT NULL clause for new column

Dropping a Column

• Use ALTER to drop column

– Some RDBMSs impose restrictions on the deletion of an attribute

Adding Primary and Foreign Key Designations

• When table is copied, integrity rules do not copy, so primary and foreign keys need to be
manually defined on new table

• User ALTER TABLE command

– Syntax:

• ALTER TABLE tablename ADD


PRIMARY KEY(fieldname);

• For foreign key, use FOREIGN KEY in place of PRIMARY KEY


Deleting a Table from the Database

• DROP

– Deletes table from database

– Syntax:

• DROP TABLE tablename;

Advanced Select Queries

• SQL provides useful functions that can:

– Count

– Find minimum and maximum values

– Calculate averages

• SQL allows user to limit queries to only those entries having no duplicates or entries whose
duplicates may be grouped

Virtual Tables: Creating a View

• View is virtual table based on SELECT query

– Can contain columns, computed columns, aliases, and aggregate functions from one or
more tables

• Base tables are tables on which view is based

• Create view by using CREATE VIEW command

Joining Tables with an Alias

• Alias can be used to identify source table

• Any legal table name can be used as alias

• Add alias after table name in FROM clause

– FROM tablename alias

You might also like