There are tools available to help us create and manage databases. Many of them hide the complexities of the underlying data structures. For instance, Ruby on Rails abstracts all database access and makes most direct access unnecessary, as do component technologies such as Enterprise JavaBeans and lots of object-oriented frameworks. For windows, Access does it. However, we still need to understand how relational databases work.
Relational databases store data in tables, which consist of rows and columns. Each table has at least one column, and each column has a type associated with it, which limits the type of data that can be stored in the column. Most tables have keys. One of the keys is designated to be the primary key. A table can be linked to another table using a foreign key.
A database management system (DBMS) is software provided by the database vendors. Micorsoft Access, Microsoft SQL Server, Oracle Database, Sybase, DB2, INGRES, MySQL, and PostgreSQL are all DMBSs or, more correctly, relational DBMSs (RDBMSs).
The DBMS provides all the basic services required to organize and maintain the database:
The Structured Query Language (SQL) is a language designed specifically for communication with databases. SQL is the industry-wide standard language used by virtually all database systems.
Databases allow collections of data to be stored in an organized manner. Most modern Database Management Systems (DBMS) store data in related tables, so are called Relational DBMS (RDBMS). The data stored inside databases can be examined and manipulated by SQL commands.
SQL commands are known as queried and utilize special keywords that can be used both to add data to a database, or extract details of data contained within a database. There are not many keywords so SQL is simple to understand. However, despite its apparent simplicity, SQL is a powerful language.
There are number of ways that SQL queries may be sent to a database to deposit or extract data:
Popular software to execute SQL queries:
Relational databases are the most commonly used type of database. Their theoretical basis is relational algebra. We do not need to know the relational theory but we need to understand some basic database concepts. For example, let's think about the database for users registered on a site.
Tables
Relational databases are made up of relations, which are tables. Table has a name, a number of columns, each corresponding to a different piece of data and rows that correspond to individual users.
Columns
Each column in the table has a unique name and contains different data. Additionally, each column has an associated data type.
Rows
Each row in the table represents a different user. Because of the tabular format, each row has the same attributes. Rows are also called records or tuples.
Values
Each row consists of a set of individual values that correspond to columns. Each value must have the data type specified by its column.
Keys
We need to have a way of identifying each user. Names usually aren't a good way of doing this because often we have common name. In general, using UserID is a good choice because an artificially assigned identification number can be guaranteed to be unique.
Schemas
The complete set of table designs for a database is called the database schema. It is similar to a blueprint for the database. A schema should show the tables along with their columns, and the primary key of each table and any foreign keys. A schema does not include any data, but we might want to show sample data with our schema to explain what it is for.
Relationships
Foreign keys represent a relationship between data in two tables. Three basic kinds of relationships exist in a relational database. They are classified according to the number of elements on each side of the relationship. Relationships can be either one-to-one, one-to-many, or many-to-many.
Database design can be thought of as the logical design of the base data structures used to store the data. In the relational model these are the tables and views. Database design is the overall process of designing, not just the base data structures, but also the forms and queries used as part of the overall database application within the database management system (DBMS).
Here are some of the rules:
Microsoft SQL Server 2008 is well integrated with Visual Basic 2010. So, we can easily create a new database from within the IDE.
Make a new Forms Application in Visual Basic 2010 with a name CarsApplication
In the Solution Explorer window, right-click on the project icon and then choose Add => New Item to launch Add New Item dialog.
Select the Service-based Database icon, type CarsDatabase.mdf in the name field. Then, click the Add button.
At this time, we just click Cancel.
Right-click the CarsDatabase.mdf icon that we've just added and then choose Open From the context menu to open the Database Explorer window.
Examine the CarsDatabase.mdf icon in Database Explorer and we should see it has below it to indicate we're connected to that database.
Right-click the CarsDatabase.mdf icon in Database Explorer then choose Close Connection from the context menu and we'll see the icon change to have a red X below it.
Right-click the CarsDatabase.mdf icon in Database Explorer then choose Refresh to reconnect to the database.
To test the connection, choose Modify Connection and then click its Test Connection button. Then, we'll see the Connection Succeeded confirmation dialog appear.