0% found this document useful (0 votes)
11 views3 pages

Creating and Populating Tables.

The document provides SQL commands for creating and populating various database tables including Employee, Library, Student, Department, Product, Courses, Marks, and Orders. It explains key SQL concepts such as DEFAULT and NOT NULL constraints, and the significance of data types in ensuring data integrity. Additionally, it includes examples of inserting records into these tables.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views3 pages

Creating and Populating Tables.

The document provides SQL commands for creating and populating various database tables including Employee, Library, Student, Department, Product, Courses, Marks, and Orders. It explains key SQL concepts such as DEFAULT and NOT NULL constraints, and the significance of data types in ensuring data integrity. Additionally, it includes examples of inserting records into these tables.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

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:

CREATE TABLE Employee (


EmpID INT PRIMARY KEY,
Name VARCHAR(30),
Salary FLOAT );

2. Write an SQL command to insert the following record into the Employee table: EmpID
= 101, Name = 'Ravi', Salary = 45000.
Answer:

INSERT INTO Employee (EmpID, Name, Salary)


VALUES (101, 'Ravi', 45000);

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:

CREATE TABLE Library (

BookID INT PRIMARY KEY,

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:

CREATE TABLE Student (

RollNo INT PRIMARY KEY,

Name VARCHAR(30),

City VARCHAR(20) DEFAULT 'Delhi' );

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');

6. What is the use of the NOT NULL constraint? Write an example.

Answer:
NOT NULL ensures that a column cannot have a NULL value.

Example:

CREATE TABLE Product (

ProductID INT PRIMARY KEY,

Name VARCHAR(30) NOT NULL,

Price FLOAT

);

7. Write SQL commands to create and populate a Courses table with columns CourseID,
CourseName, and Duration.

Answer:

CREATE TABLE Courses (

CourseID INT PRIMARY KEY,

CourseName VARCHAR(50),

Duration INT

);

INSERT INTO Courses (CourseID, CourseName, Duration)

VALUES (1, 'Python Programming', 3);

8. Create a table Marks with fields: StudentID, Subject, Marks, where StudentID and
Subject together form a composite primary key.

Answer:

CREATE TABLE Marks (


StudentID INT,
Subject VARCHAR(30),
Marks INT,
PRIMARY KEY (StudentID, Subject));

9. Explain the significance of data types while creating a table.

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:

CREATE TABLE Orders (


OrderID INT PRIMARY KEY,
CustomerName VARCHAR(50),
OrderDate DATE );

You might also like