The UPDATE TABLE Statement in SQL : Data Science Code

ritvikmath · Intermediate ·📰 AI News & Updates ·6y ago

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 Math Team Update
Math Team Update
ritvikmath
2 Single Variable Calculus Volume of a Sphere - Proof 1
Single Variable Calculus Volume of a Sphere - Proof 1
ritvikmath
3 Single Variable Calculus Volume of a Sphere - Proof 2
Single Variable Calculus Volume of a Sphere - Proof 2
ritvikmath
4 Multivariable Calculus Volume of a Sphere Proof - Triple Integrals
Multivariable Calculus Volume of a Sphere Proof - Triple Integrals
ritvikmath
5 Multivariable Calculus Volume of a Sphere Proof - Double Integrals
Multivariable Calculus Volume of a Sphere Proof - Double Integrals
ritvikmath
6 The Euclidian Algorithm
The Euclidian Algorithm
ritvikmath
7 Proving the Chain Rule
Proving the Chain Rule
ritvikmath
8 Proving the Fundamental Theorem of Calculus Part 1
Proving the Fundamental Theorem of Calculus Part 1
ritvikmath
9 Proving the Fundamental Theorem of Calculus Part 2
Proving the Fundamental Theorem of Calculus Part 2
ritvikmath
10 Math Puzzle - Poison Perplexity
Math Puzzle - Poison Perplexity
ritvikmath
11 Math Puzzle - Poison Perplexity - Solution
Math Puzzle - Poison Perplexity - Solution
ritvikmath
12 Expected Value and Variance of Continuous Random Variables (Calculus)
Expected Value and Variance of Continuous Random Variables (Calculus)
ritvikmath
13 Expected Value and Variance of Discrete Random Variables (No Calculus)
Expected Value and Variance of Discrete Random Variables (No Calculus)
ritvikmath
14 Array Method
Array Method
ritvikmath
15 Complex Power Series and their Derivatives
Complex Power Series and their Derivatives
ritvikmath
16 Distributions - Intro
Distributions - Intro
ritvikmath
17 The Poisson Distribution
The Poisson Distribution
ritvikmath
18 The Bernoulli Distribution
The Bernoulli Distribution
ritvikmath
19 The Binomial Distribution
The Binomial Distribution
ritvikmath
20 The Continuous Uniform Distribution
The Continuous Uniform Distribution
ritvikmath
21 The Geometric Distribution
The Geometric Distribution
ritvikmath
22 The Triangular Distribution
The Triangular Distribution
ritvikmath
23 The Exponential Distribution
The Exponential Distribution
ritvikmath
24 The Borel Distribution + Notes on Poisson Distribution
The Borel Distribution + Notes on Poisson Distribution
ritvikmath
25 The Gamma Distribution
The Gamma Distribution
ritvikmath
26 The Normal Distribution
The Normal Distribution
ritvikmath
27 The Laplace Distribution
The Laplace Distribution
ritvikmath
28 The Chi - Squared Distribution
The Chi - Squared Distribution
ritvikmath
29 Overfitting
Overfitting
ritvikmath
30 Vector Norms
Vector Norms
ritvikmath
31 Truths Behind the Titanic : K-Nearest Neighbor
Truths Behind the Titanic : K-Nearest Neighbor
ritvikmath
32 The Mathematics of Breakups
The Mathematics of Breakups
ritvikmath
33 Sillyfish
Sillyfish
ritvikmath
34 Finding Optimal Paths - Dynamic Programming
Finding Optimal Paths - Dynamic Programming
ritvikmath
35 HowToDataScience : Scraping Twitter Data
HowToDataScience : Scraping Twitter Data
ritvikmath
36 Decision Trees
Decision Trees
ritvikmath
37 Perceptron
Perceptron
ritvikmath
38 Naive Bayes
Naive Bayes
ritvikmath
39 K-Nearest Neighbor
K-Nearest Neighbor
ritvikmath
40 Evaluating Machine Learning Models
Evaluating Machine Learning Models
ritvikmath
41 Decision Tree Pruning
Decision Tree Pruning
ritvikmath
42 K-Means Clustering
K-Means Clustering
ritvikmath
43 Gaussian Mixture Model
Gaussian Mixture Model
ritvikmath
44 Data Science - Fuzzy Record Matching
Data Science - Fuzzy Record Matching
ritvikmath
45 Time Series Talk : Autocorrelation and Partial Autocorrelation
Time Series Talk : Autocorrelation and Partial Autocorrelation
ritvikmath
46 Time Series Talk : Autoregressive Model
Time Series Talk : Autoregressive Model
ritvikmath
47 Time Series Talk : Moving Average Model
Time Series Talk : Moving Average Model
ritvikmath
48 Time Series Talk : ARMA Model
Time Series Talk : ARMA Model
ritvikmath
49 Time Series Talk : ARCH Model
Time Series Talk : ARCH Model
ritvikmath
50 Time Series Talk : White Noise
Time Series Talk : White Noise
ritvikmath
51 Time Series Talk : Stationarity
Time Series Talk : Stationarity
ritvikmath
52 Time Series Talk : ARIMA Model
Time Series Talk : ARIMA Model
ritvikmath
53 Time Series Talk : Lag Operator
Time Series Talk : Lag Operator
ritvikmath
54 Time Series Talk : What is Seasonality ?
Time Series Talk : What is Seasonality ?
ritvikmath
55 Time Series Talk : Seasonal ARIMA Model
Time Series Talk : Seasonal ARIMA Model
ritvikmath
56 So ... What Actually is a Matrix ? : Data Science Basics
So ... What Actually is a Matrix ? : Data Science Basics
ritvikmath
57 Derivative of a Matrix : Data Science Basics
Derivative of a Matrix : Data Science Basics
ritvikmath
58 Basics of PCA (Principal Component Analysis) : Data Science Concepts
Basics of PCA (Principal Component Analysis) : Data Science Concepts
ritvikmath
59 Eigenvalues & Eigenvectors : Data Science Basics
Eigenvalues & Eigenvectors : Data Science Basics
ritvikmath
60 The Covariance Matrix : Data Science Basics
The Covariance Matrix : Data Science Basics
ritvikmath

This video teaches how to use the ALTER TABLE and DROP TABLE statements in SQL to modify and manage database tables. It covers adding columns, renaming tables, and deleting tables, and provides examples of how to use these statements in a database.

Key Takeaways
  1. Use the ALTER TABLE statement to add a column to a table
  2. Use the ALTER TABLE statement to rename a table
  3. Use the DROP TABLE statement to delete a table
  4. Create a new table with desired columns and copy data from old table if needed
  5. Drop the old table and rename the new table
💡 The ALTER TABLE and DROP TABLE statements are powerful tools for managing database tables, but must be used carefully to avoid data loss or corruption.

Related AI Lessons

When AI Asks for More Electricity Than a Country Can Imagine
AI's increasing power consumption is causing concerns, learn why it matters for data centers and energy supply
Medium · AI
You Are Not Behind. The World Is.
You're not behind, the world is still adapting to AI, and it's okay to take your time to learn and grow
Medium · AI
Career choice with the advent of AI - pure Computer Science or learn software with a background of core engineering area
Learn how to choose between a Computer Science and Engineering career path or combining programming with a core engineering background in the age of AI
Dev.to AI
The AI Hype Cycle: Calm Before the Next Breakthrough?
Understand the AI hype cycle to anticipate the next breakthrough and make informed decisions
Medium · Programming
Up next
Motorist saved by human chain | 9 News Australia
9 News Australia
Watch →