0% found this document useful (0 votes)
16 views

My SQL

Uploaded by

Jayesh Kalkate
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
16 views

My SQL

Uploaded by

Jayesh Kalkate
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 3

-- Also we used the DROP DATABASE wite_file_name ; to delete the file from database

--
DROP DATABASE college ;

-- The ; symbol is used to end line


-- The CREATE DATABASE is used to create a database like given we used them
CREATE DATABASE college ;

-- The USE is used to access the file into the database to perform any operations
on them
USE college ;

-- To Create a table we used CREATE TABLE keyword and write the table name --
-- Also the under the () we are write the all content like student name , student
id , student age , etc... --
-- Also after write every row we used the , to end this row --
CREATE TABLE STUDENT (
STUDENT_ID INT PRIMARY KEY,
NAME VARCHAR(20),
AGE INT NOT NULL,
DOB DATE,
CONTACT_NUMBER VARCHAR(10),
ADDRESS VARCHAR(300),
BRANCH VARCHAR(30)
);

-- To insert the values in table we used INSERT INTO file_name VALUES (Enter
values) --
-- Also to write the string init we used single quotes or double quotes but there
are many cases people used single quotes so we prefer it --
-- INSERT INTO student VALUES (1, 'JAYESH', 22 , '1992-11-20' , '9876543210' ,
'Maple Avenue Skyline Apartments Flat Ten Pune Maharashtra India' , 'Computer
Science');
-- INSERT INTO student VALUES (2, 'MAYUR', 32 , '2002-05-15' , '9123456789' , 'Elm
Street Green Meadows Society Bengaluru Karnataka India' , 'Mechanical
Engineering');
-- INSERT INTO student VALUES (3, 'OM', 24 , '1998-09-10' , '9988776655' , 'River
Road Sunshine Complex Apartment Fifteen B Jaipur Rajasthan India' , 'Civil
Engineering');
-- INSERT INTO student VALUES (4, 'CHETAN', 42 , '1982-04-18' , '9123678456' , 'Oak
Lane Royal Residency Room Three Zero Two Mumbai Maharashtra India' , 'Electrical
Engineering');
-- INSERT INTO student VALUES (5, 'HITESH', 12 , '2012-03-25' , '9871234567' ,
'Pine Street Silver Sands Villas New Delhi Delhi India' , 'Electronics and
Communication');
-- INSERT INTO student VALUES (6, 'YESH', 43 , '1981-07-30' , '9098765432' ,
'Willow Drive Ocean Breeze Apartments Floor Five Hyderabad Telangana India' ,
'Information Technology');
-- INSERT INTO student VALUES (7, 'RAJ', 22 , '2002-08-12' , '9812345678' , 'Cedar
Avenue Palm Grove Tower Suite One Twenty Ahmedabad Gujarat India' , 'Chemical
Engineering');

-- At a one time we used the INSERT INTO and insert the multiple values in the
table like STUDENT_ID , NAME , AGE , DOB , CONTACT_NUMBER , ADDRESS , BRANCH
INSERT INTO student
(STUDENT_ID , NAME , AGE , DOB , CONTACT_NUMBER , ADDRESS , BRANCH)
VALUES
(1, 'JAYESH', 22 , '1992-11-20' , '9876543210' , 'Maple Avenue Skyline Apartments
Flat Ten Pune Maharashtra India' , 'Computer Science'),
(2, 'MAYUR', 32 , '2002-05-15' , '9123456789' , 'Elm Street Green Meadows Society
Bengaluru Karnataka India' , 'Mechanical Engineering'),
(3, 'OM', 24 , '1998-09-10' , '9988776655' , 'River Road Sunshine Complex Apartment
Fifteen B Jaipur Rajasthan India' , 'Civil Engineering'),
(4, 'CHETAN', 22 , '1982-04-18' , '9123678456' , 'Oak Lane Royal Residency Room
Three Zero Two Mumbai Maharashtra India' , 'Electrical Engineering'),
(5, 'HITESH', 12 , '2012-03-25' , '9871234567' , 'Pine Street Silver Sands Villas
New Delhi Delhi India' , 'Electronics and Communication'),
(6, 'YESH', 43 , '1981-07-30' , '9098765432' , 'Willow Drive Ocean Breeze
Apartments Floor Five Hyderabad Telangana India' , 'Information Technology'),
(6, 'YESH', 43 , '1981-07-30' , '9098765432' , 'Willow Drive Ocean Breeze
Apartments Floor Five Hyderabad Telangana India' , 'Computer Science'),
(7, 'RAJ', 22 , '2002-08-12' , '9812345678' , 'Cedar Avenue Palm Grove Tower Suite
One Twenty Ahmedabad Gujarat India' , 'Chemical Engineering');

-- By using the where we are able to find the data from the table by using the
speciffic condition --
SELECT * FROM STUDENT WHERE AGE = 22 ;

-- Also we are able to sort the data in asending order


SELECT * FROM STUDENT ORDER BY NAME ASC ;

-- The SELECT * FROM write_file_name is used to get all information or data in the
form of table --
SELECT * FROM student ;

-- Also when we wont to get the same row then we used the GROUP
SELECT BRANCH , COUNT(NAME)
FROM STUDENT
GROUP BY BRANCH ;

DROP DATABASE IF EXISTS employee ;

USE college ;

CREATE TABLE employee (


EMPLOYEE_ID INT PRIMARY KEY,
FIRST_NAME VARCHAR(50),
LAST_NAME VARCHAR(50),
DOB DATE,
GENDER VARCHAR(10),
CONTACT_NUMBER VARCHAR(15),
EMAIL VARCHAR(100),
ADDRESS VARCHAR(255),
JOB_TITLE VARCHAR(50),
DEPARTMENT VARCHAR(50),
HIRE_DATE DATE,
SALARY DECIMAL(10, 2),
STATUS VARCHAR(20),
MANAGER_ID INT,
EMERGENCY_CONTACT VARCHAR(100)
);

INSERT INTO employee


(EMPLOYEE_ID , FIRST_NAME , LAST_NAME , DOB , GENDER , CONTACT_NUMBER , EMAIL ,
ADDRESS , JOB_TITLE , DEPARTMENT , HIRE_DATE , SALARY , STATUS , MANAGER_ID ,
EMERGENCY_CONTACT)
VALUES
(1 , 'John' , 'Doe' , '1985-06-15' , 'Male' , '9876543210' , '[email protected]'
, '123 Maple Street, New York, NY, USA' , 'Software Engineer' , 'IT', '2015-01-
20' , 75000, 'Active' , 3 , 'Emily Doe, 9876543211'),
(2 , 'Jane' , 'Smith' , '1990-08-22' , 'Female' , '9123456789' ,
'[email protected]' , '456 Elm Street, Los Angeles, CA, USA' , 'Data
Analyst' , 'Data Science' , '2018-03-15' , 68000 , 'Active' , 4, 'Robert Smith,
9123456790'),
(3 , 'Michael' , 'Johnson', '1979-11-02' , 'Male' , '9988776655' ,
'[email protected]' , '789 Oak Avenue, Chicago, IL, USA' , 'Project Manager' ,
'Management' , '2012-10-10' , 90000 , 'Active' , NULL, 'Sarah Johnson,
9988776656'),
(4 , 'Emily' , 'Davis' , '1988-02-14' , 'Female' , '9123678456' ,
'[email protected]' , '101 Pine Drive, Houston, TX, USA' , 'HR Specialist' ,
'Human Resources' , '2016-07-05' , 60000 , 'Active' , 3, 'David Davis,
9123678457'),
(5 , 'Robert' , 'Brown' , '1992-12-30' , 'Male' , '9871234567' ,
'[email protected]' , '202 Cedar Boulevard, San Francisco, CA, USA' , 'Marketing
Coordinator' , 'Marketing' , '2020-09-01' , 55000 , 'Active', 2, 'Anna Brown,
9871234568'),
(6 , 'Linda' , 'Wilson' , '1975-03-18' , 'Female' , '9098765432' ,
'[email protected]' , '303 Willow Lane, Phoenix, AZ, USA' , 'Chief Technology
Officer' , 'IT' , '2010-11-20' , 120000 , 'Active' , NULL, 'James Wilson,
9098765433'),
(7 , 'David' , 'Lee' , '1995-05-10' , 'Male' , '9812345678' ,
'[email protected]' , '404 Palm Grove, Seattle, WA, USA' , 'Sales Executive' ,
'Sales' , '2022-01-15' , 50000, 'Active' , 5 , 'Alice Lee, 9812345679');

-- It's used to display the all columns which are included into the table --
SELECT * FROM employee ;

-- It's used to display the columns which can be you wanted


SELECT FIRST_NAME , LAST_NAME FROM employee ;

SELECT * FROM employee WHERE GENDER = 'Male' AND SALARY > 50000 ;

-- Also we are able to setup the limit of an table output by using the LIMIT
SELECT * FROM employee WHERE GENDER = 'Male' AND SALARY > 50000 LIMIT 1 ;

-- Also we are able to sort the data in desending order


SELECT * FROM employee ORDER BY NAME DESC ;

-- We are also used the Aggregate Function like MAX , MIN , COUNT , SUM , AVG ,
etc...

SELECT MAX(SALARY) FROM employee ;

SELECT MIN(SALARY) FROM employee ;

SELECT COUNT(SALARY) FROM employee ;

SELECT SUM(SALARY) FROM employee ;

SELECT AVG(SALARY) FROM employee ;

SELECT max(SALARY) FROM employee ;

You might also like