Uploaded January 2016 | Updated September 2026, 2 weeks ago
mysql tutorial for beginners (4/8) : MySQL Syntax and Datatype
The commands you’ll use most often are a lot, I’ll cover most of these as we proceed, but first, you need to remember a couple of points about MySQL commands:
1- SQL commands and keywords are case-insensitive. CREATE in capital case, create in small case, and CrEaTe in random case, all mean the same thing. However, for the sake of clarity, the recommended style is to use uppercase.
2- Table names are case-sensitive on Linux and OS X, but case-insensitive on Windows. So for portability purposes, you should always choose a case and stick to it. The recommended style is to use lowercase for tables.
MySQL Data Types
-------------------------------
When creating a table in MySQL it is important to know the type you wish to use for each attribute.
The most common used data types:
----------------------------------------------------------
INT UNSIGNED : Makes the column take an integer,
large enough for you to store more than 4 billion records in the table.
NOT NULL : Ensures that every column has a value.
Many programmers use NULL in a field to indicate that it doesn’t have any value.
But that would allow duplicates, which would violate the whole reason for this column’s existence. So we disallow NULL values.
AUTO_INCREMENT: Causes MySQL to set a unique value for this column in every row. We don’t really have control over the value that this column will take in each row, but we don’t care: all we care about is that we are guaranteed a unique value.
KEY : An auto-increment column is useful as a key, because you will tend to search for rows based on this column.
Each entry in the column Assigned Auto-Increment data type will now have a unique number, with the first starting at 1 and the others counting upward from there.
UNIQUE (column_name, ...)-used to specify which fields are unique
Primary keys
----------------------
The importance of having a key with a unique value for each row will come up when we start to combine data from different tables. “The AUTO_INCREMENT data type introduced the idea of a primary key when creating the auto-incrementing column, which could have been used as a primary key
Creating a database:
----------------------------------
To create new database, use the following command:
CREATE DATABASE the database name is examSystem;
Now that you’ve created the database, you want to work with it, so issue the following command:
USE examSystem;
Creating users:
------------------------
So let’s create a user who can access just the new examSystem database and all its objects, by entering the following command:
GRANT ALL ON examSystem.* TO 'Safaa'@'localhost'
IDENTIFIED BY ‘mypassword';
What this does is allow the user Safaa full access to the examSystem database using the password mypasswd.
Creating a table:
--------------------------
At this point, you should now be logged into MySQL with ALL privileges granted for the database examSystem, so you’re ready to create your first table.
Make sure the correct database is in use by typing the following:
USE examSystem;
Let’s create students table, by typing the following command:
CREATE TABLE students,
Open parentheses,
The first column in the table students,
'id_student' specify the data type for this field to be SMALLINT UNSIGNED NOT NULL
AUTO_INCREMENT, to add new column, you need to separate them by coma,
'name' VARCHAR(lO) NOT NULL,
'surname' VARCHAR(20) NOT NULL,
'email' VARCHAR(30) NOT NULL,
You need to make one column primary key, and that will be id_student
PRIMARY KEY ('id_student'),
Email values must be unique values, then you need to use Unique data type for email field:
UNIQUE ('email'))
engine = InnoDB COMMENT = 'Super table';
The engine field at the end is not really necessary, but you should include it to force the type of table you are creating.
The COMMENT field is just an example of how you would insert a comment for a created table.
To check whether your new table has been created, type the following:
DESCRIBE student;
You can also use DESCRIBE command to remind yourself about a table’s field and the types of data in each one.
Table students has been created! But, it’s empty, so, on the next tutorial we will learn how to insert, update and delete data.
Subscribe for more:
----------------------------------------------------------------------------
youtube.com/subscription_center?add_user=saf3al2a
SWE.Safaa Al-Hayali - saf3al2a
mysql tutorial for beginners (4/8) : MySQL Syntax and Datatype
The commands you’ll use most often are a lot, I’ll cover most of these as we proceed, but first, you need to remember a couple of points about MySQL commands:
1- SQL commands and keywords are case-insensitive. CREATE in capital case, create in small case, and CrEaTe in random case, all mean the same thing. However, for the sake of clarity, the recommended style is to use uppercase.
2- Table names are case-sensitive on Linux and OS X, but case-insensitive on Windows. So for portability purposes, you should always choose a case and stick to it. The recommended style is to use lowercase for tables.
MySQL Data Types
-------------------------------
When creating a table in MySQL it is important to know the type you wish to use for each attribute.
The most common used data types:
----------------------------------------------------------
INT UNSIGNED : Makes the column take an integer,
large enough for you to store more than 4 billion records in the table.
NOT NULL : Ensures that every column has a value.
Many programmers use NULL in a field to indicate that it doesn’t have any value.
But that would allow duplicates, which would violate the whole reason for this column’s existence. So we disallow NULL values.
AUTO_INCREMENT: Causes MySQL to set a unique value for this column in every row. We don’t really have control over the value that this column will take in each row, but we don’t care: all we care about is that we are guaranteed a unique value.
KEY : An auto-increment column is useful as a key, because you will tend to search for rows based on this column.
Each entry in the column Assigned Auto-Increment data type will now have a unique number, with the first starting at 1 and the others counting upward from there.
UNIQUE (column_name, ...)-used to specify which fields are unique
Primary keys
----------------------
The importance of having a key with a unique value for each row will come up when we start to combine data from different tables. “The AUTO_INCREMENT data type introduced the idea of a primary key when creating the auto-incrementing column, which could have been used as a primary key
Creating a database:
----------------------------------
To create new database, use the following command:
CREATE DATABASE the database name is examSystem;
Now that you’ve created the database, you want to work with it, so issue the following command:
USE examSystem;
Creating users:
------------------------
So let’s create a user who can access just the new examSystem database and all its objects, by entering the following command:
GRANT ALL ON examSystem.* TO 'Safaa'@'localhost'
IDENTIFIED BY ‘mypassword';
What this does is allow the user Safaa full access to the examSystem database using the password mypasswd.
Creating a table:
--------------------------
At this point, you should now be logged into MySQL with ALL privileges granted for the database examSystem, so you’re ready to create your first table.
Make sure the correct database is in use by typing the following:
USE examSystem;
Let’s create students table, by typing the following command:
CREATE TABLE students,
Open parentheses,
The first column in the table students,
'id_student' specify the data type for this field to be SMALLINT UNSIGNED NOT NULL
AUTO_INCREMENT, to add new column, you need to separate them by coma,
'name' VARCHAR(lO) NOT NULL,
'surname' VARCHAR(20) NOT NULL,
'email' VARCHAR(30) NOT NULL,
You need to make one column primary key, and that will be id_student
PRIMARY KEY ('id_student'),
Email values must be unique values, then you need to use Unique data type for email field:
UNIQUE ('email'))
engine = InnoDB COMMENT = 'Super table';
The engine field at the end is not really necessary, but you should include it to force the type of table you are creating.
The COMMENT field is just an example of how you would insert a comment for a created table.
To check whether your new table has been created, type the following:
DESCRIBE student;
You can also use DESCRIBE command to remind yourself about a table’s field and the types of data in each one.
Table students has been created! But, it’s empty, so, on the next tutorial we will learn how to insert, update and delete data.
Subscribe for more:
----------------------------------------------------------------------------
youtube.com/subscription_center?add_user=saf3al2a
SWE.Safaa Al-Hayali - saf3al2a





![python tutorial for beginners #3: variables and datatype in python
python tutorial for beginners #3: variables and datatype in python
A variable is a name in source code that is associated with an area in memory that you can use to store data, which is then called upon throughout the code.
We create a variable by writing the name of the variable we want followed by an equal’s sign, which is followed by the value we want to store in the variable.
The data can be one of many types, including:
Integer, that Stores whole numbers
hello_int = 21
Float data type: Stores decimal numbers
hello_float = 1.3
Boolean data type can have a value of True or False
hello_bool = True
String data type stores a collection of characters. “Hello
World” is a string
hello_str = “Hello World!”
As well as these main data types, there are sequence types
List data type contains a collection of data in a specific order
hello_list = [“Hello,”, “this”, “is”, “list”]
You could also create the same list in the following way
hello_list = list()
hello_list.append(“Hello,”)
hello_list.append(“this”)
hello_list.append(“is”)
hello_list.append(“list”)
The first line creates an empty list and the following lines use the append function of the list type to add elements to the list.
It can be useful when working with dynamic data such as user input.
Tuple data type, contains a collection immutable data in a specific order.
hello_tuple = (1991, 77)
The data stored in a tuple is immutable because you aren’t able to change values of individual elements in a tuple. However, you can do so in a list.
It will also be useful to know about Python’s dictionary type.
A dictionary is a mapped data type. It stores data in key-value pairs.
hello_dict = { “first_name” : “Safaa”,
“last_name” : “Alaa”,
“eye_colour” : “Brown” }
This means that you access values stored in the dictionary using that value’s corresponding key,
print(hello_dict[“first_name”] + “ “ + hello_dict[“last_name”] + “ has “ + hello_dict[“eye_colour”] + “ eyes.”)
Which is different to how you would do it with a list.
In a list, you would access an element of the list using that element’s index, index it just a number representing the element’s position in the list).
Indexes in Python are zero-based, which means the first element has an index of 0.
print(hello_list[3])
We’ll start by changing the value of the last string in our hello_list and add an exclamation mark to the end.
hello_list[3] += “!”
print(hello_list[3])
In tuple, we can’t change the value of those elements like we just did with the list
print(hello_tuple[0])
Let’s create a sentence using the data in our hello_dict
A tidier way of doing this would be to use Python’s string formatter
print(“{0} {1} has {2} eyes.”.format(hello_dict[“fi rst_name”],
hello_dict[“last_name”],
hello_dict[“eye_colour”]))
“Any text in a Python file that follows a # character will be ignored”
Subscribe for more:
https://www.youtube.com/subscription_center?add_user=saf3al2a
SWE.Safaa Al-Hayali - saf3al2a python tutorial for beginners #3: variables and datatype in python](https://i.ytimg.com/vi/sbfucrE7-BE/mqdefault.jpg)




