0% found this document useful (0 votes)
6 views4 pages

SQL

The document outlines the creation of two SQL tables, Students and Courses, with appropriate fields and relationships. It details the insertion of student and course records, as well as various SELECT queries to retrieve data from these tables. Additionally, it provides the structure of both tables using the DESC command.

Uploaded by

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

SQL

The document outlines the creation of two SQL tables, Students and Courses, with appropriate fields and relationships. It details the insertion of student and course records, as well as various SELECT queries to retrieve data from these tables. Additionally, it provides the structure of both tables using the DESC command.

Uploaded by

22ad026
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 4

SQL> CREATE TABLE Students (

2 student_id INT PRIMARY KEY NOT NULL,


3 name VARCHAR(100) NOT NULL,
4 age INT NOT NULL
5 );

Table created.

SQL> CREATE TABLE Courses (


2 course_id INT PRIMARY KEY NOT NULL,
3 course_name VARCHAR(100) NOT NULL,
4 student_id INT NOT NULL,
5 FOREIGN KEY (student_id) REFERENCES Students(student_id)
6 );

Table created.

SQL> INSERT INTO Students (student_id, name, age) VALUES


2 (1, 'Alice', 20),
3 (2, 'Bob', 22),
4 (3, 'Charlie', 21);
(1, 'Alice', 20),
*
ERROR at line 2:
ORA-00933: SQL command not properly ended

SQL> INSERT INTO Students (student_id, name, age) VALUES


2 (1, 'Alice', 20),
3 (2, 'Bob', 22),
4 (3, 'Charlie', 21);
(1, 'Alice', 20),
*
ERROR at line 2:
ORA-00933: SQL command not properly ended

SQL> INSERT INTO Students (student_id, name, age) VALUES (1, 'Alice', 20);

1 row created.

SQL> INSERT INTO Students (student_id, name, age) VALUES (2, 'Bob', 22);

1 row created.

SQL> INSERT INTO Students (student_id, name, age) VALUES (3, 'Charlie', 21);

1 row created.

SQL> INSERT INTO Courses (course_id, course_name, student_id) VALUES (101,


'Mathematics', 1);

1 row created.

SQL> INSERT INTO Courses (course_id, course_name, student_id) VALUES (102,


'Physics', 2);

1 row created.
SQL> INSERT INTO Courses (course_id, course_name, student_id) VALUES (103,
'Chemistry', 3);

1 row created.

SQL> INSERT INTO Courses (course_id, course_name, student_id) VALUES (104,


'Biology', 1);

1 row created.

SQL> SELECT * FROM Students;

STUDENT_ID
----------
NAME
--------------------------------------------------------------------------------
AGE
----------
1
Alice
20

2
Bob
22

STUDENT_ID
----------
NAME
--------------------------------------------------------------------------------
AGE
----------

3
Charlie
21

SQL> SELECT * FROM Courses;

COURSE_ID
----------
COURSE_NAME
--------------------------------------------------------------------------------
STUDENT_ID
----------
101
Mathematics
1

102
Physics
2

COURSE_ID
----------
COURSE_NAME
--------------------------------------------------------------------------------
STUDENT_ID
----------

103
Chemistry
3

104
Biology

COURSE_ID
----------
COURSE_NAME
--------------------------------------------------------------------------------
STUDENT_ID
----------
1

SQL> SELECT name, age FROM Students;

NAME
--------------------------------------------------------------------------------
AGE
----------
Alice
20

Bob
22

Charlie
21

SQL> SELECT course_name FROM Courses;

COURSE_NAME
--------------------------------------------------------------------------------
Mathematics
Physics
Chemistry
Biology

SQL> SELECT course_name FROM Courses WHERE student_id = 1;

COURSE_NAME
--------------------------------------------------------------------------------
Mathematics
Biology

SQL> DESC Students;


Name Null? Type
----------------------------------------- -------- ----------------------------
STUDENT_ID NOT NULL NUMBER(38)
NAME NOT NULL VARCHAR2(100)
AGE NOT NULL NUMBER(38)

SQL> DESC Courses;


Name Null? Type
----------------------------------------- -------- ----------------------------
COURSE_ID NOT NULL NUMBER(38)
COURSE_NAME NOT NULL VARCHAR2(100)
STUDENT_ID NOT NULL NUMBER(38)

You might also like