Create, Drop and Alter Operations in SQL Server (DDL Operations) | YourSite

Create, Drop and Alter Operations in SQL Server (DDL Operations)

SQL SERVER 1463 views

In this blod we will discuss how to perform Create, Drop and Alter Operations in SQL Server (DDL Operations)

Use a Database in your Project


USE DB02TEST01;

Create a table: ( Customers )


CREATE TABLE Customers_rumman_1637935(
CustomerId char(5) not null,
CompanyName varchar(40) not null,
ContactName char(30) null,
Address varchar(60) null,
City char(15) null,
Phone char(24) null,
Fax char(24) null
)

Create a table: ( Orders )


CREATE TABLE Orders_rumman_1637935(
OrderId int not null,
CustomerId char(5) not null,
OrderDate datetime null,
ShippedDate datetime null,
Freight money null,
ShipName varchar(40) null,
ShipAddress varchar(24) null,
Quantity integer null
)

Use the ALTER TABLE statement, add a new column named ShipRegion to the Orders_rumman_1637935 table the field should be nullable and integer constant.


ALTER TABLE Orders_rumman_1637935 ADD ShipRegion int null;

Use the ALTER TABLE statement, change the data type of the column ShipRegion from INTEGER to Character with length 8. The field may contain null variable.


ALTER TABLE Orders_rumman_1637935 DROP COLUMN ShipRegion;
ALTER TABLE Orders_rumman_1637935 ADD ShipRegion char(8) null;

Delete the formally created column ShipRegion


ALTER TABLE Orders_rumman_1637935 DROP COLUMN ShipRegion

Using the SQL Server Management Studio, try to insert a new row into the Orders table with the following values. (10, 'ord01', getdate(), getdate(), 100.0, 'Windstar', 'Ocean',1) Find out the reason why this is not possible.


INSERT INTO Orders_rumman_1637935 (OrderId, CustomerId, OrderDate, ShippedDate, Freight,
ShipName, ShipAddress, Quantity)
VALUES (10, 'ord01', getdate(), getdate(), 100.0, 'Windstar', 'Ocean',1)

Using the ALTER TABLE statement, add the current system date and time as the default value to the OrderDate column of the Order table.


ALTER TABLE Orders_rumman_1637935
ADD CONSTRAINT df_Orders_rumman_1637935_OrderDate
DEFAULT GETDATE() FOR OrderDate

Rename the city column of the Customers table. The new name is town


sp_RENAME 'Customers_rumman_1637935.Town' , 'City'

🚀 More Blogs You Might Like

Explore more articles and keep learning

What is Bounce Rate in SEO? Complete Guide for Beginners
search-engine-optimization
What is Bounce Rate in SEO? Complete Guide for Beginners

Learn what bounce rate is in SEO, how it is calculated, why it matters, common causes of high bounce rates, an...

👁 28 2026-05-24
Read More →
Comprehensive Interviewer Guide - Detailed Article
skill
Comprehensive Interviewer Guide - Detailed Article

Learn how to conduct effective interviews with this comprehensive interviewer guide. Explore hiring strategies...

👁 43 2026-05-22
Read More →
Five Industry Shifts Reshaping the AI Ecosystem (2026 Trends)
skill
Five Industry Shifts Reshaping the AI Ecosystem (2026 Trends)

Five Industry Shifts Reshaping the AI Ecosystem (2026 Trends)...

👁 38 2026-05-19
Read More →
How to Grow Your Business Mindset Step by Step
skill
How to Grow Your Business Mindset Step by Step

Learn how to develop and grow a successful business mindset step by step. Discover entrepreneurial thinking, p...

👁 56 2026-05-09
Read More →