Showing posts with label adding columns to table. Show all posts
Showing posts with label adding columns to table. Show all posts

Thursday, July 23, 2020

Adding Multiple Columns With Default Value

Almost a decade before, I came across a requirement where I needed to add multiple columns in a table with default value. It took a while on that time to figure it out.

I found it in my old SQL Projects repository and thought to share it with you.


-- Creating a table and adding a row

CREATE TABLE TestTable1(Id INT, SomeCol VARCHAR(10))

INSERT INTO TestTable1 SELECT 10, 'abcdefgh'

-- Adding Multiple Columns With Default Values

ALTER TABLE TestTable1

                        ADD Col1 VARCHAR(100) NOT NULL DEFAULT('SomeInformation'),

                                    Col2 INT NOT NULL DEFAULT(999)

GO

-- Retrieve Data from Table

SELECT * FROM TestTable1

GO



Big Data & SQL

Hi Everybody, Please do visit my new blog that has much more information about Big Data and SQL. The site covers big data and almost all the...