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

14.1 Lecture 11 ALTER PDF

The ALTER TABLE statement is used to change the structure of existing tables. It allows adding, removing, and modifying columns and constraints. The document provides syntax examples for adding and dropping columns, modifying and renaming columns, and adding and dropping constraints.

Uploaded by

Tauseef khan
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)
45 views5 pages

14.1 Lecture 11 ALTER PDF

The ALTER TABLE statement is used to change the structure of existing tables. It allows adding, removing, and modifying columns and constraints. The document provides syntax examples for adding and dropping columns, modifying and renaming columns, and adding and dropping constraints.

Uploaded by

Tauseef khan
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

ALTER

The ALTER TABLE statement is used to change the definition or structure of an existing table

ALTER TABLE "table_name"


[Specify Actions];

Following actions can be performed


Syntax
• Columns – Add, Delete (Drop), Modify or Rename
• Constraints – Add, Drop
• Index – Add, Drop

Start-Tech Academy
COLUMN – ADD & DROP
The basic syntax of an ALTER TABLE command to add/drop a Column in an existing table is as follows.

ALTER TABLE "table_name"


ADD "column_name" "Data Type";
Syntax
ALTER TABLE "table_name"
DROP "column_name";

Start-Tech Academy
COLUMN – MODIFY & RENAME
The basic syntax of an ALTER TABLE command to Modify/Rename a Column in an existing table is as follows.

ALTER TABLE "table_name"


ALTER COLUMN "column_name" TYPE "New Data Type";

Syntax
ALTER TABLE "table_name"
RENAME COLUMN "column 1" TO "column 2";

Start-Tech Academy
CONSTRAINT – ADD & DROP
The basic syntax of an ALTER TABLE command to add/drop a Constraint on a existing table is as follows.

1. ALTER TABLE "table_name“ ALTER COLUMN “column_name” SET NOT NULL;

2. ALTER TABLE "table_name“ ALTER COLUMN “column_name” DROP NOT NULL;

3. ALTER TABLE "table_name" ADD CONSTRAINT “column_name” CHECK

Syntax (“column_name”>=100);

4. ALTER TABLE "table_name" ADD PRIMARY KEY (“column_name”);

5. ALTER TABLE “child_table" ADD CONSTRAINT “child_column”


FOREIGN KEY (“parent column”) REFERENCES “parent table”;

Start-Tech Academy

You might also like