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
763
votes
6 answers

MongoDB vs. Cassandra

I am evaluating what might be the best migration option. Currently, I am on a sharded MySQL (horizontal partition), with most of my data stored in JSON blobs. I do not have any complex SQL queries (already migrated away after since I partitioned my…
meow
  • 27,476
  • 33
  • 116
  • 177
761
votes
8 answers

'IF' in 'SELECT' statement - choose output value based on column values

SELECT id, amount FROM report I need amount to be amount if report.type='P' and -amount if report.type='N'. How do I add this to the above query?
Michael
  • 13,838
  • 18
  • 52
  • 81
728
votes
22 answers

Solutions for INSERT OR UPDATE on SQL Server

Assume a table structure of MyTable(KEY, datafield1, datafield2...). Often I want to either update an existing record, or insert a new record if it doesn't exist. Essentially: IF (key exists) run update command ELSE run insert command What's…
Chris Cudmore
  • 29,793
  • 12
  • 57
  • 94
725
votes
10 answers

How can I avoid concurrency problems when using SQLite on Android?

What would be considered the best practices when executing queries on an SQLite database within an Android app? Is it safe to run inserts, deletes and select queries from an AsyncTask's doInBackground? Or should I use the UI Thread? I suppose that…
Vidar Vestnes
  • 42,644
  • 28
  • 86
  • 100
722
votes
24 answers

How to drop columns using Rails migration

What's the syntax for dropping a database table column through a Rails migration?
Ethan
  • 9,558
  • 5
  • 27
  • 24
715
votes
6 answers

Difference between rake db:migrate db:reset and db:schema:load

The difference between rake db:migrate and rake db:reset is pretty clear to me. The thing which I don't understand is how rake db:schema:load is different from the former two. Just to be sure that I am on the same page: rake db:migrate - Runs the…
Gaurav Agarwal
  • 14,664
  • 4
  • 29
  • 41
671
votes
20 answers

Import SQL dump into PostgreSQL database

We are switching hosts and the old one provided a SQL dump of the PostgreSQL database of our site. Now, I'm trying to set this up on a local WAMP server to test this. The only problem is that I don't have an idea how to import this database in the…
dazz
  • 8,162
  • 9
  • 31
  • 41
671
votes
11 answers

How to skip certain database tables with mysqldump?

Is there a way to restrict certain tables from the mysqldump command? For example, I'd use the following syntax to dump only table1 and table2: mysqldump -u username -p database table1 table2 > database.sql But is there a similar way to dump all…
Zac
  • 1,010
  • 3
  • 11
  • 20
663
votes
11 answers

How do you query for "is not null" in Mongo?

I would like to execute a following query: db.mycollection.find(HAS IMAGE URL) What should be the correct syntax?
TIMEX
  • 259,804
  • 351
  • 777
  • 1,080
654
votes
19 answers

How do I restore a dump file from mysqldump?

I was given a MySQL database file that I need to restore as a database on my Windows Server 2008 machine. I tried using MySQL Administrator, but I got the following error: The selected file was generated by mysqldump and cannot be restored by …
Zack Peterson
  • 56,055
  • 78
  • 209
  • 280
652
votes
10 answers

Difference between partition key, composite key and clustering key in Cassandra?

I have been reading articles around the net to understand the differences between the following key types. But it just seems hard for me to grasp. Examples will definitely help make understanding better. primary key, partition key, composite key…
brain storm
  • 30,124
  • 69
  • 225
  • 393
638
votes
66 answers

Postgres could not connect to server

After I did brew update and brew upgrade, my postgres got some problem. I tried to uninstall postgres and install it again, but it didn't work as well. This is the error message. (I also got this error message when I try to do rake db:migrate) $…
Gary Lai
  • 6,543
  • 3
  • 17
  • 16
630
votes
13 answers

Copying PostgreSQL database to another server

I'm looking to copy a production PostgreSQL database to a development server. What's the quickest, easiest way to go about doing this?
Robin Barnes
  • 13,133
  • 15
  • 44
  • 45
614
votes
30 answers

Elasticsearch query to return all records

I have a small database in Elasticsearch and for testing purposes would like to pull all records back. I am attempting to use a URL of the form... http://localhost:9200/foo/_search?pretty=true&q={'matchAll':{''}} Can someone give me the URL you…
John Livermore
  • 30,235
  • 44
  • 126
  • 216
613
votes
58 answers

Do you use source control for your database items?

I feel that my shop has a hole because we don't have a solid process in place for versioning our database schema changes. We do a lot of backups so we're more or less covered, but it's bad practice to rely on your last line of defense in this way.…
Brian MacKay
  • 31,133
  • 17
  • 86
  • 125