SQL Day -1
Definition for SQL
Structured query language (SQL) is a programming language for storing and processing information in a relational database. A relational database stores information in tabular form, with rows and columns representing different data attributes and the various relationships between the data values. You can use SQL statements to store, update, remove, search, and retrieve information from the database. You can also use SQL to maintain and optimize database performance.
In this article,we are going to discuss how to create a table in a database,insert the values in the table.First start the mariadb server,follow the steps in the article if mariadb is not installed in your system.Refer the Installation guide for mariadb is below link.
https://opendiaryofgowthamg.wordpress.com/2024/02/14/installation-mariadb/
After opening the terminal,we need to know the databases presented in mariadb.So that,use..,
SHOW DATABASES;
It will show the available databases.Next we need to create a database and switch into that new database.Using Capital letters for keywords is a good practice in SQL.
CREATE DATABASE database_name;
USE database_name;
Now,we created a database and switched into it.We need to create a table for this database.
CREATE TABLE table_name (Sno int(3),Name varchar (30),Mobile No int (13));
We created a new table with three columns.
Sno has Integer datatype and it can stores upto 3 integer values (i.e up-to 999).
Name has varchar datatype and it stores up-to 30 Characters.
Mobile No has Integer datatype and stores up-to 13 integer value
DESC table_name;
This command allow us to view the description of that table.Practice is the database name which i was created and testing is the name i given to this table.We will discuss about NULL,Key,Default,Extra are in the later sessions.
This is how we create a simple basic table.Letβs see hoe to insert values to this table.
INSERT INTO table_name values (1,"person_1",1231231231);
INSERT INTO table_name values (2,"person_2",97979797),(3,"person_3",34343434),(4,'person_4',456789123);
First line shows,inserting only a single row data to the table.Whereas,second one shows multi data insertion to the table.We can use either Double Quote (β β) or Single Quote (β β) to the Character datatype.
Letβs see how to view this table entirely or only a specific column.
SELECT * FROM table_name;
SELECT column_name FROM table_name;
The first image shows the full table contents.
Second image shows only a particular column named βbooksβ.
EXIT;
Exit from mariadb.
We will discuss how to edit,update the table in next article.
Thatβs it..!