Computer Science - Class 12
Solutions to CBSE Sample Paper - Computer Science Class 12

Ms. Shalini has just created a table named “Employee” containing columns Ename, Department and Salary.

After creating the table, she realized that she has forgotten to add a primary key column in the table. Help her in writing an SQL command to add a primary key column EmpId of integer type to the table Employee.

Thereafter, write the command to insert the following record in the table:

EmpId- 999

Ename- Shweta

Department: Production

Salary: 26900

Answer

Answer by student

The SQL command to add a primary key column EmpId of integer type to the table Employee is:

ALTER TABLE Employee 

ADD EmpId INT PRIMARY KEY;

The command to insert the record in the table is:

INSERT INTO Employee (EmpId, Ename, Department, Salary) 

VALUES (999, ‘Shweta’, ‘Production’, 26900);

Detailed answer by teachoo

  • To add a primary key column EmpId of integer type to the table Employee , we can use the ALTER TABLE statement with the ADD COLUMN clause.

The SQL command to add the primary key column is as follows:

ALTER TABLE Employee 

ADD EmpId INT PRIMARY KEY;

This command modifies the existing Employee table by adding a new column called EmpId of integer type ( INT ). The PRIMARY KEY constraint is added to the column, which ensures that each value in the EmpId column is unique and serves as the primary key for the table.

  • After adding the primary key column, we can insert the given record into the table using the INSERT INTO statement.

The SQL command to insert the record is as follows:

INSERT INTO Employee (EmpId, Ename, Department, Salary) 

VALUES (999, ‘Shweta’, ‘Production’, 26900);

This command inserts a new row into the Employee table with the specified values. The EmpId column is assigned a value of 999 , Ename column is assigned 'Shweta' , Department column is assigned 'Production' , and Salary column is assigned 26900 .

Go Ad-free
Davneet Singh's photo - Co-founder, Teachoo

Made by

Davneet Singh

Davneet Singh has done his B.Tech from Indian Institute of Technology, Kanpur. He has been teaching from the past 14 years. He provides courses for Maths, Science and Computer Science at Teachoo