Questions tagged [database]

A database is an organized collection of data. It is the collection of schemas, tables, queries, reports, views, and other objects. The data are typically organized to model aspects of reality in a way that supports processes requiring information. Use this tag if you have questions about designing a database. If it is about a particular database management system, (e.g., MySQL), please use that tag instead.

From Wikipedia:

A database is an organized collection of data. It is the collection of tables, queries, reports, views and other objects. The data is typically organized to model aspects of reality in a way that supports processes requiring information, such as modelling the availability of rooms in hotels in a way that supports finding a hotel with vacancies.

A large proportion of websites and applications rely on databases. They are a crucial component of telecommunications systems, banking systems, video games, and just about any other software system or electronic device that maintains some amount of persistent information. In addition to persistence, database systems provide a number of other properties that make them exceptionally useful and convenient: reliability, efficiency, scalability, concurrency control, data abstraction, and high-level query languages. Databases are so ubiquitous and important that computer science graduates frequently cite their database class as the one most useful to them in their industry or graduate-school careers.2

The term database should not be confused with Database Management System (DBMS). A DBMS is the system software used to create and manage databases and provide users and applications with access to the database(s). A database is to a DBMS as a document is to a word processor.

Database Languages

Database languages are special-purpose languages, which do one or more of the following:

###ACID In computer science, ACID (Atomicity, Consistency, Isolation, Durability) is a set of properties of database transactions.

  1. Atomicity - Atomicity requires that each transaction be "all or nothing": if one part of the transaction fails, then the entire transaction fails, and the database state is left unchanged. An atomic system must guarantee atomicity in each and every situation, including power failures, errors, and crashes. To the outside world, a committed transaction appears (by its effects on the database) to be indivisible ("atomic"), and an aborted transaction does not happen.

  2. Consistency - The consistency property ensures that any transaction will bring the database from one valid state to another. Any data written to the database must be valid according to all defined rules, including constraints, cascades, triggers, and any combination thereof. This does not guarantee correctness of the transaction in all ways the application programmer might have wanted (that is the responsibility of application-level code) but merely that any programming errors cannot result in the violation of any defined rules.

  3. Isolation - The isolation property ensures that the concurrent execution of transactions results in a system state that would be obtained if transactions were executed serially, i.e., one after the other. Providing isolation is the main goal of concurrency control. Depending on the concurrency control method (i.e., if it uses strict - as opposed to relaxed - serializability), the effects of an incomplete transaction might not even be visible to another transaction.

  4. Durability - The durability property ensures that once a transaction has been committed, it will remain so, even in the event of power loss, crashes, or errors. In a relational database, for instance, once a group of SQL statements execute, the results need to be stored permanently (even if the database crashes immediately thereafter). To defend against power loss, transactions (or their effects) must be recorded in a non-volatile memory.

A few notable DBMSs:

Popular Database tools

Some useful references:

Free online database courses:

193843 questions
36
votes
3 answers

What is the maximum number of connections for a SQLite3 database?

What is the maximum number of connections for a SQLite3 database? Why can't I use it for very big websites, for example with 3 million users?
Michael harris
  • 966
  • 2
  • 14
  • 25
36
votes
2 answers

Where does Chrome save its SQLite database to?

Google Chrome stores internal data such as browser history in a SQLite database; where is this saved to?
vivianaranha
  • 2,781
  • 6
  • 33
  • 47
36
votes
2 answers

MySQL concepts: session vs connection

I'm a bit confused by MySQL concepts: session vs connection. When talking about connecting to MySQL, we use connection terminology, connection pool, etc. However in the MySQL online doc:…
Xiaofeng Tang
  • 476
  • 1
  • 6
  • 8
36
votes
5 answers

Oracle - How to create a materialized view with FAST REFRESH and JOINS

So I'm pretty sure Oracle supports this, so I have no idea what I'm doing wrong. This code works: CREATE MATERIALIZED VIEW MV_Test NOLOGGING CACHE BUILD IMMEDIATE REFRESH FAST ON COMMIT AS SELECT V.* FROM TPM_PROJECTVERSION V; If I…
Mike Christensen
  • 88,082
  • 50
  • 208
  • 326
36
votes
8 answers

Database query time complexity

I'm pretty new to databases, so forgive me if this is a silly question. In modern databases, if I use an index to access a row, I believe this will be O(1) complexity. But if I do a query to select another column, will it be O(1) or O(n)? Does the…
Zifre
  • 26,504
  • 11
  • 85
  • 105
36
votes
7 answers

MySQL query, MAX() + GROUP BY

Daft SQL question. I have a table like so ('pid' is auto-increment primary col) CREATE TABLE theTable ( `pid` INT UNSIGNED PRIMARY KEY AUTO_INCREMENT, `timestamp` TIMESTAMP DEFAULT CURRENT_TIMESTAMP, `cost` INT UNSIGNED NOT NULL, …
codinghands
  • 1,741
  • 2
  • 18
  • 31
36
votes
6 answers

SQL Query - how do filter by null or not null

I want to filter a record.... If statusid is null, filter the record (where statusId is not null) If statusid is not null, filter the record where statusid is equal to the specified statusid. How do I do this?
001
  • 62,807
  • 94
  • 230
  • 350
36
votes
14 answers

Databases versus plain text

When dealing with small projects, what do you feel is the break even point for storing data in simple text files, hash tables, etc., versus using a real database? For small projects with simple data management requirements, a real database is…
dsimcha
  • 67,514
  • 53
  • 213
  • 334
36
votes
3 answers

How to drop multiple databases in SQL Server

Just to clarify, ths isn't really a question, more some help for people like me who were looking for an answer. A lot of applications create temp tables and the like, but I was surprised when Team Foundation Server created 80+ databases on my test…
Gargravarr
  • 635
  • 2
  • 10
  • 18
36
votes
7 answers

Leaderboard ranking with Firebase

I have project that I need to display a leaderboard of the top 20, and if the user not in the leaderboard they will appear in the 21st place with their current ranking. Is there efficient way to this? I am using Cloud Firestore as a database. I…
36
votes
1 answer

SQL JSON - How to modify boolean value present in the Json Data

How can I modify the existing boolean value of a json data in SQL Server 2016 - Json? Below is the script for inserting json Data. DECLARE @a nvarchar(max) = N'{"employeeName":"Test","isActive":true}'; insert into TestTable(testId,name,jsonData)…
Viresh Mathad
  • 576
  • 1
  • 5
  • 19
36
votes
2 answers

What does eq_ref and ref types mean in MySQL explain

When we prefix an SQL query with the keyword "explain" we get a table with some columns. Please tell me what is the "type" column. What does eq_ref and ref mean in that context.
Patruni Srikanth
  • 741
  • 1
  • 7
  • 14
36
votes
6 answers

In Laravel, how do I retrieve a random user_id from the Users table for Model Factory seeding data generation?

Currently, in my ModelFactory.php, I have: $factory->define(App\Reply::class, function (Faker\Generator $faker) { return [ 'thread_id' => 1, 'user_id' => 1, 'body' => $faker->paragraph ]; }); I would like to generate a random…
Simon Suh
  • 10,599
  • 25
  • 86
  • 110
36
votes
4 answers

How do I turn MongoDB query into a JSON?

for p in db.collection.find({"test_set":"abc"}): posts.append(p) thejson = json.dumps({'results':posts}) return HttpResponse(thejson, mimetype="application/javascript") In my Django/Python code, I can't return a JSON from a mongo query because…
TIMEX
  • 259,804
  • 351
  • 777
  • 1,080
36
votes
6 answers

What is a "distributed transaction"?

The Wikipedia article for Distributed transaction isn't very helpful. Can you give a high-level description with more details of what a distributed transaction is? Also, can you give me an example of why an application or database should perform a…
Zombie
  • 361
  • 1
  • 3
  • 4