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

SQL Commands

The document provides examples of SQL commands to create a database and table, insert data, update records, and perform joins. It includes commands to: 1) Create a database called "STUDENTS" and use that database. 2) Create a table called "STU" with columns for student details. 3) Insert a row of data into the "STU" table. 4) Select, update, and join data from tables using commands like SELECT, UPDATE, and JOIN.

Uploaded by

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

SQL Commands

The document provides examples of SQL commands to create a database and table, insert data, update records, and perform joins. It includes commands to: 1) Create a database called "STUDENTS" and use that database. 2) Create a table called "STU" with columns for student details. 3) Insert a row of data into the "STU" table. 4) Select, update, and join data from tables using commands like SELECT, UPDATE, and JOIN.

Uploaded by

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

EX.

NO 21 SQL COMMANDS
AIM:
To write Queries for the following Questions based on the given table:

(a) Write a Query to Create a


new database in the name of
"STUDENTS".
CREATE DATABASE STUDENTS;
(b) Write a Query to Open the database "STUDENTS".
USE STUDENTS;
(c) Write a Query to create the above table called: "STU"
CREATE TABLE STU(ROLLNO INT PRIMARY KEY,NAME VARCHAR(10),
GENDER VARCHAR(3), AGE INT,DEPT VARCHAR(15),
DOA DATE,FEES INT);
(d) Write a Query to insert the row of above table into Info table.
INSERT INTO STU VALUES (1,'Arun','M', 24,'COMPUTER','1997-01-10', 120);
(e) Write a Query to display all the details of the Employees from the above table 'STU'.
SELECT * FROM STU;
(f) To show all information about students of History department.
SELECT * FROM STU WHERE DEPT='HISTORY';
(g) Write a Query to change the fess of Student to 170 whose Roll number is 1, if the existing fess
is less than 130.
UPDATE STU SET FEES=170 WHERE ROLLNO=1 AND FEES<130;
h) JOINS
i) To Display max price and min price of each company.

SELECT COMPANY,MAX(PRICE),MIN(PRICE) FROM COST GROUP BY COMPANY;

ii) To display the company where the number of uniforms size is more than 2.
SELECT COMPANY, COUNT(*) FROM COST GROUP BY COMPANY HAVING
COUNT(*)>2;
iii) To display the Ucode, Uname, Ucolor, Size and Company of tables uniform and cost.

SELECT U.UCODE,UNAME,UCOLOR,SIZE,COMPANY FROM

UNIFORM U,COST C WHERE U.UCODE=C.UCODE;

iv) To display the company where the number of uniforms size is more than 2.
SELECT COMPANY, COUNT(*) FROM COST GROUP BY COMPANY HAVING
COUNT(*)>2;
v) To display the Ucode, Uname, Ucolor, Size and Company of tables uniform and cost.

SELECT U.UCODE,UNAME,UCOLOR,SIZE,COMPANY FROM

UNIFORM U,COST C WHERE U.UCODE=C.UCODE;

You might also like