SQL Basics: Start with SQL
In this tutorial we’ll be starting with SQL and learning basics. I’ll be using MYSQL workbench 6.3 for the tutorial.
SQL is NOT case sensitive: select is the same as SELECT. We can write our queries in either upper case or lower case or in both of them.
Creating a Table
We’ll be start with the table. Using the following query the table can be created in the database.
create table new_table (
column1 type,
column2 type
. . .)
We can see in the following image that a blank table ‘new_table’ created with 4 columns.
Inserting the values
After creating the table the we’ll learn to insert the values in this table.
INSERT INTO TABLE_NAME(column1, column2,column3,......)
Values (Value1, value2, value3,.....),
(ValueA, valueB, valueC,.....)
But be careful while inserting the value, it must be according to the column type like integer to integer and text to text ans so on…..
As you can see the added values in the image below.
Adding a New column in the existing Table
Now suppose you want to add columns to the existing table. We can add using following query and in the image we can see that the ‘column5’ is added to the table.
ALTER TABLE Table_name ADD column_name type;
Deleting a Column from a Table
Sometimes we need to delete a column from the table. We can do using the following queries. I have deleted the ‘column3’ which can be seen in image.
ALTER TABLE table_name
DROP COLUMN column_name;
Deleting the Table
And finally to delete the table use:
DROP TABLE table_name
and that’s it for the basics keep visiting for more tutorials.