Hi, The code below is always giving errors. Could you find out and fix it, please? Many Thanks. --Creating a table CREATE TABLE IF NOT EXISTS Student ( STU_NUM CHAR(6) NOT NULL, STU_SNAME VARCHAR(15) NOT NULL, STU_FNAME VARCHAR(15) NOT NULL, STU_INITIAL CHAR(1) NOT NULL, STU_STARTDATE DATE NOT NULL, COURSE_CODE CHAR(3), PROJ_NUM INT, PRIMARY KEY (STU_NUM) ); --Inserting into table INSERT INTO Student (STU_NUM,STU_SNAME, STU_FNAME, STU_INITIAL, STU_STARTDATE, COURSE_CODE , PROJ_NUM) VALUES ('01', 'Snow', 'John', 'E', '05-Apr-14', '201' , '6'); INSERT INTO Student (STU_NUM,STU_SNAME, STU_FNAME, STU_INITIAL, STU_STARTDATE, COURSE_CODE , PROJ_NUM) VALUES ('02', 'Stark', 'Arya', 'C', '12-jul-17', '305' , '11'); --FILTER STUDENTS WITH COURSE CODE 305 SELECT * FROM Student WHERE COURSE_CODE = '305'; --All the records have been added INSERT OR REPLACE INTO Student (STU_NUM,STU_SNAME, STU_FNAME, STU_INITIAL, STU_STARTDATE, COURSE_CODE , PROJ_NUM) VALUES ('01','Snow','Jon','E','05-Apr-14','201',6), ('02','Stark','Arya','C','12-Jul-17','305',11), ('03','Lannister','Jamie','J','05-Sep-12','101',2), ('04','Lannister','Cercei','J','05-Sep-12','101',2), ('05','Greyjoy','Theon','I','9-Dec-2015','402',14), ('06','Tyrell','Margaery','Y','12-Jul-17','305',10), ('07','Baratheon','Tommen','R','13-Jun-19','201',5); SELECT * FROM Student --CHANGE COURSE CODE FOR STUDENT NUMBER 07 UPDATE Student SET COURSE_CODE = '304' WHERE STU_NUM = '07'; --Delete Record named Jamie Lannister DELETE FROM Student WHERE STU_FNAME = 'Jamie' AND STU_SNAME = 'Lannister' AND STU_STARTDATE = '5-SEP-12' AND COURSE_CODE = '101' AND PROJ_NUM = 2; --UPDATE PROJECT NUMBER UPDATE Student SET PROJ_NUM = 14 WHERE STU_STARTDATE < '2016-01-01'
SQL
SQL stands for Structured Query Language, is a form of communication that uses queries structured in a specific format to store, manage & retrieve data from a relational database.
Queries
A query is a type of computer programming language that is used to retrieve data from a database. Databases are useful in a variety of ways. They enable the retrieval of records or parts of records, as well as the performance of various calculations prior to displaying the results. A search query is one type of query that many people perform several times per day. A search query is executed every time you use a search engine to find something. When you press the Enter key, the keywords are sent to the search engine, where they are processed by an algorithm that retrieves related results from the search index. Your query's results are displayed on a search engine results page, or SER.
Hi,
The code below is always giving errors. Could you find out and fix it, please?
Many Thanks.
--Creating a table
CREATE TABLE IF NOT EXISTS Student (
STU_NUM CHAR(6) NOT NULL,
STU_SNAME VARCHAR(15) NOT NULL,
STU_FNAME VARCHAR(15) NOT NULL,
STU_INITIAL CHAR(1) NOT NULL,
STU_STARTDATE DATE NOT NULL,
COURSE_CODE CHAR(3),
PROJ_NUM INT,
PRIMARY KEY (STU_NUM)
);
--Inserting into table
INSERT INTO Student (STU_NUM,STU_SNAME, STU_FNAME, STU_INITIAL, STU_STARTDATE, COURSE_CODE , PROJ_NUM)
VALUES ('01', 'Snow', 'John', 'E', '05-Apr-14', '201' , '6');
INSERT INTO Student (STU_NUM,STU_SNAME, STU_FNAME, STU_INITIAL, STU_STARTDATE, COURSE_CODE , PROJ_NUM)
VALUES ('02', 'Stark', 'Arya', 'C', '12-jul-17', '305' , '11');
--FILTER STUDENTS WITH COURSE CODE 305
SELECT * FROM Student WHERE COURSE_CODE = '305';
--All the records have been added
INSERT OR REPLACE INTO Student (STU_NUM,STU_SNAME, STU_FNAME, STU_INITIAL, STU_STARTDATE, COURSE_CODE , PROJ_NUM)
VALUES
('01','Snow','Jon','E','05-Apr-14','201',6),
('02','Stark','Arya','C','12-Jul-17','305',11),
('03','Lannister','Jamie','J','05-Sep-12','101',2),
('04','Lannister','Cercei','J','05-Sep-12','101',2),
('05','Greyjoy','Theon','I','9-Dec-2015','402',14),
('06','Tyrell','Margaery','Y','12-Jul-17','305',10),
('07','Baratheon','Tommen','R','13-Jun-19','201',5);
SELECT * FROM Student
--CHANGE COURSE CODE FOR STUDENT NUMBER 07
UPDATE Student
SET COURSE_CODE = '304'
WHERE STU_NUM = '07';
--Delete Record named Jamie Lannister
DELETE FROM Student
WHERE STU_FNAME = 'Jamie'
AND STU_SNAME = 'Lannister'
AND STU_STARTDATE = '5-SEP-12'
AND COURSE_CODE = '101'
AND PROJ_NUM = 2;
--UPDATE PROJECT NUMBER
UPDATE Student
SET PROJ_NUM = 14
WHERE STU_STARTDATE < '2016-01-01'
AND COURSE_CODE >= '201';
DELETE * FROM Student;
DROP TABLE Student;
Step by step
Solved in 3 steps with 1 images