0% found this document useful (0 votes)
4 views4 pages

Lab SQL 16.11.2024

The document provides instructions for setting up and using SQLite3, including creating a database, performing CRUD operations, and managing tables. It outlines specific tasks such as creating a 'Student' table, inserting data, adding columns, and retrieving information based on various conditions. Additionally, it includes a task to create a 'POSITION' table with specified fields and values.

Uploaded by

memmedli0014
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views4 pages

Lab SQL 16.11.2024

The document provides instructions for setting up and using SQLite3, including creating a database, performing CRUD operations, and managing tables. It outlines specific tasks such as creating a 'Student' table, inserting data, adding columns, and retrieving information based on various conditions. Additionally, it includes a task to create a 'POSITION' table with specified fields and values.

Uploaded by

memmedli0014
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

Lab for 843i

SQL
On your computer, create a new folder
Download SQLite3: https://www.sqlite.org/download.html
Run SQLite3
Double-clicking the sqlite3.exe icon will open a pop-up terminal window with
sqlite running. This will create a temporary, untitled database db1.db that will
be deleted when you exit the session
SQL Operators
 .save path
 .open path
 .tables list of tables
 .schema table_name Retrieve a list of columns in the tables
The CRUD Operations
CRUD (Create, Read, Update and Delete).

• Create = INSERT
• Read = SELECT
• Update = UPDATE
• Delete = DELETE
Sample:
a) Create table Personnel
Id PName PSname PAge

CREATE TABLE Personnel (Id Integer Primary Key, PName varchar(30), PSname
varchar(30) ,Age integer);
b) Insert data into the table

INSERT INTO Personnel (PName, PSname ,Age) VALUES (‘Vali’,’Imanov’,21);


INSERT INTO Personnel (PName, PSname ,Age) VALUES (’Ulya’,’Mamedova’,22),
(’Said’,’Aliyev’,21);

c) Save the database in your folder


.save d:\YourFolder\Dbname.db
d) Retrieve data from the table
SELECT * FROM Personnel;
SELECT Pname FROM Personnel;
SELECT * FROM Personnel WHERE Age=22;
OR:
( Age >21, Age<21, PName like ‘Va%’)
SELECT PName FROM Personnel WHERE PName IN ('Vali','TTT');
SELECT PName FROM Personnel WHERE PName IN ('Vali','Said') AND
age>25;

e) Change the data in the table


UPDATE Personnel SET PName= ‘Sara’ WHERE id=2;
f) Add column into the table
ALTER TABLE Personnel ADD COLUMN Address;
g) Check last changes in the table
.schema Personnel
h) Check what tables we have in the database
.table

Task:

1. Create Folder University

2.Run SQLite

3.Create table Student


Id Name Sname Age
1 John Doe 31
2 Robert Luna 22
3 David Robinson 22
4 John Reinhardt 25
5 Betty Doe 28
Name , Sname - type varchar (20)

Age, Phone - type integer

4. Insert data into the table (5 records)

5. Add column Address

6. Save the database as AzMIU.db in University folder

7. Retrieve data from Student:

All data,
Only data for students with the name JOHN
Names of students with the age > 23
Names and Snames of students with the age < 25

8. Udate data: add data in the column Address

9. Save the database, Close SQLite3 window


Open database

10. Create new table


POSITION
Psn_id Position Salary
1 HR Manager (Human 2000
Resources Manager)
2 Financial Analyst 2100
3 Marketing Specialist 1800
4 Sales Manager 1900
5 Sales assistant 800
6 Сashier 950

https://www.programiz.com/sql/online-compiler/

[email protected]

You might also like