Alter database table columns without dropping table Part 67 — Transcript
Full transcript
- 0:00is part 67 of sql server tutorial in
- 0:03this video we'll discuss altering
- 0:04database table columns without dropping
- 0:07the table
- 0:08let's understand this with an example
- 0:10we'll be using this table tbl employee
- 0:12for this demo notice that this table has
- 0:14got id name gender and salary columns
- 0:18and i have used this create table script
- 0:20to create the table tbl employee and if
- 0:23you notice the salary column n where
- 0:25care is the data type and this is the
- 0:27sql script to populate it with some
- 0:29sample data if you need the sql script i
- 0:31will have it available on my blog now
- 0:33let's say based on this table we want to
- 0:36write a query which is going to list the
- 0:38total salaries of employees grouped by
- 0:41gender so we want the output to be like
- 0:43this so let's write a query for that
- 0:47so select
- 0:49gender
- 0:50and we want sum of salary
- 0:55and let's give it as amalias
- 0:58total
- 0:59from table tbl employee
- 1:04and we want to group the salaries
- 1:07by
- 1:08gender
- 1:09and keep in mind the salary column data
- 1:12type is nvecca and let's try to execute
- 1:14this and see what's going to happen look
- 1:15at the error message it states operand
- 1:18data type and where care is invalid for
- 1:20some operator so basically this error
- 1:23message is stating we cannot use the
- 1:26salary column
- 1:27with some aggregate function that's
- 1:30basically because its data type is
- 1:31n-wirecare so we need to change the data
- 1:34type of this column from n-wirecare to
- 1:37integer and one way to do that within
- 1:40the object explorer right click on the
- 1:42table tbl employee click design
- 1:46and notice the data type of the salary
- 1:48column it's n vacca let's change it to
- 1:51integer
- 1:53and let's try to save it and see what's
- 1:54going to happen look at that i get a
- 1:57warning saving changes is not permitted
- 2:00basically this is telling we need to
- 2:02drop and recreate the table and if you
- 2:04remember this table has already got some
- 2:07data as well so if we drop and recreate
- 2:09it we are going to lose that data so how
- 2:12do we get rid of this warning message
- 2:14okay
- 2:15basically there are two ways
- 2:18option one use a sql query to alter the
- 2:21column okay so instead of using the sql
- 2:24server designer we can simply use a sql
- 2:27query
- 2:29so let's write the sql query
- 2:33alt
- 2:34table tbl employee
- 2:38and within that table we want to alter
- 2:40the
- 2:41column
- 2:44salary and we want to change the data
- 2:46type to integer
- 2:48so let's execute that and let's now run
- 2:51this query and see if it works as
- 2:53expected look at that it works as
- 2:54expected so this is one option and the
- 2:57second option is basically to disable
- 3:01this option within sql server so prevent
- 3:04saving changes that require table
- 3:06recreation okay this option is on by
- 3:10default within sql server all we need to
- 3:12do is disable that option and to do that
- 3:14go back to sql server within tools
- 3:17select options
- 3:19and then expand designers and under that
- 3:22table and database designers and uncheck
- 3:24this checkbox prevent saving changes
- 3:26that require table recreation
- 3:29click ok
- 3:30now let's try to
- 3:33design the table now at the moment
- 3:35salary data type is integer maybe let's
- 3:37change it to something like maybe small
- 3:40integer
- 3:42let's save the changes and see work it
- 3:44works look at that it gives a warning
- 3:46but that's fine once i click yes look at
- 3:49what's going to happen
- 3:52the table the changes are saved
- 3:56and as you might expect when we execute
- 3:57this query we get the same output
- 4:01that's it for today thank you for
- 4:02listening have a great day
About this transcript
This page contains the full transcript of Alter database table columns without dropping table Part 67 by kudvenkat, generated from the public captions YouTube serves with the video. The transcript has 621 words across 101 segments, with the original timestamps preserved so you can click any line to jump to that moment in the embedded player.
What you can do with it
Use the transcript to take notes, quote the speaker, build a study guide, generate a summary with ChatGPT or Claude via the YouTube Summary tool, or export it as a timed subtitle file with YouTube to SRT. You can also re-open it in the transcriber to translate the transcript into 100+ languages.
Free YouTube transcript tool
YouTube2Text is a free YouTube transcript generator — no signup, no daily limit. Paste any YouTube link and get the full transcript instantly, with timestamps, click-to-jump, translation to 100+ languages, AI prompts for ChatGPT, Claude, and Gemini, and exports to TXT, SRT, VTT, or Markdown.