SQL1 Updated
SQL1 Updated
M. Y Abdur Rahman
SQL database computer language designed for the retrieval and
management of data in relational database management systems
Language
Modification of data stored in the database
Deletion of the data from the database
Other than DML, SQL has DCL DDL
DDL – Data Definition Language (create, drop, alter, truncate, comment,
SQL | DDL, rename)
and DCL DML – Data Manipulation Language (insert, update, delete, lock, call
Composite key
Primary key
Foreign key
Question 01: Create a database name School.
CREATE DATABASE school;
Question 02: Create a table name student with the following fields
(student id - varchar (30) primary key, student fname - varchar (30),
student lname – varchar (30), student address varchar (30), city
varchar(30), student contact number int (10)).
SQL questions
CREATE TABLE student (student_id varchar (30) NOT NULL primary
key, student_fname varchar (30), student_lname varchar (30),
student_address varchar (30), city varchar(30), student_contact int);
Question 03: Insert ten rows of data for the table.
Question 08: Select record of student first name and student last name
where student id is 3.
Question 11: Select record of student first name and student last name
where student id is 3.
Note: - based on the position the percentage mark moves begin a% end %a
between %am%
Question 12: Count the number of students in the table class.
Question 13 : Select all records from student where the city = Colombo
and last name = ‘Silva’
Question 14: Select records from student table where city is not Kalutara
Question 15 : Select all records from student order by city in ascending order.
15.1 Select all records from student order by last name in descending order.
Question 16: Update table and change student last name to ‘'Fernando’ where
student id is st007.
UPDATE student SET student_lname='Fernando' WHERE student_id = 'st007';
Question 17: update table and change student contact number to
‘0774124444’ where the student id is 1.
Question 21 : Find cities from student with ‘k’ and having 5 characters?
SELECT city FROM student WHERE city LIKE 'K____’;
Note: This is only to show after k there is 4 characters there should not be space in
between the underscore [‘K_ _ _ _ ‘]
Question 22: Select student name having 2nd characters ‘i’ 4th character ‘u’ and
the character before the last is ‘k’ .
WHERE
student_number=”1”
Question :Find average weight of Loan. [tbl - Loan]
https://www.youtube.com/watch?v=E-Fs49rIr7g
https://www.microsoft.com/en-pk/download/details.aspx?
id=42299