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
585
votes
12 answers

How do you rename a MongoDB database?

There's a typo in my MongoDB database name and I'm looking to rename the database. I can copy and delete like so... db.copyDatabase('old_name', 'new_name'); use old_name db.dropDatabase(); Is there a command to rename a database?
Brian Hempel
  • 8,844
  • 2
  • 24
  • 19
580
votes
10 answers

How to shrink/purge ibdata1 file in MySQL

I am using MySQL in localhost as a "query tool" for performing statistics in R, that is, everytime I run a R script, I create a new database (A), create a new table (B), import the data into B, submit a query to get what I need, and then I drop B…
lokheart
  • 23,743
  • 39
  • 98
  • 169
569
votes
25 answers

How to get a list of column names on Sqlite3 database?

I want to migrate my iPhone app to a new database version. Since I don't have some version saved, I need to check if certain column names exist. This Stackoverflow entry suggests doing the select SELECT sql FROM sqlite_master WHERE tbl_name =…
luebken
  • 6,221
  • 5
  • 22
  • 18
566
votes
40 answers

Database development mistakes made by application developers

What are common database development mistakes made by application developers?
Charles Faiga
  • 11,665
  • 25
  • 102
  • 139
542
votes
25 answers

Kill a postgresql session/connection

How can I kill all my postgresql connections? I'm trying a rake db:drop but I get: ERROR: database "database_name" is being accessed by other users DETAIL: There are 1 other session(s) using the database. I've tried shutting down the processes I…
DanS
  • 17,550
  • 9
  • 53
  • 47
538
votes
13 answers

Room - Schema export directory is not provided to the annotation processor so we cannot export the schema

I am using Android Database Component Room I've configured everything, but when I compile, Android Studio gives me this warning: Schema export directory is not provided to the annotation processor so we cannot export the schema. You can either…
Misha Akopov
  • 12,241
  • 27
  • 68
  • 82
535
votes
28 answers

MySQL Error: : 'Access denied for user 'root'@'localhost'

Consider: ./mysqladmin -u root -p** '_redacted_' Output (including typing the password): Enter password: mysqladmin: connect to server at 'localhost' failed error: 'Access denied for user 'root'@'localhost' (using password: YES)' How can I fix…
Harsh Trivedi
  • 5,591
  • 3
  • 12
  • 14
535
votes
8 answers

Best way to store password in database

I am working on a project that has to have authentication (username and password) It also connects to a database, so I figured I would store the username and password there. However, it seems like not such a good idea to have passwords as just a…
Crash893
  • 11,428
  • 21
  • 88
  • 123
525
votes
8 answers

Maximum length for MySQL type text

I'm creating a form for sending private messages and want to set the maxlength value of a textarea appropriate to the max length of a text field in my MySQL database table. How many characters can a type text field store? If a lot, would I be able…
CyberJunkie
  • 21,596
  • 59
  • 148
  • 215
517
votes
30 answers

How can I stop redis-server?

I apparently have a redis-server instance running because when I try to start a new server by entering redis-server, I'm greeted with the following: Opening port: bind: Address already in use I can't figure out how to stop this server and start a…
Qcom
  • 18,263
  • 29
  • 87
  • 113
517
votes
25 answers

How should I resolve --secure-file-priv in MySQL?

I am learning MySQL and tried using a LOAD DATA clause. When I used it as below: LOAD DATA INFILE "text.txt" INTO table mytable; I got the following error: The MySQL server is running with the --secure-file-priv option so it cannot execute this…
m0bi5
  • 8,900
  • 7
  • 33
  • 44
505
votes
5 answers

What's the Hi/Lo algorithm?

What's the Hi/Lo algorithm? I've found this in the NHibernate documentation (it's one method to generate unique keys, section 5.1.4.2), but I haven't found a good explanation of how it works. I know that Nhibernate handles it, and I don't need to…
DiegoCofre
  • 5,053
  • 3
  • 17
  • 6
495
votes
8 answers

Is there an SQLite equivalent to MySQL's DESCRIBE [table]?

I'm just getting started learning SQLite. It would be nice to be able to see the details for a table, like MySQL's DESCRIBE [table]. PRAGMA table_info [table] isn't good enough, as it only has basic information (for example, it doesn't show if a…
Matthew
  • 28,056
  • 26
  • 104
  • 170
487
votes
13 answers

List of standard lengths for database fields

I'm designing a database table and asking myself this question: How long should the firstname field be? Does anyone have a list of reasonable lengths for the most common fields, such as first name, last name, and email address?
Patrick McElhaney
  • 57,901
  • 40
  • 134
  • 167
487
votes
34 answers

How to select the nth row in a SQL database table?

I'm interested in learning some (ideally) database agnostic ways of selecting the nth row from a database table. It would also be interesting to see how this can be achieved using the native functionality of the following databases: SQL…
Charles Roper
  • 20,125
  • 20
  • 71
  • 101