.NET/C#
  • ASP.NET Core Overview
  • ASP.NET Core API tutorial
    • How to create ASP.NET Core C# API tutorial
      • launchSettings
      • Install swagger
        • Swagger best practices
      • Run the app
      • Fix CORS problem
      • Add AutoMapper
      • Add JWT reference
      • Add .gitignore
      • Basic structure & EF Core
      • AddSingleton
    • Loading Related Entities
  • Unit test controller logic in ASP.NET Core
    • Unit testing controllers
  • .NET Q&A
    • dotnet try
    • LINQ
      • LINQ Query Syntax
      • Lambda Expression
      • Standard Query Operators
  • .NET C# Interview questions
    • C# - .NET interview questions and answers [Part 1]
    • C# - .NET interview questions and answers [Part 2]
    • C# Interview questions [Part 3] General questions
  • C#
    • Object-Oriented Programming (Principles)
      • N-tier architecture style
      • Command and Query Responsibility Segregation (CQRS) pattern
      • Project architecture
    • C# Advanced review
      • Implicit typing
      • Generics
      • Attributes
      • Reflection
      • Delegates
      • Anonymous Methods and Lambda Expressions
      • Events
      • Ref vs Out
      • Task
        • TaskFactory Class
  • MySQL
    • MySQL Lerning
      • SELECT
      • ORDER BY
      • WHERE
      • DISTINCT
      • IN
      • BETWEEN
      • Join
      • INNER JOIN
      • LEFT JOIN
      • RIGHT JOIN
      • GROUP BY
      • Subquery
      • UNION
    • Stored Procedures
      • CREATE PROCEDURE
  • Versioning API, MongoDB and ci-cd
    • Create a web API with ASP.NET Core and MongoDB
    • REST API versioning with ASP.NET Core
    • Design a CI/CD pipeline using Azure DevOps
      • Create a CI/CD pipeline for GitHub repo using Azure DevOps Starter
  • TFS & TFCV
    • What is Team Foundation Version Control
      • Develop and share your code in TFVC using Visual Studio
      • Suspend your work and manage your shelvesets
    • Newtonsoft Json.NET
      • Serializing and Deserializing JSON
  • MS-SQL
    • Quick tutorial
      • Add new column to a table
      • LEFT/RIGHT Reverse operator
      • Dates (Transact-SQL)
      • CAST and CONVERT (Transact-SQL)
      • Types of JOIN
      • Our first Left Outer Join
      • CROSS JOIN
Powered by GitBook
On this page

Was this helpful?

  1. MS-SQL
  2. Quick tutorial

Add new column to a table

ALTER TABLE (Transact-SQL)

PreviousQuick tutorialNextLEFT/RIGHT Reverse operator

Last updated 4 years ago

Was this helpful?

Modifies a table definition by altering, adding, or dropping columns and constraints. ALTER TABLE also reassigns and rebuilds partitions, or disables and enables constraints and triggers.

For more information about the syntax conventions, see .

alter table [dbo].[console_games]
ADD global_sales float

Take a look at this if you want to know more about altering statements in SQL.

If we need to add a new column to our table however such a new table needs to calculate something, we can ask SQL to do it for us. Just like the following example:

update [dbo].[console_games] 
set [global_sales] = [na_sales] + [eu_sales] + [jp_sales] + [other_sales]

select * from [dbo].[console_games]

So we can now calculate the value thanks to SQL.

update [dbo].[console_games]
set [na_sales_percent] = [na_sales] / [global_sales] * 100
where [global_sales] > 0

select * from [dbo].[console_games]
USE heybaldurdb;

SELECT 
bm.Id AS BusinessId,
pro.Id AS ProblemId,
pro.Description AS ProblemDescription,
sol.Description AS SolutionDescription

	FROM businessmodels AS bm
INNER JOIN problems AS pro
ON pro.BusinessModelId = bm.Id
LEFT JOIN solutions AS sol
ON sol.BusinessModelId = bm.Id
WHERE bm.Id = 33 AND bm.ProjectId = 20
Transact-SQL Syntax Conventions
https://docs.microsoft.com/en-us/sql/t-sql/statements/alter-table-transact-sql?view=sql-server-ver15