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
37
votes
4 answers

Querying oracle clob column

I have a table with a clob column. Searching based on the clob column content needs to be performed. However select * from aTable where aClobColumn = 'value'; fails but select * from aTable where aClobColumn like 'value'; seems to workfine. How…
Dev Blanked
  • 8,555
  • 3
  • 26
  • 32
37
votes
5 answers

MySQL Database backup automatically on a windows server

Is there a way to back up MySQL database automatically at certain times of the day for designated servers or send an email with an attachment.. Which ever do you think is the best and safest way to achieve this?
Coderwannabe
  • 407
  • 1
  • 5
  • 11
37
votes
6 answers

Why does SQL Server @@SERVERNAME return my old machine name?

I just stumbled across an issue in my SQL Server 2008 R2 - When I call @@SERVERNAME, it's returning my OLD computer's machine name, rather than the current one. Why is this? And how can I fix it? SQL Server somehow is remembering the old machine…
Jerry Dodge
  • 26,858
  • 31
  • 155
  • 327
37
votes
7 answers

Which is more expensive? For loop or database call?

In general, which is more expensive? A double-nested for loop and one call to a database or a call to a database for each of N items in only one for loop? Not looking for an answer down to microseconds, just a general idea of which direction I…
benjy
  • 4,664
  • 7
  • 38
  • 43
37
votes
6 answers

Difference between different types of SQL?

What are the differences between all of the different types of SQL? I hear of PostgreSQL, SQLite, MySQL, SQL, .... What are the differences between them?
RCIX
  • 38,647
  • 50
  • 150
  • 207
37
votes
1 answer

Symfony2: get the id of the persisted object

I have two entity: User and Person. In the entity User I need the id of the associated person: user_id. When I am creating a new user, I have to create first the person and then the user. In the user, I have to put the id of the corresponding person…
Milos Cuculovic
  • 19,631
  • 51
  • 159
  • 265
37
votes
6 answers

Alternative to using LIMIT keyword in a SubQuery in MYSQL

I have a table TEST with the following columns : code_ver (VARCHAR) suite (VARCHAR) date (DATE) Now I want to select 10 rows with a distinct value of code_ver & code_ver NOT LIKE '%DevBld%' sorted by date desc. So I wrote the following…
Pi Horse
  • 2,350
  • 8
  • 30
  • 51
37
votes
6 answers

MySQL: Why use VARCHAR(20) instead of VARCHAR(255)?

Possible Duplicate: Are there disadvantages to using a generic varchar(255) for all text-based fields? In MYSQL you can choose a length for the VARCHAR field type. Possible values are 1-255. But what are its advantages if you use VARCHAR(255)…
caw
  • 30,999
  • 61
  • 181
  • 291
37
votes
12 answers

Suggest what user could buy if he already has something in the cart

I am developing e-shop where I will sell food. I want to have a suggestion box where I would suggest what else my user could buy based on what he's already have in cart. If he has beer, I want him to suggest chips and other things by descending…
good_evening
  • 21,085
  • 65
  • 193
  • 298
37
votes
2 answers

Is there data visualisation tool for postgresql which is capable of displaying inter schema relations as well?

Operating system used is linux. I have tried Navicat and SQL Power Architect. They did display relations between tables in the same schema. I have some foreign key constraints which reference tables in a different schema. Am I missing something…
37
votes
4 answers

Importing zipped files in Mysql using command line

Importing zipped files in Mysql using CMD What is the right syntax to import sql zipped files into mysql using cmd ? I am doing the following xz < backup.sql.gz | mysql -u root test But always getting the following error
Subrata
  • 2,216
  • 3
  • 24
  • 38
36
votes
6 answers

Why use a 1-to-1 relationship in database design?

I am having a hard time trying to figure out when to use a 1-to-1 relationship in db design or if it is ever necessary. If you can select only the columns you need in a query is there ever a point to break up a table into 1-to-1 relationships. I…
chobo
  • 31,561
  • 38
  • 123
  • 191
36
votes
9 answers

Should I normalize my DB or not?

When designing a schema for a DB (e.g. MySQL) the question arises whether or not to completely normalize the tables. On one hand joins (and foreign key constraints, etc.) are very slow, and on the other hand you get redundant data and the potential…
Assaf Lavie
  • 73,079
  • 34
  • 148
  • 203
36
votes
5 answers

How to insert a unique ID into each SQLite row?

I have the following SQLite code. How do I insert an auto generating unique ID into each row? tx.executeSql('DROP TABLE IF EXISTS ENTRIES'); tx.executeSql('CREATE TABLE IF NOT EXISTS ENTRIES (id unique, data)'); tx.executeSql('INSERT…
say
  • 2,585
  • 7
  • 35
  • 48
36
votes
6 answers

How to run H2 database in server mode?

I need to start H2 database in server mode from my application. Having tried the following code: server = Server.createTcpServer().start(); Here is the properties for the connection: javabase.jdbc.url =…
Feras Odeh
  • 9,136
  • 20
  • 77
  • 121