본문 바로가기

SQL

(10)
[sqlite3] Using SQLite in IDEs 1. Using SQLite in Python 1.1 What is sqlite3 module? SQLite is a C library that provides a light weight disk-based database that doesn't require a separate server process and allows accessing file database using a nonstandard variant of the SQL query language. The sqlite3 module provides an SQL interface compliant with the DB-API 2.0. 1.2 How to use sqlite3 module? Step 1 : Import module The sq..
[psycopg2] SQL Injection and Ways to defened it 1. What is SQL Injection? SQL Injection is a method for code injection attack that intentionally exploits application security loopholes to cause malicious SQL statements to be executed, resulting in abnormal manipulation of the database. query = "SELECT * FROM users WHERE username = '" + name + "';" The above code selects a row that receives an ID and password from a user and matches it. Howeve..
[psycopg2] SQL Transactions 1. What is SQL Transactions? A Database Transaction is a unit of interaction in a database management system or a similar system. Here, a similar system means a system in which transactions are clear, mutually independent, consistent, and reliable in success and failure. That is, it refers to a unit of work performed to change the state of the database. In theory, the database system guarentees ..
[psycopg2] Executing Postgres query in Python script 1. Workflow of executing query in Python script psycopg2 is a package for using Postgres in Python script. In the same way as sqlite3, a conn instance and a cursor instance are created to create a query. In Postgres, we have transaction notation when we commit the queries to sever. A new transcation will automatically be created when we open a connection in psycopg2. When a commit is called, the..
[psycopg2] How to use Postgres in Python 1. What is Postgres? Relational Database Management System(RDBMS) is a set of software tools that allow multiple users to access data within a database. DBMS allows users or other programs to process and responds appropriately to use data. For SQLite, only a single process is allowed to write to the database (It only process query statement one by one.). Therefore, there is a limit to working wi..
[sqlite3] Creating a sqlite database from CSV file 1. How to create a sqlite database from CSV file? Step 1 : Creating a sqlite database sqlite is a ligthweight database that can be started as an empty text file. We can create the file with touch data.db. from pathlib import Path Path('cars.db').toucn() Step 2 : Create a connection and cursor object Create a database connection and cursor to execute queries. We can use functions called connect a..
[Syntax] Data Definition Language 1. What is DDL? In the context of SQL, Data Definition Language(DDL) is a syntax for creating and modifying database objects such as tables, indices, and users. DDL statement are similar to a computer programming language for defining dat structures, especially database schemas. Common examples of DDL statements include CREATE, ALTER, and DROP. 2. CREATE CREATE clause make tables in database. CR..
[Syntax] Writing Efficient Query 1. Views In a database, a View is the result set of a stored query on the data, which the database users can query just as they would in a persistent database collection object. This pre-established query command is kept in the database dictionary. Unlike ordinary base tables in relational database, a view doesn't form part of physical schema. A a result, it is a virtual table computed or collec..
[Syntax] Merging Tables 1. What is MERGE? The MERGE statement in SQL is a clause that can handle insert, update, and deletes all in a single transaction without having to write sepatate logic for each of these. Using the MERGE statement in SQL gives us better flexibility in customizing our complex SQL scripts and also enhances the readability of our scripts. 2. Kinds of Merge clause We can join data from more than two ..
[Theorem] What is SQLite? 1. What is SQL? SQL(Structured Query Language) is specific purposed programming language to manipulate tables from relational database management system(RDBMS). SQL was structured for createing and manipulating schemas, querying data and handling accessment of database object. 2. What is SQLite? SQLite is a database engine written in the C language. It is not a standlaone app; rather, it is a li..