0% found this document useful (0 votes)
114 views8 pages

Student Table Creation and Management

The document outlines the creation and manipulation of a student database, including the creation of a student table with attributes such as name, register number, department, and marks in five subjects. It details SQL commands for inserting records, updating student names, deleting records, calculating total marks, and displaying specific information. Additionally, it includes integrity rules for student data and operations on a student_master table for managing student records.

Uploaded by

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

Student Table Creation and Management

The document outlines the creation and manipulation of a student database, including the creation of a student table with attributes such as name, register number, department, and marks in five subjects. It details SQL commands for inserting records, updating student names, deleting records, calculating total marks, and displaying specific information. Additionally, it includes integrity rules for student data and operations on a student_master table for managing student records.

Uploaded by

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

Ex1: Create a student table with the following attributes

name, register number, department, marks in 5 subjects


and total.
(a) Insert few records into student table.
(b) Display all the records
(c) Calculate the total marks for all the records.
(d) Display the information of student name,
register number and total only.

CREATE TABLE student (


name VARCHAR(50), register_number VARCHAR(20),
department VARCHAR(50), subject1 INT, subject2 INT,
subject3 INT, subject4 INT, subject5 INT,
total INT, PRIMARY KEY (register_number)
);
a) INSERT INTO student (name, register_number,
department, subject1, subject2, subject3, subject4,
subject5, total) VALUES
('Alice', 'REG001', 'Computer Science', 85, 78, 90, 88, 92,
0),
('Bob', 'REG002', 'Electronics', 75, 80, 70, 82, 76, 0),
('Charlie', 'REG003', 'Mechanical', 60, 65, 70, 68, 72, 0);

or
INSERT INTO student VALUES ('Alice', 'REG001',
‘computer Science', 85, 78, 90, 88, 92, 0);
INSERT INTO student VALUES ('Bob', 'REG002',
'Electronics', 75, 80, 70, 82, 76, 0);
INSERT INTO student VALUES ('Charlie', 'REG003',
'Mechanical', 60, 65, 70, 68, 72, 0);
c) SELECT * FROM student;

d) UPDATE student
SET total = subject1 + subject2 + subject3 + subject4 +
subject5;

e) SELECT name, register_number, total FROM student;

---------------------------------------------------------------------------

Ex2. Create a student table with the following attributes


name, registernumber, department, marks in 5 subjects
and total. (a) Insert few records into student table. (b)
Modify the name of the student as vignesh whose
register number is 211278019. ( c) Delete the records
whose register number is 211278005. (d) Display all the
records.
CREATE TABLE student (
name VARCHAR(50),
registernumber INT PRIMARY KEY,
department VARCHAR(50),
subject1 INT,
subject2 INT,
subject3 INT,
subject4 INT,
subject5 INT,
total INT
);
(a) Insert a few records into the student table:
INSERT INTO student (name, register_number,
department, subject1, subject2, subject3, subject4,
subject5, total) VALUES
('Arun', 0323128107, 'CSE', 78, 85, 90, 88, 76, 417),
('Kumar', 0323128109, 'MECH', 65, 70, 68, 72, 74, 349),
('Priya', 0323128110, 'EEE', 91, 89, 93, 87, 90, 450),
('Vikram', 0323128111, 'CSE', 70, 75, 80, 78, 82, 385);
Or
INSERT INTO student VALUES
('Arun', 0323128107, 'CSE', 78, 85, 90, 88, 76, 417);
INSERT INTO student VALUES
('Kumar', 0323128109, 'MECH', 65, 70, 68, 72, 74, 349);
INSERT INTO student VALUES
('Priya', 0323128110, 'EEE', 91, 89, 93, 87, 90, 450);
INSERT INTO student VALUES
('Vikram', 0323128111, 'CSE', 70, 75, 80, 78, 82, 385);
3. (b) Modify the name of the student to 'vignesh'
whose register number is 0323128109:
UPDATE student
SET name = 'vignesh'
WHERE registernumber = 0323128109;

4. (c) Delete the record whose register number is


0323128110:
DELETE FROM student
WHERE registernumber = 0323128110;

5. (d) Display all the records:


SELECT * FROM student;
Ex3: 3. Create a table student with name, roll number, gender, age and
mobile number. Apply the following integrity rules to the student table
(a)The student name must be in capital letter. (b)The roll number must be
greater than zero. (c)The age cannot be a null value. (d)The gender must be
“Male” or “Female” or “Transgend” (e)The mobile number may contain null
values.

CREATE TABLE student ( name VARCHAR(100) NOT NULL


CHECK (name = UPPER(name)),roll_number INT PRIMARY
KEY CHECK (roll_number > 0),gender VARCHAR(10) NOT
NULL CHECK (gender IN ('Male', 'Female', 'Transgend')),
age INT NOT NULL, mobile_number VARCHAR(15));
EX4: 4. Create a table student_master with the following attributes name, regno, dept
and year of joining with suitable data types. Use Select command to do the following.
(a) Display all the column in the student_ master table .
(b) Display the student’s name column only.
(c) Eliminate the duplicate entry in student_mastertable.
(d) Select the details of student who is studying computer science department
(e) Sort the attribute name in alphabetical order.
-- Create the student_master table
CREATE TABLE student_master (
name VARCHAR(100),
regno INT PRIMARY KEY,
dept VARCHAR(50),
year_of_joining INT
);
-- (a) Display all the columns in the student_master table
SELECT * FROM student_master;
-- (b) Display the student’s name column only
SELECT name FROM student_master;
-- (c) Eliminate the duplicate entry in student_master
table
SELECT DISTINCT * FROM student_master;
-- (d) Select the details of student who is studying
computer science department
SELECT * FROM student_master WHERE dept =
'Computer Science';
-- (e) Sort the attribute name in alphabetical order
SELECT name FROM student_master ORDER BY name
ASC;
EX5:

Common questions

Powered by AI

Primary keys are used in a student database to maintain uniqueness by assigning a unique identifier to each record. For example, regno or register_number can act as a primary key, ensuring that each student record is uniquely identifiable and preventing duplicate entries . This aids in maintaining data consistency and integrity and allows efficient indexing and querying within the database.

Sorting student names in alphabetical order improves data organization and retrieval efficiency by allowing users to locate and manage records easily. In SQL, this is implemented using 'SELECT name FROM student_master ORDER BY name ASC', which orders the names in ascending order alphabetically . This can be particularly useful for reports and presenting data in a more readable form.

Logical constraints in SQL ensure valid gender entries by restricting the allowable values to a specific set such as 'Male', 'Female', or 'Transgend'. This is done using a CHECK constraint on the gender column, which validates the input against the predefined options . The impact on database validity is substantial as it prevents errors from misinformation or typos, maintaining consistent and reliable data.

Methods to efficiently display and analyze specific columns in a student database include using targeted SELECT statements to query only the required columns, such as 'SELECT name FROM student_master'. This minimizes data retrieval overhead . Additionally, combining this with sorting (ORDER BY) or filtering (WHERE clause) techniques can help in efficiently organizing or limiting the dataset for analysis, as seen in querying particular departments or alphabetically sorting names .

To modify the name of a student in a database, an SQL UPDATE command is used. For example, 'UPDATE student SET name = 'vignesh' WHERE registernumber = 0323128109' updates the student’s name based on their register number . This command impacts data modification operations by allowing targeted updates, which ensure that only the specific data that meets certain conditions is changed, preserving the rest of the data integrity in the database.

Enforcing non-null constraints on specific columns ensures that essential fields such as 'age' are always populated with data, preventing incomplete records . This affects data entry by requiring that users provide values for these key fields, which ensures minimum data completeness and maintains database reliability. In terms of management, it reduces the potential for data inconsistencies and enhances the overall integrity of the database.

Integrity constraints can be applied to a student table by defining rules that the data must adhere to. For example, a constraint can require that the student name be in uppercase, ensuring uniform data format . Another rule might ensure that the roll number is greater than zero, preventing invalid entries . Additionally, the age field cannot have null values, requiring all records to have a specified age . Gender must be restricted to predefined values, such as 'Male', 'Female', or 'Transgend', to prevent erroneous entries . Finally, while the mobile number may contain null values, ensuring this field is optional helps maintain database flexibility .

SQL constraints play a crucial role in designing and maintaining a robust student database system by enforcing rules that ensure data accuracy, consistency, and integrity. Constraints such as PRIMARY KEY ensure uniqueness, CHECK constraints maintain data validity (e.g., ensuring roll numbers are positive), and NOT NULL constraints guarantee essential data is always provided . These collectively limit errors arising from user input, facilitate quality control, and enable the database to support reliable operations and reporting.

Updating the 'total' column in the student table is critical to reflect the cumulative score of a student's marks across subjects. This is accomplished by using an SQL UPDATE statement that recalculates the total as the sum of the marks in individual subjects like subject1 through subject5: 'UPDATE student SET total = subject1 + subject2 + subject3 + subject4 + subject5' . This ensures that the total reflects any changes in marks accurately and efficiently.

Using the SELECT DISTINCT command benefits a student database query by eliminating duplicate entries, which helps clean the data and ensures that the results returned are unique. This is particularly useful in instances where a table might have multiple identical records due to repeated data entry. For instance, 'SELECT DISTINCT * FROM student_master' retrieves all unique records, which is crucial for maintaining data integrity and ensuring accurate data reporting and analysis .

You might also like