The UPDATE TABLE Statement in SQL : Data Science Code
Skills:
SQL Analytics90%
Key Takeaways
The video covers the UPDATE TABLE statement in SQL, specifically the ALTER TABLE and DROP TABLE statements, and demonstrates how to add a column, rename a table, and delete a table in a database.
Full Transcript
hey welcome back everyone in this video we'll look at two other operations on entire tables so we'll look at first altering a table how do I add a column to a table if I later on decide that there's not enough columns in there and then we'll look at how to drop a table entirely so that it is no longer in the database it's gone including all video that was in it so first let's look at altering a table let's first look at what is living in our students table we have these seven students here let's say that at some point in the future we decide that but we want to also keep track of whether the student is in-state or out-of-state so right now we don't have that capability because we only have these four columns so how do we add a column to this database turns out it's pretty simple we just use this alter table statement put the name of the table you would like to alter the keyword add column put the name of the column you would like to add and the data type of the column you would like to add in this case since in-state is either true or false it can only take two values basically we're going to be using this bit 1 which basically acts like a true/false since you can only set bit 1 as 0 or 1 so we can use this in-state column to keep track of whether the student is an in-state or out-of-state student so if we do that and then we again select everything from students we see that we have this in-state column and since we haven't said what data to fill in to it it just sets at all as none or null in sequel until such time that you fill these values in and you can fill them in using the update statement in sequel which we looked at before now another way to alter a table it's not just that you can add a call and you can also rename the entire table so let's say that we have this table called students but for some reason we'd like to rename it to student data so we just use this alter statement alter table students rename to student data so we do that now if we try to select everything from students we get an error because it says there's no such table as students because we just renamed that table to student data if we instead do select everything from student data we get exactly the same table that we had up here now before I move on to dropping a table I do want to mention that some sequel environments will have support for different alter table operations like if you want to delete a column like let's say I no longer want the in-state column so sometimes you can do alter table students drop column in state and that'll work it doesn't work in this environment and it won't work in several environments so you have to use kind of creative workarounds like how would I use only what I have to get rid of this column if I had to do it workaround way I would probably create a new table which only has these four columns that I want to keep and then just copy the existing data into that new table and then drop my old table and then rename my new table as my old stable name so I know that sounds a little bit convoluted but sometimes you have to do it that way and sometimes you'll get lucky and you'll be in a sequel environment where you can just drop columns and it'll be fine so make sure to check on that now the last part is this infamous drop table statement in sequel this statement gets a lot of attention even if you're not super into computer science just because it's used in sequel injection which we'll see in the next video but before talking about sequel injection here's the basic way to drop a table let's say you no longer want student data so you just do drop table student data couldn't get simpler than that we do that if we try to select everything from student data we cannot because it is gone so that's how you drop a table in sequel alright so next we'll look at sequel injection
Original Description
All about the UPDATE TABLE statement in SQL
Watch on YouTube ↗
(saves to browser)
Sign in to unlock AI tutor explanation · ⚡30
Playlist
Uploads from ritvikmath · ritvikmath · 0 of 60
← Previous
Next →
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
Math Team Update
ritvikmath
Single Variable Calculus Volume of a Sphere - Proof 1
ritvikmath
Single Variable Calculus Volume of a Sphere - Proof 2
ritvikmath
Multivariable Calculus Volume of a Sphere Proof - Triple Integrals
ritvikmath
Multivariable Calculus Volume of a Sphere Proof - Double Integrals
ritvikmath
The Euclidian Algorithm
ritvikmath
Proving the Chain Rule
ritvikmath
Proving the Fundamental Theorem of Calculus Part 1
ritvikmath
Proving the Fundamental Theorem of Calculus Part 2
ritvikmath
Math Puzzle - Poison Perplexity
ritvikmath
Math Puzzle - Poison Perplexity - Solution
ritvikmath
Expected Value and Variance of Continuous Random Variables (Calculus)
ritvikmath
Expected Value and Variance of Discrete Random Variables (No Calculus)
ritvikmath
Array Method
ritvikmath
Complex Power Series and their Derivatives
ritvikmath
Distributions - Intro
ritvikmath
The Poisson Distribution
ritvikmath
The Bernoulli Distribution
ritvikmath
The Binomial Distribution
ritvikmath
The Continuous Uniform Distribution
ritvikmath
The Geometric Distribution
ritvikmath
The Triangular Distribution
ritvikmath
The Exponential Distribution
ritvikmath
The Borel Distribution + Notes on Poisson Distribution
ritvikmath
The Gamma Distribution
ritvikmath
The Normal Distribution
ritvikmath
The Laplace Distribution
ritvikmath
The Chi - Squared Distribution
ritvikmath
Overfitting
ritvikmath
Vector Norms
ritvikmath
Truths Behind the Titanic : K-Nearest Neighbor
ritvikmath
The Mathematics of Breakups
ritvikmath
Sillyfish
ritvikmath
Finding Optimal Paths - Dynamic Programming
ritvikmath
HowToDataScience : Scraping Twitter Data
ritvikmath
Decision Trees
ritvikmath
Perceptron
ritvikmath
Naive Bayes
ritvikmath
K-Nearest Neighbor
ritvikmath
Evaluating Machine Learning Models
ritvikmath
Decision Tree Pruning
ritvikmath
K-Means Clustering
ritvikmath
Gaussian Mixture Model
ritvikmath
Data Science - Fuzzy Record Matching
ritvikmath
Time Series Talk : Autocorrelation and Partial Autocorrelation
ritvikmath
Time Series Talk : Autoregressive Model
ritvikmath
Time Series Talk : Moving Average Model
ritvikmath
Time Series Talk : ARMA Model
ritvikmath
Time Series Talk : ARCH Model
ritvikmath
Time Series Talk : White Noise
ritvikmath
Time Series Talk : Stationarity
ritvikmath
Time Series Talk : ARIMA Model
ritvikmath
Time Series Talk : Lag Operator
ritvikmath
Time Series Talk : What is Seasonality ?
ritvikmath
Time Series Talk : Seasonal ARIMA Model
ritvikmath
So ... What Actually is a Matrix ? : Data Science Basics
ritvikmath
Derivative of a Matrix : Data Science Basics
ritvikmath
Basics of PCA (Principal Component Analysis) : Data Science Concepts
ritvikmath
Eigenvalues & Eigenvectors : Data Science Basics
ritvikmath
The Covariance Matrix : Data Science Basics
ritvikmath
More on: SQL Analytics
View skill →Related AI Lessons
⚡
⚡
⚡
⚡
When AI Asks for More Electricity Than a Country Can Imagine
Medium · AI
You Are Not Behind. The World Is.
Medium · AI
Career choice with the advent of AI - pure Computer Science or learn software with a background of core engineering area
Dev.to AI
The AI Hype Cycle: Calm Before the Next Breakthrough?
Medium · Programming
🎓
Tutor Explanation
DeepCamp AI