Introduction of SQL
Introduction of SQL
Advantage of SQL.
SQL (Structured Query Language) is the standard language used to manage and
manipulate relational databases. Its advantages are numerous, making it one of
the most popular database management languages. Here are the key benefits
of SQL:
1. Data Querying and Retrieval
• Efficient querying: SQL provides powerful and flexible querying capabilities. Complex queries
can be written to filter, join, aggregate, and sort data from multiple tables in a single
statement.
• Standardization: SQL is standardized (ANSI SQL), which means it works across most relational
database management systems (RDBMS) like MySQL, PostgreSQL, SQL Server, and Oracle.
• INSERT, UPDATE, DELETE: SQL allows you to add, modify, and remove data from a database
with simple commands.
• Bulk operations: SQL supports operations on large amounts of data with minimal coding.
• Constraints: SQL supports data integrity constraints such as primary keys, foreign keys,
unique constraints, and check constraints, which ensure the accuracy and consistency of the
data.
• Access Control: SQL allows fine-grained control over data access, enabling you to define roles
and permissions to ensure that only authorized users can access or modify specific data.
pg. 1
pg. 2
2. Write a query to create table person that contain five
column person id , first name , last name , Address city
and salary .
use my_data ;
first_name VARCHAR(100),
last_name VARCHAR(100),
address_city VARCHAR(255),
salary DECIMAL(10, 2)
);
pg. 3
pg. 4
3. Add an Email column to person table
use my_data ;
first_name VARCHAR(100),
last_name VARCHAR(100),
address_city VARCHAR(255),
salary DECIMAL(10, 2)
);
insert into person values ( 236 , 'Nihil' , 'yadav ' , 'rewari' , 28000 );
UPDATE person
UPDATE person
UPDATE person
UPDATE person
pg. 5
pg. 6
4. Delete an Email column from person table
use my_data ;
first_name VARCHAR(100),
last_name VARCHAR(100),
address_city VARCHAR(255),
salary DECIMAL(10, 2)
);
insert into person values ( 236 , 'Nihil' , 'yadav ' , 'rewari' , 28000 );
pg. 7
pg. 8
5. Modify the first name column of person
table by increasing its with to varchar(35).
use my_data ;
first_name VARCHAR(100),
last_name VARCHAR(100),
address_city VARCHAR(255),
salary DECIMAL(10, 2)
);
pg. 9
pg. 10
6. Delete or Drop the table person.
use my_data ;
first_name VARCHAR(100),
last_name VARCHAR(100),
address_city VARCHAR(255),
salary DECIMAL(10, 2)
);
pg. 11
pg. 12
7. Increase the salary of employee by 20% in the
person table .
use my_data ;
first_name VARCHAR(100),
last_name VARCHAR(100),
address_city VARCHAR(255),
salary DECIMAL(10, 2)
);
insert into person values ( 236 , 'Nihil' , 'yadav ' , 'rewari' , 28000 );
UPDATE person
pg. 13
pg. 14
8. Delete one row from person table
use my_data ;
first_name VARCHAR(100),
last_name VARCHAR(100),
address_city VARCHAR(255),
salary DECIMAL(10, 2)
);
pg. 15
pg. 16
9. Select two column from person table.
use my_data ;
first_name VARCHAR(100),
last_name VARCHAR(100),
address_city VARCHAR(255),
salary DECIMAL(10, 2)
);
FROM person;
pg. 17
pg. 18
10. Select specific row by using where clause.
use my_data ;
first_name VARCHAR(100),
last_name VARCHAR(100),
address_city VARCHAR(255),
salary DECIMAL(10, 2)
);
FROM person
pg. 19
pg. 20
11. Short the data in person table.
use my_data ;
first_name VARCHAR(100),
last_name VARCHAR(100),
address_city VARCHAR(255),
salary DECIMAL(10, 2)
);
FROM person
pg. 21
pg. 22
12. Use various type of pattern matching
operator in person table.
create database my_data ;
use my_data ;
first_name VARCHAR(100),
last_name VARCHAR(100),
address_city VARCHAR(255),
salary DECIMAL(10, 2)
);
FROM person
pg. 23
pg. 24
13. Use group by and having clause the creating
viewers on table by using create method.
use my_data ;
first_name VARCHAR(100),
last_name VARCHAR(100),
address_city VARCHAR(255),
salary DECIMAL(10, 2)
);
insert into person values ( 233 , 'Nihil' , 'yadav ' , 'rewari' , 28000 );
FROM person
GROUP BY first_name
pg. 25
pg. 26
14. Use And , Not , Or operator in table.
use my_data ;
first_name VARCHAR(100),
last_name VARCHAR(100),
address_city VARCHAR(255),
salary DECIMAL(10, 2)
);
FROM person
pg. 27
pg. 28