SQL Essentials: Database, Table,
and Record Operations
Database system
Creating a Database
CREATE DATABASE dbname;
Replace dbname with your desired database name.
Example: CREATE DATABASE CompanyDB;
Creating Tables
CREATE TABLE Employees ( EmployeeID INT PRIMARY KEY, FirstName VARCHAR(50), LastName
VARCHAR(50), Salary DECIMAL(10,2) );
Data Types
INT: Integer
VARCHAR(n): Variable-length character string with a maximum length of 'n'
DECIMAL(p, s): Decimal number with precision 'p' and scale 's'
Updating Table Records
UPDATE tablename
SET column1 = value1, column2 = value2
WHERE condition;
Updating Table Records
UPDATE Employees
SET Salary = 60000
WHERE EmployeeID = 101;
Task
Write an SQL query to create a database named "CompanyDB.“
Write an SQL query to create a table named "Employees" with the following columns:
EmployeeID (Integer, Primary Key)
FirstName (Variable-length character string with a maximum length of 50)
LastName (Variable-length character string with a maximum length of 50)
Salary (Decimal number with precision 10 and scale 2)
Write an SQL query to update the salary of the employee with EmployeeID 101 to 60000.
Task Answer
CREATE DATABASE CompanyDB;
CREATE TABLE Employees (
EmployeeID INT PRIMARY KEY,
FirstName VARCHAR(50),
LastName VARCHAR(50),
Salary DECIMAL(10,2)
);
UPDATE Employees
SET Salary = 60000
WHERE EmployeeID = 101;