All about SQL basics
SQL — — structured query language
Suppose you have Excel and you fill the details of the students in it in an unstructured format, which also you want it to enhance this so here we use the concept of SQL where we store the data in a structured format and also use the query to fetch the data and make use of it in a meaningful way.
- you cannot avoid duplicity in Excel
- Anybody can access the data in Excel
- you can override the data in Excel
let’s consider you and your friend has join account , now what you have done is at 3:30 pm you have withdrawn 10,000 rupees from the ATM . At the same time your friend has withdrawn at same time 10,000 rupees . let’s say there is 50,000 rupees . if we keep the record in excel then it would show the same time as the withdrawal because excel it cannot remove the duplicacy and also the detection of duplicacy of the time of the withdrawl . it is easy to avoid duplicacy but in sql, it is easy to avoid such things.
create a database
create Database DBname;
lets consider an example
Here we have a students table given
Get Manasa’s stories in your inbox
Join Medium for free to get updates from this writer.
Create table Students (name char(100), subject char ,grade char(1))
Data types mostly used
int A medium integer. Signed range is from -2147483648 to 2147483647. Unsigned range is from 0 to 4294967295. The size parameter specifies the maximum display width (which is 255)
decimal
float A floating point number. The total number of digits is specified in size. The number of digits after the decimal point is specified in the d parameter. This syntax is deprecated in MySQL 8.0.17, and it will be removed in future MySQL versions
Char A FIXED length string (can contain letters, numbers, and special characters). The size parameter specifies the column length in characters — can be from 0 to 255.
VARCHAR A VARIABLE length string (can contain letters, numbers, and special characters). The size parameter specifies the maximum string length in characters — can be from 0 to 65535
BIT(size) A bit-value type. The number of bits per value is specified in size. The size parameter can hold a value from 1 to 64. The default value for size is 1
A bit-value type. The number of bits per value is specified in size. The size parameter can hold a value from 1 to 64. The default value for size is 1.
TINYINT(size) A very small integer. The signed range is from -128 to 127. The unsigned range is from 0 to 255. The size parameter specifies the maximum display width (which is 255)
DOUBLE(size, d) A normal-size floating point number. The total number of digits is specified in size. The number of digits after the decimal point is specified in the d parameter
TIME(fsp) A time. Format: hh: mm: ss. The supported range is from ‘-838:59:59’ to ‘838:59:59’
YEAR A year in four-digit format. Values allowed in four-digit format: 1901 to 2155, and 0000.
MySQL 8.0 does not support year in two-digit format.
Will be cont… in next chapters






