so welcome back everyone to this yet another master class on my sequel so in today's session we will be covering out some of the statements which are very important in my sequel we will be like writing our first queries in MySQL we will understand how to create and manipulate tables right in tables we will understand how to define a table structure right and how to manipulate a table which means that how to add a column delete a column rename a column and things like that after that we will cover uh in this case we will
not be covering select and limits in current session that we will leave for the next session because those are your DML commands data manipulation language commands we will cover in the next session in today's session we will focus our attention on covering only the data definition language commands what is a data definition language command I'll come to that in a second but just setting up the agenda for the day today's agenda is to understand what are the basic SQL statements how to manipulate tables in MySQL and how to uh you know Define the structure and
how to add columns rename columns and manipulate the definition of Any Given table in MySQL all right so let's begin so obviously you must be curious about what exactly are statements in MySQL so statements are nothing but the commands that you give to your underlying database to execute as I have mentioned in the last session that SQL is nothing but an tool which allows you to communicate with the underlying database right so whichever database you are using that database is going to store your data in a relational format in the last session we have already
covered what is exactly a relational database in a relational database the tables so the data is stored in the format of tables and what are tables tables are nothing but a data structure in which data is present in rows and columns format so a statement is nothing but a command that allows you to interact with the data which you have stored in that relational database all right so how do you instruct MySQL to basically execute any state any command that you have you write your statement that you want to execute with that so statements are
nothing but the set of commands or instructions that you give to your underlying database so the first before starting off with the statements I would like to give you a categorizations on based upon the nature of the statement so in my sequel the statements are broadly divided into three categories one is called ddl commands which are called Data definition language commands right so this it stands for ddl or data definition language commands then we have DML commands or data manipulation language commands and finally we have DCL commands or data control language commands so what are
ddl commands ddl commands as the name suggests are the commands which allows you to give a definition of your data so whenever you have a command that allows you to Define your data so commands like create alter truncate delete okay so these are the commands that allow you to define the definition of the language so with the help of create command we have already seen in the last session how you can use create to create a new database similarly we can use create command to create a new table you can use create commands to create
a new constraint and whatever you want to create additionally for a database that you can do using the create command so create is a data definition language command because it allows you to create a definition or define the definition of your database and when I say definition what I mean by a definition is what are the names of a database and the tables what are the names of the columns what are the constraints on the columns what type of values are stored in the columns right what columns you want to add what columns you want
to drop so everything that you are doing right now you are basically changing the definition of your data so therefore these set of commands which allow you to manipulate the definition of the data are called Data definition language commands or ddl commands the next type of commands are called DML commands or data manipulation language commands or DML data manipulation language and as the name suggests these commands are used to manipulate the data which is available in any table so what you mean by manipulation manipulation means that let's say you want to add new rows to
a table you want to update some existing rows in a table you want to select data from the table you want to delete rows from a table right so all these are essentially your manipulation activities that you are doing on the underlying data and the set of commands which allow you to manipulate your data as per your choice are called Data manipulation language commands and the third set of commands are called Data control language commands and these commands allow you to give or you can say control the data which is available and when I say
control means basically allowing somebody access to the data right revoking somebody's access things like that so these com these set of commands allow you to take control of whatever data you have stored in that table right so with the help of them you can provide access to somebody on the database or you can revoke somebody's access on the database and in all you are essentially trying to control who is able to access that data which is stored in that database so data control language allow you to control access to the database that you want to
or do not want to give to a person so broadly speaking these are the three categories of commands that we have in my SQL in today's session we will be focusing our attention to understand the data definition language commands or TDL commands so the First ddl Command that we will cover is called create table command now this name might already give you a hint towards what it is used for create table commands is used to create a new table in a database so whenever you have a blank database or you are just starting to work
on defining the database and the tables in it obviously once you have created your database you want to populate that database with tables otherwise what is the point of creating the database in the first place so here create table command is used to create a new table in a database talking about the syntax in this case whenever you want to create a table you can see here in the top left corner a bottom left corner of the screen in this case you can see that the first two keywords here should be create and table so
whenever you want to create a new table the first two keywords are create table then after that this next set of commands which is if not exists it's optional this is there to check if you have already created a similar table or not because in the last session I have said this that in MySQL you cannot create two entities of the same name right so you cannot create two database with exact same name you cannot create two tables with the exact same name you cannot create two columns with the same name you cannot create two
constraints with the same nothing in my sequel can have duplicate names so therefore this syntax or this set of check which you are applying which is if not exists it will check whether this particular command that you are executing this table which you are creating if it is already present in the database or not so if it is already present in the database it will throw you a warning by saying that this table is already there kindly don't create a table with the same name right so you should not be creating a table with the
same name so this is optional obviously if you don't give this if not exists command and you still execute a command wherein you are creating a duplicate table then MySQL will throw you an error straightforward so after writing the create table and an optional check on whether the table exists or not then we provide the table name here you can see the table name can be a set of alphanumeric characters in this case please remember that you are not allowed to use any special character here and other than underscore so whenever you create a table
name you are only allowed to use underscore as a special character apart from that no other special character is allowed to be used so whatever table name you want to give if that table name contains more than two tokens or more than two words you can either omit the use of underscore altogether if you are fine with that but if you want to use a delimiter between the words you cannot uh you you you have to use underscore as the delimiter if you want to use any other delimiter then there is another way of doing
it which I will show you in the Hands-On session right so after you have created the table name then comes the providing the list of columns that you want to create in that table obviously as I mentioned here we are defining the schema of the table remember in the last session I had used this term that here in the create table command you define the table schema and in the table schema we basically after giving the table name we write which columns we want to add so what are the column names that we want to
add in this table what are the data type of the data which you are storing in that column so your data type could be string integers fractional values Boolean values Etc right so your data type will Define what type of value you will store in that column and finally you will Define what are the constraints you want to impose on any given column in the last session I have already given you a hint about what exactly are constraints so constraints are nothing but some mandatory checks that you want to impose on any given column so
let's say constraints like not null which will allow you to make sure that no values in that column is null or you can also give a constraint like default so a default constraint will basically make sure that if somebody has missed out on giving a value to a column then that default value will be put in that in that place so if somebody accidentally missed writing the value for a particular column then a default value will be used in place of that column so these are some of the constraints that you can put on top
of the table names right and here after writing the column and the data type of the column you can also write the constraints that you want to impose on them right so this is basically how you structure your create table command let me quickly show it to you in MySQL as well just give me a second let me share my screen all right so here we are in MySQL workbench already I already have introduced you to mySQL workbench in the last session and in this way we are basically going to practice how to create and
manipulate tables and columns in MySQL right now so as you can see over here I am in my uh this is the connection which I have established locally so there is we are working in my current local system and in this case what am I doing first I am simply creating a database right now so here you can see I am creating a database here the name of the database is temp DB indicating that this is just a temporary database that I'm creating for my system here you can see I'm just increasing the font size
elected so I am creating a temporary database here and if you can see here I once I click on this execute button here it will execute my command and here you can see if I refresh it this time DB has been created on the uh on the left hand side panel these are all the databases that are there on my system so this 10 10 DB has just been created by me then once a database has been created as I have mentioned in the last class you have to let MySQL know which database you want
to execute your queries on so out of these seven databases that I have on my system I have to tell MySQL on which database do I have to execute the queries that I am going to run because otherwise MySQL will not be able to understand on what database you are trying to run these queries so here with the help of use command we specify on which database we want to run these queries and here you can see as soon as I executed this command the temp database here has been highlighted indicating that this is the
database which is going to be used going forward right so now let's use the create table command here right so here I am going to execute my create table command in this create table command here you can see I am starting my command with the two keywords which I had mentioned previously the first keyword was create then you have a table that is we are going to create our table right now I am not specifying if not exists but if you want you can write it as well so it's just a check which basically ensures
that the same table is not getting created twice so here if not exists we'll check if you already have a table name students in your database or not currently if you see this database is completely blank so we don't have a table called students in our database so we won't be getting any warning and here you can see I am writing my table name so my table name is a student's table I'm just creating a student stable over here now as I had mentioned the way you create a table name is basically if you are
not uh using any special character or you can so in this case if you write if you want to write a table name like we had written that is you don't want to enclose it between any string characters then you only have a couple of options right so you can either write a name in one single stretch or in this case you can use an underscore as a delimiter right so you can use underscore as a delimiter apart from underscore if you want to use any other syntax let's say now you want to use space
as a delimiter so right now if you use space as a delimiter what is happen is that you will get an error right so here you can see as if I run this command over here one second if I execute this you will see that I will get a syntax error at the bottom so here you can see my last command which I had executed this x this command is giving me a syntax error right so you can clearly read this error here which is saying you have an error in SQL syntax and why is
this incorrect this is incorrect because right now in this particular format so what's my SQL is considering is that your table name is student but data is being treated as yet another command and this is not a correct SQL statement because this is syntactically not a correct SQL statement so if you want to create a table name which has student space data as the name in that case you have to enclose it between these special characters called back ticks so these are basically like consider them to be your uh MySQL way of letting it know
that this is a complete single unit right so in this case whatever you are enclosing between these backticks by the way these special characters are available on top of your keyboard here so just below Escape key there is a special character called tilde right so in in that special character itself you will find another character which is back tick so on your keyboard it is available just above the tab key or just below the Escape key so this is basically available over there and if you enclose anything in between these two ticks MySQL will consider
this entire set of characters at one single unit and it will treat it as a normal string operation right so it will not treat it as any SQL command it will just treat it as a normal name for any entity that you are assigning it to so this will consider it to be a normal name that you are giving so now if I run this you will see that here no uh no error will come so here you can see there is no error which is coming and if I refresh this particular uh set here
you can see a table has been created and the name of this table is student data all right so here you can see this table has been created with the name of student data earlier on it was not getting created because we were we were not specifying these backticks because of which SQL was thinking that your table name is student but there is yet another command that you are giving called data which is not syntactically correct in this particular create table command so therefore you will get a error immediately over there all right so after
that you can see once I have given my table name then I am specifying The Columns that I want to keep in these tables the First Column is rule number here you can see this is as I said you can use underscore as a delimiter directly you don't have to enclose it between back text after that I am specifying the type of the values which I am storing in these columns here you can see I am specifying type as big integers in MySQL there are multiple type of numerical data types that you can use big
integer is often used when you want to store big integers in any given columns right so as the name suggests whenever your column has requirement to store huge integers in it then you are going to use big integers as the real type they are integers available as well here you can see in age column I am using the normal integer but the sometimes what happens is that the amount of space which is allocated for each integer I think it's only 4 bytes so if any integer requires more than four bytes of memory then it will
not properly be stored in the Square case so therefore we use big integer in its place because big integers allows us to store much bigger integers which cannot be stored in four bytes so so here you can see sometimes depending upon the type you can you need to use some other uh you can say variations of the same data type so here the column name was roll number then I specified the type of the value and finally I am specifying a constraint of primary key so primary key is a constraint which specifies that this roll
number column will be my primary key of this table I have not yet discussed in detail what exactly is a primary and a foreign key that we will cover in the following videos but just to quickly give you a overview of what is what is this so a primary key whenever you impose a constraint of primary key it makes sure that no value in this column is duplicate right so whenever you keep a constraint of primary key in any column it makes sure that there is no duplicate value in this column and there are no
null values in this column as well so by default a primary key constraints applies two constraints the first constraint which it applies is to ensure that no value is duplicate in this column because we know that no two students should have the same roll number so therefore it will first apply a constraint of unique which will make sure that all values in this column are unique and secondly it will apply another constraint which will check that no value in this column should be null so these two constraints will be automatically applied on this roll number
column by applying one single constraint of primary key after that I am using creating another column called name so this will store the name of a student here you will find that I am enclosing them I mean closing these in back ticks now why am I enclosing them in backpacks because in my SQL name is essentially a function which is used by strings here you can see as soon as I remove the bat text this name is getting treated as a MySQL function so ideally if you don't want to avoid this mistake happening in the
syntax so what you can do if you want to avoid MySQL in interpreting any of the inbuilt functions here because obviously when you create a table name sometimes it might be required you to use a name which my SQL is already using for some purpose right so therefore as you can see here create table if not exists all of them are MySQL keywords which it uses to perform a operation and if you are doing or if you are using or creating some content which requires you to use these keywords then you will have to enclose
them in back text if you want to you know make sure that MySQL is not interpreting them as its own set of commands so if you enclose them in back text then they will be treated as normal string values like this roll number age and gender right so it will not treat them as any SQL keyword rather it will just take it as a normal column attribute name which you are giving it to this particular column so this is the column name and we are specifying the data type of this column this data type is
variable character meaning that the name will be a a data type which can hold variable number of characters your characters means any alphanumeric special whatever characters you want to give right because your name could contain anything right so therefore here you have a variable character and in Brackets you specify what is the maximum length of this variable character so in this particular case we are limiting the number of characters in a name to 20 because we don't want to you know give too much Headroom to anybody to to you know keep on utilizing the characters
we want to control the size of the columns as well so therefore we are limiting the number of characters in a column to 20 only so in this case if you have more than 20 characters in a name then it will only truncate it to the first 20 characters so in case if somebody has more than 20 characters in that case it will just truncate the number of characters to 20 only it will not exceed Beyond 20. the third column here is integer age which is of integer type obviously in age of a person is
an integers then we have gender so gender usually requires only one character to be specified M for male f for female right so therefore we are the data type which we are specifying here we are using character data type and the number of characters which we will use here is only one single character so for every unit for every value in this column we will only use one character to specify its value so it might be M it might be f it might be T right so for some third gender so therefore here you can
see gender is specified using character over here and finally Hobbies is another variable character column because a person can have variable number of copies so we want to give a slightly more Headroom here to somebody who wants to ink keep a list of more number of hobbies so we are specifying 50 characters here which means a person has 50 characters to create a list of all of his or her Hobbies and once you can see that here this is basically we have defined the entire table schema please remember one thing that after writing the table
name the columns and the constraints and everything should go Within These circular brackets so here these round brackets are mandatory so after writing create table and table name you have to mention these round brackets and Within These round brackets you will specify the column names and constraints and the type of the columns and between each pair of value there should be a comma right so here there should be a comma after the end of each column definition after you have defined the First Column write a comma then write other definition then third and it is
not mandatory that you have to write everything in new line no if you want you can give this entire command in one single line I have written it like this because it makes it much easier on the I to read right if I had written this entire command in one single line then it would become very difficult for somebody to read and keep in memory the entire thing which has happened so just to make it aesthetically more easy to read so therefore I have just divided this command across multiple lines but it is not at
all mandatory to do it if you want you can write the entire command in one single line what all things are mandatory I have already specified that is these round brackets are mandatory then you have to keep a comma in between every successive um column definition and finally once you are entire command is complete once you have written the command then you have to terminate a command with a semicolon right so after each command you have to write a semicolon a semicolon whenever you write a semicolon it basically tells MySQL that this command is complete
and then you can execute everything which is basically just before this semicolon so here you can see from here till here is our create table command right and this create table command will immediately create a student data here so this is the table which we have created in this table we have these columns which you can see one by one this is roll number name age gender and hobbies so if you click on any column you will get some definitions or you can say what are the constraints and what all uh properties are applied to
each column so here you can see roll number the definition is of rule number and it is a primary key column that's why it has PK written against it this is a big integer which has 20 characters so if you want to know any additional information about a column then in that case you can simply click on it and it will tell you about what is the type of the value which is stored in it right so here the bottom is basically some information tab so this this tab here tells you some information about any
entity which you have clicked on so here you can see this is a schema of temporary TV hope it's clear right so next we will move on to the next command that we have to discuss one second let me share the screen next we want to discuss the another command which is called truncate table command now as the name suggests a truncate table command is used to truncate the data which is present in a table so whenever you have created a table but you want to empty that table completely right that is you want to
delete the entire data which is available in that table so a truncate table command is used to truncate the data inside a table but not the table itself right so in this particular case here you can see the syntax is pretty straightforward the Syntax for truncate table command is to write the truncate table keyword and table name which you want to truncate so let me quickly tell you about this as well so let me share that ice equals screen back so in this case since we currently don't have any data in the students data table
so I am going to truncate another table which is there in my system so for that table I am going to use the company DB database because the table which I want to truncate it is present in this company DB database so therefore I have to first let MySQL know that the following commands will be executed on the company DB database so therefore I am executing this command and as soon as I execute it you will find that company DB database has been highlighted over here now the table which I'll truncate is this table here
you can see this table has been truncated so now if I again print the output of this table what will happen is that this table content will not be there so here you can see all the rows in this table are blank right now and why that has happened because we have truncated this table so a truncate table command will basically empty the content of a table without deleting the table itself right so it will delete the contents of the table without deleting the table itself and if you want to delete the table directly then
you have to use the drop table command all right so in this case if you want to let's say now drop the table directly right so if you want to drop the table itself for dropping the table you have to use drop table and table name let's say you want to drop this works on table if I run this what will happen now that works on table itself is deleted from my company DB database so here if you take a look here there is no works on table now so depending upon what you want to
do you can you have multiple options here the first option is basically if you want to just delete the data in the table then you will use the truncate command so just specify truncate and the table name that you want to truncate and that will only delete the contents of that table without changing or deleting the table definition and if you want to delete the entire table along with its content then you will use drop table command so drop table command will delete the table data as well plus the entire table so when you delete
the table obviously you are deleting the definition as well as the data of that table also so drop table will drop the complete table from your database entirely all right so that was how you can basically manipulate the contents in a table either you can drop a table or drop just the content of that table now let's look at another data definition language command which is called alter table command and as the name suggests alter table command is used to alter the definition of any existing table so when I say alter what operations are allowed
here so operations like adding new columns or dropping existing columns or modifying the data type of existing columns or renaming columns renaming tables so all these operations that I just mentioned in these operations you are altering the existing tables directly so that's why the the command goes like alter table and with the alter table command you can use Simple alter table commands to do a bunch of things which I just now mentioned so we will take a look at each and every one of these operations one by one but the idea of alter table command
is to allow you to alter the existing table that you have present in your database that is the primary use of alter table command so first operation that we will use for alter table is to add a new column in the table all right so in the alter table command you can you have to specify or you can use it to add a new column in a table in this case there are some parameters that you want to give obviously whenever we add a new column you have to specify firstly what table you want to
alter so the table name is one parameter that you have to specify which is the first one which table you want to alter then what is the column name that you want to add so obviously if you are adding any new column you have to assign a name to that column like we do at the definition of that table so when we Define the table there also we all have to give a column name to each column so here also if you are adding externally a new column then also you have to specify a new
column name for that column after that comes the column definition in column definition you include the data type of the values in that column and the constraints that you have to apply on that column similarly how you had done in the table schema creation phase right so there also we have defined the column name the data type and the constraints here also if you have to add a new column then you have to specify the column name the column uh data type and the constraints if you want to apply any constraints there right so then
comes the constraints and finally you can even specify the location where you have to add this column let's say you want to add this column first so it will basically append that column and make it the First Column of that table or let's say you want to add a column after a specific column let's say you already have a column called first name and want to add a new column called last name so obviously first name and last name these two columns should always come one after the other like so speaking from the perspective of
a user it will make much more sense if these two columns came just one after the next so now imagine that you already have a column of first name in your table and you want to add a new column of last name so here you can specify that okay add this new column after first name column so that MySQL will actually insert that column just next to the first name column so adding a column you have these many parameters that you can work around with so let me go back to my SQL workbench and let's
practice this command this way so here you can see uh I'm again going back to the temporary DB to just manipulate the data which is available in tempdb so here I am again working on the temp database which I had created now I will first show you how to add a new column in a table so here you can see alter table Command right so in this case first I'll show you how to add just one single column at a time so here I'll write first alter table command after alter table command you will have
to write the table name that you want to alter in this case the table name that we are altering is actually student data that's because I just had changed it previously when you write the add column keyword because after you write that you want to alter a table you have to write the operation that you want to execute in this alter table command So currently the operation that we are executing is to add a new column in this table so in this case in the student data table we already have these columns we have roll
number name age gender and hobbies we already have these columns available so let's add a new column here and that new column could be your uh let's say uh your hometown right so let's add a new column called Hometown in the student and here you can see I have specified the column name after the column name I'll specify the type of the value so this will be a variable character let's say the maximum length of a town can be of 10 characters so I'll specify the length here to be variable characters of 10 length and
now if I want to write any constraints I can write the constraints that I want let's say there is one constraint called not null this not null constraint will ensure that no value in this column is null right now we don't want to impose such a constraint anywhere so I'll just remove it from here but here you can see these are the columns that I have written and after that you can specify where you want to insert this so let's say you want to insert it after age column so in this case what it will
do it will alter this table call student data it will add a new column of hometown whose data type here is of variable character and it will insert this column after my age column so if I execute this command here and if I refresh this schema here so you will see that immediately after age there is a new column inserted called hometown if you had not specified this particular command here towards the end then it would have inserted it towards the last so the default insertion happens towards the end but here since we have specified
that I want to insert this column immediately after the age column so it will come here and insert Hometown immediately after the age column so this is how you insert one column at a time so if you want to insert one column at a time simply come here write the alter table then table name that you want to alter then specify what column you want to add and the definition of that entire column and if you want you can even break it down across multiple lines it's completely optional right so if you want to make
it more easily readable then simply break your commands down logically across multiple lines so that the end user can have a much easier time reading your query next you can also add multiple columns at a time it's not like you have to run this query each time you want to add a new column if you want you already have a list of columns that you want to add in one single shot then you can also do that the initial syntax Remains the Same that is you will write the table name and the here you can
see that the table name will be student data so I am again going to change it here I am going to alter my student data table and this time instead of just adding one column at a time I am going to add two columns here the First Column here that I'm adding here is basically emergency contact the data type of which is variable character 20 length and second is address what is the current address of the student so here you can see when you want to add multiple columns again you have to use round brackets
so inside round brackets you have to write your uh the definition of that entire columns that you are adding similar to how you had done in create table command here also we did the same thing bit down also you will have to repeat the same way if you want to add multiple columns in a table so if you want to add multiple columns after alter table command write within these lists here just write a comma separate values of column definitions one by one so if I run this particular command now so what happen is this
time you will find that two more columns will be added but this time these columns will be added towards the bottom so emergency contact and address has been added all right so this is the first use case of alter table command and this use case is to add new columns to an existing table next let's talk about another use case which is to rename a particular table or not rename a table or change the data type of an existing table so I have already explained how to add multiple columns so now let's modify a particular
column in a table let's say you have a column call address in that address column you have currently specified that a student is only allowed to input an address of 50 characters long but sometimes uh what is happening is that some people have a longer address and you cannot afford to you know truncate an address column because obviously if you don't have a complete address of a person during time of emergencies it will become extremely difficult to track that locations right so therefore you want to change the data type of an existing column all right
so therefore what we can do here we can change the definition with the help of the modify command here so modify column allows you to modify the definition of an existing column and when I say definition I mean by definition is that what is the data type and what are the constraints that are applied on the column so if you already have an existing column in your table and you want to modify the definition of that existing column that is where you will use the modify column command let me show that in MySQL again so
if I come back to this table here you can see that again I'm going back to students data table right and this time I am going to modify my address column right so previously I had specified this address column to have at Max 30 characters but let's say now I find that 30 characters are not going to be enough I want to increase the limit to some other value so I will change the data type of this column by specifying here the column name so the syntax is pretty straightforward you write the alter table and
the table name then you write the modify keyword and what you want to modify you want to modify the address column here so I will write the address column over here and then simply specify the data type of the column that you want to change to so in this case I want to change it to a variable character with maximum 50 characters this time right this will give you a lot more Headroom to work with so if I run this now right and I refresh this column here so now what will happen if you get
a look at address this time so address now has variable character length of 50 units earlier on it had 30 characters now it has changed its type to 50 characters now the next implementation that you want to discuss is to rename columns in tables so just like how you have a currently added columns and modified their definition if you are unhappy with a column name you can even use rename column command to rename the column name to some other value so this will not change the definition if you want you can change the definition as
well so in this case here you have options available that is when you are renaming so renaming is like basically deleting an old column and creating a new column using the values from the old column so whenever you create a new column here or you rename a column what you will find is that when you rename it you are also allowed to change the definition of that column as well so let me show it to you by practicing only right so let me go back to our MySQL workbench and there I'll showcase how you can
rename an existing column in a table as well so if you take a look here I am specifying the alter table Command right so here you can see uh the syntax is Alter table then the table name here again I have to change it to student data sorry for this now I will alter this table here called student data and now comes the part wherein I'll specify how to rename a column so when you rename a column the command which you will use is change column right so the way you are allowed to rename a
column is to have you have to specify a command called change column so change column basically means that you will change an existing column to a new column so how it is done you basically write the change column command after the change column command you specify which column you want to change So currently I want to change my emergency contact column let's say I want to rename it to some other value so I will specify the column name which is emergency contact and the new column definition that I want to change it to so in
this case I want to change it to a column called Contact which has variable character length of 10 units so instead of writing emergency contact I simply want to specify it as contact here and the length of this is variable characters of 10 units now so this will basically change the name here from emergency contact to simple contact over here and this will alter this particular table and change the or rename this column so by default you are not allowed to modify anything in place in MySQL so what will happen is that it will delete
the old column create a new column and copy the values from the old column to the new column all right that is how the the operation will work underneath so that is why the command name is different although you are doing the rename operations from your perspective but from sql's perspective the operation takes a couple series of steps to change its name that is it will create a new column with the specified type then it will copy the contents of the previous column to the new column and then it will delete the old column so
that is how rename column Works in between and that is how you can rename an existing column to some new value the last operation that we will discuss here is to alter the table and to rename an entire table itself so if you want you can even rename complete tables in MySQL so in order to rename tables you have option or a command to rename a table so here the syntax goes like this that is you write the alter table command then the old table name obviously right now if you've seen that I have been
renaming the table let's say I want to rename my old table from student data do some new value called student right now I just want to rename it to a new value call student so what it will do it will take this old database right sorry it will take this old table and just rename it to a same new table called student so when you want to rename a table you have a command called rename and the syntax is you write the rename to table name so what table name you want to rename it to
you run it and now if you refresh it you will find that the table has been renamed over here so you can see that earlier on this table name was student data now it has been renamed to students table right so I hope this is clear to everyone thank you