DEV Community

Mohammed Nadeem Shareef
Mohammed Nadeem Shareef

Posted on

DBMS Student table

Illustrate an example to create a table student, student table will content the following attributes, stdid, stdname, dob, doj, fee, gender etc.

Write the following queries:

  • Describe the structure of the table.
  • Insert few records into student table.
  • Add column to the student table (that is phone_no).
  • Modify the column name of phone_no to student_no.
  • Rename the table name to student_info
  • Delete any records from the table.

Solution

Creating student table.


CREATE TABLE STUDENT (
    stdid number(5),
    stdname varchar2(20),
    dob date,
    doj date,
    fee number(5),
    gender char
);


Enter fullscreen mode Exit fullscreen mode

Describe the structure of the table.


DESC STUDENT;

Enter fullscreen mode Exit fullscreen mode

Insert few records into student table.


INSERT INTO STUDENT (
    stdid, stdname, dob, doj, fee, gender
)
VALUES (1, 'SHAREEF', '20-jan-2001', '25-oct-2001', 10000, 'M');

Enter fullscreen mode Exit fullscreen mode

Inserting second record.


INSERT INTO STUDENT (
    stdid, stdname, dob, doj, fee, gender
)
VALUES (2, 'NADEEM', '17-nov-2019', '26-oct-2001', 11000, 'M');

Enter fullscreen mode Exit fullscreen mode

Here I am just inserting two records you can insert as many as you want.

Add column to the student table (that is phone_no).

ALTER TABLE STUDENT ADD PHONE_NO NUMBER(10);
Enter fullscreen mode Exit fullscreen mode

Modify the column name of phone_no to student_no.


ALTER TABLE STUDENT RENAME COLUMN PHONE_NO TO STUDENT_NO;

Enter fullscreen mode Exit fullscreen mode

Rename the table name to student_info.


ALTER TABLE STUDENT RENAME TO STUDENT_INFO;

Enter fullscreen mode Exit fullscreen mode

Delete any records from the table.


DELETE FROM STUDENT_INFO WHERE STDID = 2;

Enter fullscreen mode Exit fullscreen mode

Note:- DBMS is not a strictly type language, meaning if you write in small letter or capital letter
it doesn't make any difference, It is good practice to write everything in capital letter.

Second Question.
DBMS Department and Employee Table

Closing here 👋👋👋

This is Shareef.
My recent project yourounotes
My Portfolio
Twitter ShareefBhai99
Linkedin
My other Blogs

Top comments (0)