{"id":92,"date":"2026-03-06T07:11:56","date_gmt":"2026-03-06T07:11:56","guid":{"rendered":"https:\/\/gigz.pk\/sql\/?post_type=lesson&#038;p=92"},"modified":"2026-03-16T18:52:16","modified_gmt":"2026-03-16T18:52:16","slug":"alter-table","status":"publish","type":"lesson","link":"https:\/\/gigz.pk\/sql\/lesson\/alter-table\/","title":{"rendered":"\u00a0ALTER TABLE"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">The <code>ALTER TABLE<\/code> statement is used to <strong>modify an existing table<\/strong> in a database. You can use it to <strong>add, delete, or modify columns<\/strong>, and even change table constraints.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>1. Add a Column<\/strong><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">To add a new column to a table:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">ALTER TABLE table_name<br>ADD column_name datatype;<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Example:<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">ALTER TABLE Employees<br>ADD DateOfBirth DATE;<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">This adds a new column <code>DateOfBirth<\/code> to the <code>Employees<\/code> table.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>2. Delete a Column<\/strong><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">To remove a column from a table:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">ALTER TABLE table_name<br>DROP COLUMN column_name;<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Example:<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">ALTER TABLE Employees<br>DROP COLUMN DateOfBirth;<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">This deletes the <code>DateOfBirth<\/code> column from the table.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>3. Modify a Column<\/strong><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">To change the datatype or size of an existing column:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">ALTER TABLE table_name<br>MODIFY COLUMN column_name new_datatype;<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Example:<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">ALTER TABLE Employees<br>MODIFY COLUMN LastName VARCHAR(100);<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">This changes the <code>LastName<\/code> column to allow up to 100 characters.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>4. Rename a Column<\/strong><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">To rename a column (syntax may vary by database):<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">ALTER TABLE table_name<br>RENAME COLUMN old_name TO new_name;<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Example:<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">ALTER TABLE Employees<br>RENAME COLUMN LastName TO Surname;<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">This renames <code>LastName<\/code> to <code>Surname<\/code>.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>5. Rename a Table<\/strong><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">To rename the entire table:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">ALTER TABLE old_table_name<br>RENAME TO new_table_name;<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Example:<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">ALTER TABLE Employees<br>RENAME TO Staff;<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">This renames the <code>Employees<\/code> table to <code>Staff<\/code>.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>6. Add a Constraint<\/strong><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">You can add constraints like <code>PRIMARY KEY<\/code>, <code>FOREIGN KEY<\/code>, <code>UNIQUE<\/code>, or <code>CHECK<\/code>:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">ALTER TABLE table_name<br>ADD CONSTRAINT constraint_name constraint_definition;<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Example:<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">ALTER TABLE Employees<br>ADD CONSTRAINT PK_EmployeeID PRIMARY KEY (EmployeeID);<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">This sets <code>EmployeeID<\/code> as the primary key.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Key Points<\/strong><\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>ALTER TABLE<\/code> changes the table structure <strong>without deleting data<\/strong>.<\/li>\n\n\n\n<li>Always <strong>backup your table<\/strong> before making major changes.<\/li>\n\n\n\n<li>Syntax can vary slightly between <strong>MySQL, SQL Server, and Oracle<\/strong>.<\/li>\n<\/ul>\n\n\n<div class=\"yoast-breadcrumbs\"><span><span><a href=\"https:\/\/gigz.pk\/sql\/\">Home<\/a><\/span> \u00bb <span class=\"breadcrumb_last\" aria-current=\"page\">Intermediate SQL for Data Professionals (SQL-201) > Table Management > ALTER TABLE<\/span><\/span><\/div>\n\n\n<div class=\"schema-faq wp-block-yoast-faq-block\"><div class=\"schema-faq-section\" id=\"faq-question-1773575350313\"><strong class=\"schema-faq-question\"><\/strong> <p class=\"schema-faq-answer\"><\/p> <\/div> <\/div>\n","protected":false},"menu_order":39,"template":"","class_list":["post-92","lesson","type-lesson","status-publish","hentry"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.6 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>\u00a0ALTER TABLE - SQL Learning Hub<\/title>\n<meta name=\"description\" content=\"&quot;Learn SQL ALTER TABLE: add, delete, modify, or rename columns and tables, plus add constraints safely with examples.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/gigz.pk\/sql\/lesson\/alter-table\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"\u00a0ALTER TABLE - SQL Learning Hub\" \/>\n<meta property=\"og:description\" content=\"&quot;Learn SQL ALTER TABLE: add, delete, modify, or rename columns and tables, plus add constraints safely with examples.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/gigz.pk\/sql\/lesson\/alter-table\/\" \/>\n<meta property=\"og:site_name\" content=\"SQL Learning Hub\" \/>\n<meta property=\"article:modified_time\" content=\"2026-03-16T18:52:16+00:00\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data1\" content=\"1 minute\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":[\"WebPage\",\"FAQPage\"],\"@id\":\"https:\\\/\\\/gigz.pk\\\/sql\\\/lesson\\\/alter-table\\\/\",\"url\":\"https:\\\/\\\/gigz.pk\\\/sql\\\/lesson\\\/alter-table\\\/\",\"name\":\"\u00a0ALTER TABLE - SQL Learning Hub\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/gigz.pk\\\/sql\\\/#website\"},\"datePublished\":\"2026-03-06T07:11:56+00:00\",\"dateModified\":\"2026-03-16T18:52:16+00:00\",\"description\":\"\\\"Learn SQL ALTER TABLE: add, delete, modify, or rename columns and tables, plus add constraints safely with examples.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/gigz.pk\\\/sql\\\/lesson\\\/alter-table\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/gigz.pk\\\/sql\\\/lesson\\\/alter-table\\\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/gigz.pk\\\/sql\\\/lesson\\\/alter-table\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/gigz.pk\\\/sql\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Intermediate SQL for Data Professionals (SQL-201) > Table Management > ALTER TABLE\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/gigz.pk\\\/sql\\\/#website\",\"url\":\"https:\\\/\\\/gigz.pk\\\/sql\\\/\",\"name\":\"SQL Learning Hub\",\"description\":\"\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/gigz.pk\\\/sql\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"\u00a0ALTER TABLE - SQL Learning Hub","description":"\"Learn SQL ALTER TABLE: add, delete, modify, or rename columns and tables, plus add constraints safely with examples.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/gigz.pk\/sql\/lesson\/alter-table\/","og_locale":"en_US","og_type":"article","og_title":"\u00a0ALTER TABLE - SQL Learning Hub","og_description":"\"Learn SQL ALTER TABLE: add, delete, modify, or rename columns and tables, plus add constraints safely with examples.","og_url":"https:\/\/gigz.pk\/sql\/lesson\/alter-table\/","og_site_name":"SQL Learning Hub","article_modified_time":"2026-03-16T18:52:16+00:00","twitter_card":"summary_large_image","twitter_misc":{"Est. reading time":"1 minute"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":["WebPage","FAQPage"],"@id":"https:\/\/gigz.pk\/sql\/lesson\/alter-table\/","url":"https:\/\/gigz.pk\/sql\/lesson\/alter-table\/","name":"\u00a0ALTER TABLE - SQL Learning Hub","isPartOf":{"@id":"https:\/\/gigz.pk\/sql\/#website"},"datePublished":"2026-03-06T07:11:56+00:00","dateModified":"2026-03-16T18:52:16+00:00","description":"\"Learn SQL ALTER TABLE: add, delete, modify, or rename columns and tables, plus add constraints safely with examples.","breadcrumb":{"@id":"https:\/\/gigz.pk\/sql\/lesson\/alter-table\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/gigz.pk\/sql\/lesson\/alter-table\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/gigz.pk\/sql\/lesson\/alter-table\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/gigz.pk\/sql\/"},{"@type":"ListItem","position":2,"name":"Intermediate SQL for Data Professionals (SQL-201) > Table Management > ALTER TABLE"}]},{"@type":"WebSite","@id":"https:\/\/gigz.pk\/sql\/#website","url":"https:\/\/gigz.pk\/sql\/","name":"SQL Learning Hub","description":"","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/gigz.pk\/sql\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"}]}},"_links":{"self":[{"href":"https:\/\/gigz.pk\/sql\/wp-json\/wp\/v2\/lesson\/92","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/gigz.pk\/sql\/wp-json\/wp\/v2\/lesson"}],"about":[{"href":"https:\/\/gigz.pk\/sql\/wp-json\/wp\/v2\/types\/lesson"}],"wp:attachment":[{"href":"https:\/\/gigz.pk\/sql\/wp-json\/wp\/v2\/media?parent=92"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}