Found 12 Articles for SQLite

How to Create a Backup of a SQLite Database Using Python?

Mukul Latiyan
Updated on 20-Apr-2023 14:00:36

2K+ Views

SQLite is a popular lightweight and server less database management system used in many applications. It is known for its ease of use, small footprint, and portability. However, just like any other database, it is important to have a backup of your SQLite database to protect against data loss. Python is a powerful programming language that is widely used for various tasks including data processing and management. In this tutorial, we will explore how to create a backup of a SQLite database using Python. We will walk through the process of connecting to a SQLite database, creating a backup file, ... Read More

Write a SQL query to count the number of duplicate TRANSACTION_ID in an ORDERS DB2 table

Mandalika
Updated on 01-Dec-2020 04:39:32

2K+ Views

We can find the duplicate TRANSACTION_ID in the ORDERS DB2 table using the below query:ExampleSELECT TRANSACTION_ID, COUNT(*) AS TRANSACTION_COUNT FROM ORDER GROUP BY TRANSACTION_ID HAVING COUNT(*) > 1The purpose of COUNT(*) is to count the number of rows. We will group the result based on the TRANSACTION_ID using GROUP BY function and to display the duplicate transaction ids, we will place a predicate using HAVING statement for COUNT(*) greater than one.For example, consider the below TRANSACTIONS DB2 table:TRANSACTION_IDTRANSACTION_STATUSIRN22345PAIDIRN22345PAIDIRN22345PAIDIRN56902PAIDIRN99781UNPAIDIRN56902PAIDThe query will give the below result:TRANSACTION_IDTRANSACTION_COUNTIRN223453IRN569022IRN997811Read More

Explain SQL describing COUNT aggregate and CURRENT DATE function

Mandalika
Updated on 01-Dec-2020 04:38:41

373 Views

Problem: Write a SQL query to count the number of orders which were placed today from the ORDERS DB2 table. (The date should not be hardcoded)SolutionWe can find the count of orders which are placed today using the below DB2 query:ExampleSELECT COUNT(ORDER_ID) AS ORDER_COUNT FROM ORDERS WHERE ORDER_DATE = CURRENT DATEIn this query, we have used the COUNT COLUMN function which will count the total number of ORDER_ID (primary key). In the WHERE clause, we will use the predicate for the ORDER_DATE column. The CURRENT DATE is a DB2 inbuilt function which will return the current system date.For example, if ... Read More

Example of SQL query describing the conditional processing

Mandalika
Updated on 30-Nov-2020 09:42:48

233 Views

Problem: Write a SQL query to display 2 columns. First column should have ORDER_ID, the second column should give the value as YES/NO for free shipping based on ORDER_TOTAL > 500.SolutionThe query to display ORDER_ID and free shipping result based on the ORDER_TOTAL criteria can be written as below.ExampleSELECT ORDER_ID,    CASE WHEN ORDER_TOTAL > 500 THEN ‘YES’       ELSE ‘NO’ AS FREE_SHIPPING    END FROM ORDERSWe will use CASE expressions through which we can implement a logic to check the ORDER_TOTAL. If the ORDER_TOTAL is greater than 500 then we will get ‘YES’ for the free shipping ... Read More

Difference between stored procedure and triggers in SQL

Venu Madhavi
Updated on 22-Jan-2025 17:42:32

19K+ Views

Stored Procedures Stored Procedures is a group of pre-compiled SQL statements that is stored in a database and can be reused anytime. It allows you to do many things in one command. So doing several activities in a database will be easier and quicker than before. A stored procedure can be called from SQL commands as well as applications like Python, Java, or PHP. Syntax Following is the syntax to create a stored procedure − CREATE PROCEDURE procedure_name AS BEGIN -- SQL statements END; Example Let us create a stored procedure where it ... Read More

Difference between correlated and non-collreated subqueries in SQL

Himanshu shriv
Updated on 23-Dec-2024 19:33:52

12K+ Views

SQL query is used to fetch data from the database. In some of the scenario you may need some perquisite data to call subsequent SQL query to fetch data from a table so instead of writing two seperate query we can write SQL query within the query. Therefore subQuery is a way to combine or join them in single query. Subqurey can have two types −Correlated subquery - In correlated subquery, inner query is dependent on the outer query. Outer query needs to be executed before inner queryNon-Correlated subquery - In non-correlated query inner query does not dependent on the outer ... Read More

Difference between hierarchical and network database model in SQL

Himanshu shriv
Updated on 24-Dec-2024 17:56:16

11K+ Views

Hierarchical Data Model In the Hierarchical data model, the relationship between the table and data is defined in parent-child structure. In this structure, data is arranged in the form of a tree structure. This model supports one-to-one and one-to-many relationships. Network Model The Network model arranges data in a graph structure. In this model, each parent can have multiple children, and children can also have multiple parents. This model supports many-to-many relationships as well. Comparison Table ... Read More

Difference between Inner and Outer join in SQL

Himanshu shriv
Updated on 21-Jan-2020 09:41:05

2K+ Views

In Relational database tables are associated with each other and we used foreign key to maintain relationships between tables. We used join clause to retrieve data from associated tables. The join condition indicates how column in each table are matched against each other. There are two types of joins clause in SQL Inner join Outer joinOuter join is again divided into parts −LEFT OUTER JOIN - It will return all data of the left table and matched  records in both table RIGHT OUTER JOIN - it will return all the data of the right table and matched records in both tableSr. No.KeyInner joinOuter join1Basic It ... Read More

Block of PL/SQL in Oracle DBMS

Ricky Barnes
Updated on 20-Jun-2020 08:55:16

4K+ Views

PL/SQL is a block structured language i.e the code of PL./SQL is written in the form of blocks. PL/SQL also contains the robustness, security and portability of the Oracle database.Each block of PL/SQL contains the following subparts −Declarations -  This section contains all the items that needs to be declared before the program such as variables, subprograms etc. This section contains the keyword DECLARE at its start. In general, Declarations is an optional subpart of the PL/SQL program.Executable Commands -  This section of the PL/SQL code contains the executable statements. It contains BEGIN and END at its starting and ending. ... Read More

Overview of Packages in Oracle

Alex Onsman
Updated on 20-Jun-2020 08:46:22

790 Views

Packages are SQL procedures, functions, variables, statements etc. that are grouped into a single unit. Many different applications can share the contents of a package, as it is stored in the database.Parts of a PackageThe following are the parts of a package in Oracle −Package SpecificationThe package specifications contains information about all the procedures, functions, variables, constants etc. stored inside it. It has the declaration of all the components but not the code.All the objects that are in the specification are known as public objects. If there is any object that is not available in the specification but is coded ... Read More

Advertisements