In my previous articles I have given the idea about different SQL Programming Examples used in real world industry.The users have question in mind that which are different Basic SQL Queries used in industry.I have already given different real life sql examples as well in previous articles.In this article I would like to give you Basic SQL Queries Real Examples. I would like to explain queries with its use and one scenario so that user will get actual idea about basic sql queries in depth.I have already explained the important SQL queries in depth in different articles but i would like to summarize that information in this article so that user will get information directly regarding Basic SQL Queries.
The first question in users mind is which are different types of important SQL queries. In this section i want to give you following important SQL queries which are useful in industry :
3.Update table
4.Delete table
5.Alter table
6.Drop table
If user wants to learn SQL then user should know about the above sql queries.I have already explained the above queries separately in article in depth.In this section i would like to give you different examples.
For Example 1 :
How to create a table named Student which has Student_name,Roll_No Columns?
Create table Student
(Roll_No Number(10),
Student_name Varchar2(50));
The above statement will create a table named Student.
For Example 2 :
How to create a table named student which has Student_name and Roll_No columns where Roll_No is primary key.
CREATE TABLE Student
(RollNo Number (10),
Student_name Varchar2(50) ,
Constraint PK_Roll_No primary key (RollNo));
For Example 3 :
How to create table which has replica of Student table.
Create table Student_Replica
as Select * from Student;
User uses As Select statement because user needs to create exact replica of Student table.
For Example 4 :
How to create table and add the constraint separately to the table.
Step 1 : Create table Named Student
Create table Student
(Roll_No Number(10),
Student_name Varchar2(50));
Step 2 : Add Specified Constraint to Column using Alter Statement
ALTER TABLE Student
MODIFY Roll_No Number (10) PRIMARY KEY;
User needs to alter the table because the primary constraint was not added at the time of creating table.
In above section i have given different examples of create table likewise i would like to give you different examples of insert in to the same table named ‘Student’.
For Example 1 :
How to insert 2 records in already created table named Student.
Query 1 :
Insert in to Student
Values(1,’Amit’);
Commit;
Query 2 :
Insert in to Student
Values(1,’Rohit’);
Commit;
The above statements will insert 2 values in Student table.
For Example 2 :
The user has inserted two different values using insert statement in above examples.Likewise if User wants to insert only Roll_No in Student table.
Insert in to Student
(Roll_No)
values(1);
The above statement will insert only Roll_no in Student table as we are defining the Roll_No column manually while inserting it.
For Example 3 :
How to insert the records in Student table without using columns multiple time.
INSERT INTO Student
Values (&RollNo, &Student_name);
For Example 4 : Insert data using select statement
How to insert all the data from student table in to Student_replica table.
Insert Into Student_Replica
Select * from Student;
For Example 1:
Update the name of Student to Amit Who’s Roll_No is 1.
Update Student
set Student_Name = ‘Amit’
where Roll_No=1;
For Example 1 :
How to delete all records from Student table.
Delete from Student;
For Example 2 :
Delete the record for Student where Roll_No is 69.
Delete from Student where Roll_No=’69’;
User can Alter the table to add or modify columns from the table.
For Example 1 :
How to add new column named Grade in Student table.
Alter table Student
Add Grade Varchar2(1);
For Example 2 :
How to Modify the Size of Student_name column to 100.
Alter table Student
Modify Student_name varchar2(100);
For Example 3 :
How to drop column named Grade from Student table.
Alter table Student
Drop column Grade;
For Example 4 :
How to Rename Student_Name column to Name.
Alter table Student
Rename Column Student_Name to Student;
User can drop,modify and add constraints also using alter statement.
For Example 1 :
How to drop table named Student_Replica?
Drop table Student;
User gets confused between Truncate,delete and drop statement.I have explained the difference between truncate,delete and drop with real life examples in other article.
I have tried to explain the different Basic SQL Queries which are useful to user while working in industry. I hope you like this article.If you like this article or if you have any issues with concepts kindly comment in comments section.
In my previous articles I have given the roles and responsibilities of L1,L2 and L3…
In my previous articles i have given the hierarchy of production support in real company…
In this article i would like to provide information about production support organization structure or…
In my previous article I have given roles for L1 and L2 support engineer with…
I have started this new series of how to become application support engineer. This article…
In this series we are starting with Roles and responsibilities of L1 support engineer .…