SQL

RDBMS (Database) software are used to store the data.

Formally known RDBMS (Relational Database Management System)
Informally known Database   

1) MySQL
2) Oracle
3) Sybase
5) Postgre
and there are many more



SQL (Structure query langauge) is used to to work around these RDBMS or Database

SQL is pronounced as "sequel"




Q: write a SQL to select all student ?
SELECT * FROM student;

Q: write a SQL to select only firstname of all students ?
SELECT firstname FROM student;

Q: write a SQL to select only surname of all students ?
SELECT surname FROM student;

Q: write a SQL to select only firstname and fathername of all students ?
SELECT firstname, fathername FROM student;

Q: write a SQL to select all students whose fathername is "akbar" ?
SELECT * FROM student WHERE fathername = "akbar";

Q: write a SQL to select all students whose class is graeter than or equal to 5 ?
SELECT * FROM student WHERE class >= 5;

Q: write a SQL to insert a new student record ?
INSERT INTO student VALUES(6, "ishita", "anil", "kumar", 1, "hyderbad");

Q: write a SQL to update surname of a student whose id is 3 ?
UPDATE student SET surname = "bagwan" WHERE id = 3;

Q: write a SQL to delete student whose id is 5 ?
DELETE FROM student WHERE id = 5;

Q: write a SQL to create a new table ?
CREATE TABLE teacher (  
id INT NOT NULL,  
name VARCHAR (10) NOT NULL,  
address CHAR (40),  
PRIMARY KEY (id)
);  

Q: write a SQL to remove the table ?
DROP TABLE teacher;

Q: write a SQL to add new column in the table ?
ALTER TABLE student ADD COLUMN mama VARCHAR (5);

Q: write a SQL to rename existing column in a table?
ALTER TABLE student RENAME COLUMN mama TO mamu;

Q: write a SQL to delete existing column in a table?
ALTER TABLE student DROP COLUMN mamu;

Q: write a SQL to count no. of records?
SELECT count(*) FROM student;

Q: write a SQL to check student who has min mark in physics?
SELECT firstname, min(physics) FROM student;

Q: write a SQL to check student who has max mark in physics?
SELECT firstname, max(physics) FROM student;

Q: write a SQL to select all students based on ascending order of firstname?
SELECT * FROM student ORDER BY firstname ASC;
 
Q: write a SQL to select all students based on descending order of firstname?
SELECT * FROM student ORDER BY firstname DESC;

Q: write a SQL to select top two records from database?
SELECT * FROM student LIMIT 2;

Q: write a SQL to select distinct record based on firstname?
SELECT DISTINCT firstname
FROM student; 

Q: write a SQL to create new user name 'aliza' and grant only select, update and create privileges to her?
CREATE USER IF NOT EXISTS aliza@localhost IDENTIFIED BY 'jtp123456';
  
GRANT CREATE, SELECT, INSERT ON * . * TO aliza@localhost; 


 

Comments

Popular posts from this blog

Website Event Handling (JavaScript)

C Language

Unix like operating system