0% found this document useful (0 votes)
3 views1 page

Scripts

Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as ODT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views1 page

Scripts

Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as ODT, PDF, TXT or read online on Scribd

--- CREATE DATABASE

create database university_db;

-- SELECT A DATABASE
use university_db;

-- CREATE TABLE
CREATE TABLE Student (
StudentID INT PRIMARY KEY,
Name VARCHAR(50),
Year INT
);

-- ALTER OR ADD A COLUMN ON A TABLE


ALTER TABLE Student ADD Email VARCHAR(50);
ALTER TABLE student ADD ADDRESS varchar (100);

-- DELETE/DROP A TABLE
drop table student;

--- INSERT DATA INTO A TABLE


INSERT INTO Student VALUES (101, 'Mariatu', 2);
INSERT INTO Student VALUES (102, 'Foday', 1);
INSERT INTO Student VALUES (103, 'Saidu', 4);
INSERT INTO Student VALUES (104, 'Janet', 5);

-- TO SHOW THE ENTIRE TAABLE CONTENT


select *from university_db.student;

-- UPDATING A TABLE
UPDATE Student SET Year = 3 WHERE StudentID = 101;

--- DELETE A SINGLE RECORD


DELETE FROM Student WHERE StudentID = 101;

--- TO TARGET TWO OR MORE COLUMS


SELECT Name, Year FROM Student;

--- TO TARGET A SINGLE RECORD


SELECT * FROM Student WHERE Year = 5;

---- TO SHOW IN ORDER

SELECT * FROM Student ORDER BY Name ASC;

You might also like