0% found this document useful (0 votes)
18 views

Database System Lab-3

This document discusses SQL operations for databases, tables, and records. It explains how to create a database and table, defines data types, and provides an example of updating a record in a table.

Uploaded by

Hafiz Mian 10
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
18 views

Database System Lab-3

This document discusses SQL operations for databases, tables, and records. It explains how to create a database and table, defines data types, and provides an example of updating a record in a table.

Uploaded by

Hafiz Mian 10
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 8

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;

You might also like