From 8173f8e50dd65822605dd55f6378861d2cb84002 Mon Sep 17 00:00:00 2001 From: akashboora Date: Sat, 10 Aug 2024 20:42:41 +0530 Subject: [PATCH] telusko: added sql practise --- telusko/SQL/script1.sql | 42 +++++++++++++++++++++++++++++++++++++ telusko/SQL/script2.sql | 15 ++++++++++++++ telusko/SQL/script3.sql | 19 +++++++++++++++++ telusko/SQL/script4.sql | 46 +++++++++++++++++++++++++++++++++++++++++ telusko/SQL/script5.sql | 9 ++++++++ telusko/SQL/script6.sql | 5 +++++ telusko/SQL/script7.sql | 13 ++++++++++++ telusko/SQL/script8.sql | 9 ++++++++ 8 files changed, 158 insertions(+) create mode 100644 telusko/SQL/script1.sql create mode 100644 telusko/SQL/script2.sql create mode 100644 telusko/SQL/script3.sql create mode 100644 telusko/SQL/script4.sql create mode 100644 telusko/SQL/script5.sql create mode 100644 telusko/SQL/script6.sql create mode 100644 telusko/SQL/script7.sql create mode 100644 telusko/SQL/script8.sql diff --git a/telusko/SQL/script1.sql b/telusko/SQL/script1.sql new file mode 100644 index 0000000..d5b3a9f --- /dev/null +++ b/telusko/SQL/script1.sql @@ -0,0 +1,42 @@ +create database telusko_db; +DROP DATABASE telusko_db; +CREATE SCHEMA telusko_db; +drop schema telusko_db; + +create database if not exists telusko_db; + +/** +Data Types: +INT - 44,4,78 +FLOAT - 4.5,55.2 +CHAR => fixed length string, Postal code +VARCHAR => variable length string, FirstName, CIty +DATE => 12/12/2024 +TIME => 12:44 +DATETIME => 12/12/2024 12:44:44 +BOOLEAN => True/False +*/ + +use telusko_db; + +create table personalInfo( +id INT, +name varchar(40), +date_of_birth date, +city varchar(40) +); + +create table personalEducation( +id INT, +courses varchar(30), +city_of_education varchar(40) +); + +insert into personalInfo(id, name, date_of_birth, city) values (1, 'Akash', '2000-07-22', 'Ganneruvaram'); +insert into personalInfo(id, name, date_of_birth, city) values (2, 'Rohit', '2000-07-22', 'Ganneruvaram'); +insert into personalInfo(id, name, date_of_birth, city) values (3, 'Ramesh', '2000-10-22', 'Hyderabad'); + +insert into personalInfo(id, name, date_of_birth, city) values (4, 'Raju', '1999-10-22', 'Banglore'), +(5, 'Kamal', '1998-10-22', 'Pune'), +(6, 'Uday', '1998-07-22', 'Mumbai'); + diff --git a/telusko/SQL/script2.sql b/telusko/SQL/script2.sql new file mode 100644 index 0000000..784ec1f --- /dev/null +++ b/telusko/SQL/script2.sql @@ -0,0 +1,15 @@ +use telusko_db; + +create table employee( +id int, +emp_name varchar(40), +emp_age int, +emp_city varchar(40), +primary key(id)); + + +insert into employee(id, emp_name, emp_age, emp_city) +values +(1, "Rohan", 15, "Bangalore"), +(2, "Rohan", 15, "Bangalore"), +(3, "Rohan", 15, "Bangalore"); diff --git a/telusko/SQL/script3.sql b/telusko/SQL/script3.sql new file mode 100644 index 0000000..871900c --- /dev/null +++ b/telusko/SQL/script3.sql @@ -0,0 +1,19 @@ +use telusko_db; + +create table studentsINfo( +id int not null, +name varchar(40) not null, +age int not null check(age>=18), +gender varchar(10) not null, +phone varchar(10) not null, +city varchar(20) not null default "Bangalore", +primary key (id)); + +INSERT INTO studentsInfo(id,name, age, gender, phone) +VALUES(1, " Rohan" , 19, "Male","456123"); + +INSERT INTO studentsInfo(id,name, age, phone) +VALUES(1, " Rohan" , 19,"456123"); + +INSERT INTO studentsInfo(id,name, age, gender, phone) +VALUES(2, "Rohan" , 19, "Male","456123"); \ No newline at end of file diff --git a/telusko/SQL/script4.sql b/telusko/SQL/script4.sql new file mode 100644 index 0000000..1bcd97f --- /dev/null +++ b/telusko/SQL/script4.sql @@ -0,0 +1,46 @@ +# where caluse + +use sakila; + +select * from actor; + +select first_name from actor; + +select * from actor where first_name="NICK"; + +select * from actor where actor_id>10; + +# AND OR NOT +select * from actor where first_name="NICK" and last_name='WAHLBERG'; + +select * from actor where first_name="NICK" or last_name='WAHLBERG'; + +select * from actor where (first_name="NICK" or first_name='DARYL') and last_name='WAHLBERG'; + +select * from actor where not(first_name="NICK" or last_name='WAHLBERG'); + + +# in operator +select * from actor where first_name="NICK" or first_name='DARYL'; +# can be written as +select * from actor where first_name in ("NICK",'DARYL'); + +select * from actor where last_name='STALLONE' or last_name='WAHLBERG' or last_name='CRAWFORD'; + +select * from actor where last_name in ('STALLONE', 'WAHLBERG', 'CRAWFORD'); + +# between and not between + +select * from actor where first_name between "DARYL" and "FRED"; + +select * from actor where first_name not between "DARYL" and "FRED"; + + +select * from actor order by first_name ASC; + +select * from actor where last_name='WAHLBERG' order by first_name DESC; + +select distinct(first_name) from actor; + + + diff --git a/telusko/SQL/script5.sql b/telusko/SQL/script5.sql new file mode 100644 index 0000000..580893c --- /dev/null +++ b/telusko/SQL/script5.sql @@ -0,0 +1,9 @@ +use telusko_db; + +select * from employee; + +update employee set emp_name="Rohit" where id =3; + +update employee set emp_city="Pune" where id in(2,3); + +delete from employee where id=3; \ No newline at end of file diff --git a/telusko/SQL/script6.sql b/telusko/SQL/script6.sql new file mode 100644 index 0000000..131fd00 --- /dev/null +++ b/telusko/SQL/script6.sql @@ -0,0 +1,5 @@ +use telusko_db; +select * from employee; +update employee set emp_age=36 where id=2; +rollback; +commit; \ No newline at end of file diff --git a/telusko/SQL/script7.sql b/telusko/SQL/script7.sql new file mode 100644 index 0000000..5b3e1d4 --- /dev/null +++ b/telusko/SQL/script7.sql @@ -0,0 +1,13 @@ +use telusko_db; +create table city(id int auto_increment, cityname varchar(20), primary key(id)); +SELECT * FROM telusko_db.city; +insert into city(cityname) values ("Bangolre"), ("Pune"), ("Karimnagar"), ("Mumbai"); + + +CREATE TABLE student(sid INT AUTO_INCREMENT, name VARCHAR(50), age INT, city INT, PRIMARY KEY(sid), FOREIGN KEY(city) references city(id)); +SELECT * FROM telusko_db.student; +INSERT INTO student(name, age, city) values +( "Rohit " ,22, 1), +( " Robin " ,24,2), +( " Ramesh", 22,3), +( " Rahul " ,24,4); diff --git a/telusko/SQL/script8.sql b/telusko/SQL/script8.sql new file mode 100644 index 0000000..c3eecb4 --- /dev/null +++ b/telusko/SQL/script8.sql @@ -0,0 +1,9 @@ +use sakila; + +select * from category as c INNER join film_category as f on c.category_id = f.category_id; + +select * from category as c left join film_category as f on c.category_id = f.category_id; + +select * from category as c right join film_category as f on c.category_id = f.category_id; + +select * from category as c join film_category as f on c.category_id = f.category_id; \ No newline at end of file