Creating and Populating Tables.
Creating and Populating Tables.
1. Write the SQL command to create a table Employee with fields: EmpID (integer,
primary key), Name (varchar(30)), and Salary (float).
Answer:
2. Write an SQL command to insert the following record into the Employee table: EmpID
= 101, Name = 'Ravi', Salary = 45000.
Answer:
3. Write an SQL command to create a table Library with fields: BookID (integer, primary
key), Title (varchar(50)), Author (varchar(30)), and Price (float).
Answer:
Title VARCHAR(50),
Author VARCHAR(30),
Price FLOAT );
4. What is the use of the DEFAULT constraint? Give an example while creating a table.
Answer:
The DEFAULT constraint provides a default value for a column when no value is specified.
Example:
Name VARCHAR(30),
5. Write an SQL command to insert multiple rows into a Department table with fields:
DeptID, DeptName.
Answer:
INSERT INTO Department (DeptID, DeptName)
VALUES
(1, 'HR'),
(2, 'Finance'),
(3, 'IT');
Answer:
NOT NULL ensures that a column cannot have a NULL value.
Example:
Price FLOAT
);
7. Write SQL commands to create and populate a Courses table with columns CourseID,
CourseName, and Duration.
Answer:
CourseName VARCHAR(50),
Duration INT
);
8. Create a table Marks with fields: StudentID, Subject, Marks, where StudentID and
Subject together form a composite primary key.
Answer:
Answer:
Data types define the kind of data a column can hold (e.g., INT, VARCHAR, DATE). They
ensure data consistency, optimize storage, and help maintain data integrity.
10. Create a table Orders with fields: OrderID (integer, primary key), CustomerName
(varchar(50)), and OrderDate (DATE).
Answer: