Home » SQL & PL/SQL » SQL & PL/SQL » Help WIth Fixing Errors In SQL Script (SQL Plus)
Help WIth Fixing Errors In SQL Script [message #624904] Sat, 27 September 2014 13:37 Go to next message
Mckenzo101
Messages: 2
Registered: September 2014
Location: United States
Junior Member
Hi everyone, Im currently a student attending a Tech University. However, within my assignment - is to create a table with 7 columns that keep track of enrollment information for a school. I been trying to fix all the errors for two weeks,but I want to seek clarity on how a basic script is supposed to be written. If anyone could just provide some information, I gratefully appreciate it for my studies.




Script:



--Lab 3
DROP TABLE ENROLLMENT CASCADE CONSTRAINTS PURGE; 
DROP TABLE COURSE_SECTION CASCADE CONSTRAINTS PURGE; 
DROP TABLE COURSE CASCADE CONSTRAINTS PURGE; 
DROP TABLE TERM CASCADE CONSTRAINTS PURGE; 
DROP TABLE STUDENT CASCADE CONSTRAINTS PURGE;
DROP TABLE FACULTY CASCADE CONSTRAINTS PURGE; 
DROP TABLE LOCATION CASCADE CONSTRAINTS PURGE;

Create table ENROLLMENT
(
SID NUMBER(5) CONSTRAINT ENRL_SID_PK PRIMARY KEY,
CONSTRAINT FK_CSECID REFERENCES (STUDENT),
Grade VARCHAR(1))
;

INSERT INTO ENROLLMENT
VALUES (100,'1000','A');
INSERT INTO ENROLLMENT
VALUES (100,'1003','A');
INSERT INTO ENROLLMENT
VALUES (101,'1000','C');
INSERT INTO ENROLLMENT
VALUES (102,'1000','C');
INSERT INTO ENROLLMENT
VALUES (102,'1001','NULL');
INSERT INTO ENROLLMENT
VALUES (102,'1003', 'I');

create table COURSE_SECTION
(
CSECID NUMBER(8) 
CONSTRAINT COURSESECTION_PK_CORID PRIMARY KEY (ENROLLMENT),
CID NUMBER(6) NOT NULL,
CONSTRAINT COURSESECTION_CID_FK FOREIGN KEY (COURSE),
Termid NUMBER(5) NOT NULL,
CONSTRAINT COURSESECTION_TERMID_FK FOREIGN KEY (TERM),
Fid NUMBER (4) NOT NULL,
CONSTRAINT COURSESECTION_Fid_FK FOREIGN KEY (FACULTY),
Lucid NUMBER(5) NOT NULL,
CONSTRAINT COURSESECTION_Lucid_FK FOREIGN KEY (LOCATION),
Secnum NUMBER(2),
FID NUMBER(4),
DAY VARCHAR2(10),
Locid number(5),
Maxenrl NUMBER(4),
Currenrl NUMBER(4)
);

INSERT INTO COURSE_SECTION
VALUES (1000,'1','2','1','12','MWF','55','100','35');
INSERT INTO COURSE_SECTION
VALUES (1001,'1','2','2','10','TTH','54','45','35');
INSERT INTO COURSE_SECTION
VALUES (1002,'2','2','3','10','MWF','53','35','32');
INSERT INTO COURSE_SECTION
VALUES (1003,'3','2','1','11','TTH','54','45','35');

create table COURSE
(CID NUMBER(6) CONSTRAINT PK_COURSE PRIMARY KEY,
Callid VARCHAR2(10) NOT NULL,
Cname VARCHAR2(30) NOT NULL,
Ccredit NUMBER(2));

INSERT INTO COURSE
VALUES (1,'MIS101','Intro. to Info. Systems','3');
INSERT INTO COURSE
VALUES (2,'MIS321','System Analysis and Design','3');
INSERT INTO COURSE
VALUES (3,'MIS349','Intro to Database Management','3')
);

create table TERM
(Termid NUMBER(5) CONSTRAINT PK_TERM PRIMARY KEY,
Tdesc VARCHAR2(20) NOT NULL,
Status VARCHAR2(20) NOT NULL,
);

INSERT INTO TERM
VALUES ('Spring 2004','CLOSED')
INSERT INTO TERM
VALUES ('SUMMER 2004','OPEN');

create table STUDENT
(
Sid NUMBER(5) CONSTRAINT PK_STUDENT PRIMARY KEY,
Slame VARCHAR2(25) NOT NULL,
Sfname VARCHAR2(25) NOT NULL,
Smi CHAR(1),
Saddr VARCHAR2(30),
Scity VARCHAR2(30),
Sstate CHAR(2),
Szip NUMBER(9),
Sphone NUMBER(10) NOT NULL,
Sclass CHAR(2),
Sdob DATE NOT NULL,
Spin NUMBER(4) NOT NULL,
Fid NUMBER (4) CONSTRAINT FK_STUDENT REFERENCES FACULTY,
);

INSERT INTO STUDENT
VALUES (100, 'McCLURE', 'SARAH', 'M', '144 WINDRIDGE BLVD.', 'EAU CLAIRE', 'WI', 54703, 7155559876, 'SR', 

'14-JUL-1979', 8891, 10);
INSERT INTO STUDENT
VALUES (101, 'BOWIE', 'JIM', 'D', '454 ST. JOHN STREET', 'EAU CLAIRE', 'WI', 54702, 7155552345, 'SR', '19-

AUG-1979', 1230, 11);
INSERT INTO STUDENT
VALUES (102, 'BOONE', 'DANIEL', NULL, '8921 CIRCLE DRIVE', 'BLOOMER', 'WI', 54715, 7155553907, 'JR', '10-

OCT-1977', 1613, 11);

create table FACULTY
Fid NUMBER(4) CONSTRAINT PK_FACULTY PRIMARY KEY,
Flname VARCHAR2(25),
Ffname VARCHAR2(25),
Fmi CHAR(1),
Fphone NUMBER(10),
F_rank VARCHAR(4));

INSERT INTO FACULTY
VALUES (10,'Cox', 'Kim', 'J', '7155551234', 'ASSO', 1181);
INSERT INTO FACULTY
VALUES (11,'Blanchard', 'Frank', 'R', '7155559087', 'FULL', 1075);
INSERT INTO FACULTY
VALUES (12,'McClure', 'William', 'L', '7155556409', 'ADJ', 1690);

create table LOCATION
Locid NUMBER(5) CONSTRAINT PK_LOCATION PRIMARY KEY,
Bldg_Code VARCHAR2(10) NOT NULL,
Room VARCHAR2(6) NOT NULL,
Capacity NUMBER(5));

INSERT INTO FACULTY
VALUES (53,'BUS','424','45');
INSERT INTO FACULTY
VALUES (54,'BUS','402','35');
INSERT INTO FACULTY
VALUES (55,'BUS','433','100');

Commit;



Edited by Lalit : Added code tags, 8 enclosed within braces becomes an emoticon without tags

[Updated on: Sun, 28 September 2014 07:23] by Moderator

Report message to a moderator

Re: Help WIth Fixing Errors In SQL Script [message #624906 is a reply to message #624904] Sat, 27 September 2014 13:48 Go to previous messageGo to next message
EdStevens
Messages: 1376
Registered: September 2013
Senior Member
So what kind of "some information" are you looking for?
Did the script run without errors?
Did it produce the results you expected/wanted?
Re: Help WIth Fixing Errors In SQL Script [message #624908 is a reply to message #624906] Sat, 27 September 2014 18:35 Go to previous messageGo to next message
Mckenzo101
Messages: 2
Registered: September 2014
Location: United States
Junior Member
I actually cannot get it to run at all. I'm able to paste it into the command prompt of SQL Plus; however I get a various amount of errors. What I am attempting to achieve is to have a row/column database that will display the given information from my assignment.

The tables that are apart of the given values are named

Enrollment
Course_Selection
Course
Term
Student
Faculty
Location.

I managed to write and format the script the way my instructor inteded it to be. But I'm unaware of the list of errors that I recieve when I run the script.

[Updated on: Sat, 27 September 2014 18:36]

Report message to a moderator

Re: Help WIth Fixing Errors In SQL Script [message #624910 is a reply to message #624908] Sat, 27 September 2014 20:25 Go to previous messageGo to next message
BlackSwan
Messages: 26766
Registered: January 2009
Location: SoCal
Senior Member
One potential problem area involves Foreign Keys (FK).
You can only create the child table constraint (FK) after the parent table & its Primary Key (PK) now exists.

This means that as the SQL is currently written the order of the CREATE TABLE statements is critical to throwing no errors.

SO, SO, So, so many errors; syntax, data, order of execution.

I am tired of trying to clean up this mess.
Re: Help WIth Fixing Errors In SQL Script [message #624911 is a reply to message #624904] Sat, 27 September 2014 23:23 Go to previous messageGo to next message
Solomon Yakobson
Messages: 3273
Registered: January 2010
Location: Connecticut, USA
Senior Member
1. You can't create a FK constraint to a non-existent table, so sequence CREATE TABLE statements.
2. You need to fix syntax errors like extra commas after last column, missing open parethesis after CREATE TABLE, etc.

SY.
Re: Help WIth Fixing Errors In SQL Script [message #624917 is a reply to message #624908] Sun, 28 September 2014 12:03 Go to previous messageGo to next message
EdStevens
Messages: 1376
Registered: September 2013
Senior Member
Mckenzo101 wrote on Sat, 27 September 2014 18:35
however I get a various amount of errors.


Errors which you chose not to share with those from whom you are seeking help . . .

So what have you done on your own to try to resolve the errors? Did you do a google on the various "ORA-nnnnn" messages? Have you collaborated with other members of the class?

None of the errors that are possible from such a simple sequence of commands can be all that hard. But you have to be willing to read them, look them up, and think about the explanation and what it will take to resolve them.

Once you graduate from school and get a job, looking up error codes and resolving them will be a large part of what your employer will be paying you to do. I'm not trying to be difficult or withhold assistance, but I see a more fundamental problem here than the errors your script produces. And that fundamental problem is one you need to address if you expect to be successful in ANY area of IT .. or any other professional career.
Re: Help WIth Fixing Errors In SQL Script [message #624973 is a reply to message #624917] Mon, 29 September 2014 13:18 Go to previous message
Bill B
Messages: 1971
Registered: December 2004
Senior Member
1) Create your tables without foreign keys
2) Use alter table command to add the foreign keys
3) add in your data starting with the parent tables

Good luck
Previous Topic: Regexp Replace - Replacement Problem
Next Topic: distribute grp_cd equally among the data
Goto Forum:
  


Current Time: Tue Apr 23 18:33:41 CDT 2024