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
414
votes
10 answers

Is storing a delimited list in a database column really that bad?

Imagine a web form with a set of check boxes (any or all of them can be selected). I chose to save them in a comma separated list of values stored in one column of the database table. Now, I know that the correct solution would be to create a second…
Mad Scientist
  • 18,090
  • 12
  • 83
  • 109
412
votes
13 answers

How to create a yes/no boolean field in SQL server?

What is the best practice for creating a yes/no i.e. Boolean field when converting from an access database or in general?
leora
  • 188,729
  • 360
  • 878
  • 1,366
408
votes
17 answers

Should each and every table have a primary key?

I'm creating a database table and I don't have a logical primary key assigned to it. Should each and every table have a primary key?
Daniel Silveira
  • 41,125
  • 36
  • 100
  • 121
407
votes
32 answers

Get the Last Inserted Id Using Laravel Eloquent

I'm currently using the below code to insert data in a table: nombre = $post['name']; $data->direccion = $post['address']; …
SoldierCorp
  • 7,610
  • 16
  • 60
  • 100
406
votes
5 answers

What's the difference between CharField and TextField in Django?

The documentation says that CharField() should be used for smaller strings and TextField() should be used for larger strings. Okay, but where is the line drawn between "small" and "large"? What's going on under the hood here that makes this the…
Jonathan Gleason
  • 4,567
  • 3
  • 17
  • 18
405
votes
7 answers

When and why are database joins expensive?

I'm doing some research into databases and I'm looking at some limitations of relational DBs. I'm getting that joins of large tables is very expensive, but I'm not completely sure why. What does the DBMS need to do to execute a join operation,…
Rik
  • 28,507
  • 14
  • 48
  • 67
403
votes
7 answers

What's the best strategy for unit-testing database-driven applications?

I work with a lot of web applications that are driven by databases of varying complexity on the backend. Typically, there's an ORM layer separate from the business and presentation logic. This makes unit-testing the business logic fairly…
friedo
  • 65,762
  • 16
  • 114
  • 184
400
votes
10 answers

How to replace a string in a SQL Server Table Column

I have a table (SQL Sever) which references paths (UNC or otherwise), but now the path is going to change. In the path column, I have many records and I need to change just a portion of the path, but not the entire path. And I need to change the…
Iralda Mitro
  • 7,190
  • 5
  • 24
  • 29
399
votes
8 answers

What datatype to use when storing latitude and longitude data in SQL databases?

When storing latitude or longitude data in an ANSI SQL compliant database, what datatype would be most appropriate? Should float be used, or decimal, or ...? I'm aware that Oracle, MySql, and SQL Server have added some special datatypes specifically…
dthrasher
  • 40,656
  • 34
  • 113
  • 139
396
votes
12 answers

How to compare only Date without Time in DateTime types?

Is there a way to compare two DateTime variables but to disregard the Time part. The app stores items in the DB and adds a published date. I want to keep the exact time but still be able to pull by the date itself. I want to compare 12/3/89 12:43:34…
Sruly
  • 10,200
  • 6
  • 34
  • 39
394
votes
12 answers

Liquibase lock - reasons?

I get this when running a lot of liquibase-scripts against a Oracle-server. SomeComputer is me. Waiting for changelog lock.... Waiting for changelog lock.... Waiting for changelog lock.... Waiting for changelog lock.... Waiting for changelog…
Peter
  • 5,556
  • 3
  • 23
  • 38
388
votes
8 answers

What database does Google use?

Is it Oracle or MySQL or something they have built themselves?
solrevdev
  • 8,863
  • 11
  • 41
  • 49
381
votes
19 answers

Adding a new value to an existing ENUM Type

I have a table column that uses an enum type. I wish to update that enum type to have an additional possible value. I don't want to delete any existing values, just add the new value. What is the simplest way to do this?
Ian
  • 24,116
  • 22
  • 58
  • 96
380
votes
32 answers

What's the difference between TRUNCATE and DELETE in SQL

What's the difference between TRUNCATE and DELETE in SQL? If your answer is platform specific, please indicate that.
David Aldridge
  • 51,479
  • 8
  • 68
  • 96
380
votes
10 answers

Difference Between Schema / Database in MySQL

Is there a difference between a schema and a database in MySQL? In SQL Server, a database is a higher level container in relation to a schema. I read that Create Schema and Create Database do essentially the same thing in MySQL, which leads me to…
Lloyd Banks
  • 35,740
  • 58
  • 156
  • 248