Fundamental Operation of SQL
SQL in data definition
Data is defined or defined using SQL through the CREATE statement. An example is given below
CREATE TABLE Employee()
Emp_No NUMBER (5) NOT NULL
Name CHAR (20)
Skill CHAR (20)
pay_rate NUMBER (10, 2);
Explanation of the statement:
(i) A table named Employee can be created through this SQL. The table will have four fields named Emp_No, Name, Skill and Pay_rate.
(ii) Emp_No field will be NUMBER type data and this field will never be empty as it is declared as NOT NULL.
(iii) Name field will be Character tight data and its length will be 20.
(iv) The Skill field will be Character tight data and its length will be 20.
(v) Pay_rate field will be NUMBER data type and its length will be 10 and 2 digits after decimal.
Now let's say we want to add a new field to this table. Then type the following command:
ALTER TABLE Employee
ADD Phone_No NUMBER (10);
Now type the following command to delete the Employee table.
DROP TABLE Employee.
SQL in Data Manipulation:
(1) Delete Operation: The delete command is used to delete one or more records. For example, the following command is used to delete the record named Ranjan:
DELETE Employee
WHERE Name = 'Ranjan',
(2) Insert Operation: Insert command is used to create one or more documents. For example, the following command is used to create a record named Ranjan:
INSERT INTO Employee
Values (12345, 'Ranjan', 'Professor' 12345, 98765431):
(3) Update Operation: Update command is used to update one or more records. For example, the salary of the record named "Ranjan" in the Employee table is updated to Rs. 15000. UPDATE Employee
SET SALARY = 15000
WHERE Name = "Ranjan",
SQL to retrieve data:
The use of SQL as a data query language is very important for data retrieval. Data query language is used to query the required data from the database.
In SQL, data is retrieved using a single SELECT statement. Data manipulation is done using more clauses with Select. An example is given below-
Select Name, Emp_No, Skill, Pay_rate FROM EMPLOYEE
WHERE Name = 'Ranjan',
Through this SQL all information of Employee named Ranjan in EMPLOYEE table like Emp_No, Skill and Pay_rate etc. can be known. Below are two SQL examples
Example-1:
SELECT Customer_name FROM Customer WHERE Customer_city = 'Tangail',
Through this SOL, the names of all the customers of Tangail city in the Customer table can be extracted. If Gazipur or Dhaka is written instead of Customer city Tangail then the name of all customers of Dhaka or Gazipur will be available.
Example-2:
SELECT Loan_number FROM Loan
WHERE branch_name = Bajitpur' AND amount >= 20000
Through this SQL, all those Loan_numbers of the Loan table can be extracted, whose branch_name = 'Bajitpur' Loan amount is equal to 20000 or more.
Comments
Post a Comment