Archive for November, 2012

How to create a foreign key in a database table?

A foreign key is a field (or fields) that points to the primary key of another table. The purpose of the foreign key is to ensure referential integrity of the data. In other words, only values that are supposed to appear in the database are permitted. For example, say we have two tables, a CUSTOMER […]

read more

How to add a primary key in a database table?

A primary key is used to uniquely identify each row in a table. Primary keys can be specified either when the table is created (using CREATE TABLE) or by changing the existing table structure (using ALTER TABLE). CREATING TABLE WITH PRIMARY KEY SYNTAX: CREATE TABLE table_name(field_name datatype(index),…,field_nameN datatype(index),PRIMARY KEY(field_name_primary_key)); Say for example, you are going […]

read more

How to delete a column in a database table?

In a database table, all fields should always be related with each other. If there is/are fields which are not related to it, then it should be deleted immediately. Drop Column is used to remove an entire column and all its data from a table. Syntax: ALTER TABLE table_name DROP COLUMN field_name; Supposed we have […]

read more

How to add a column in a database table?

When a table is already created in your database and suddenly you wanted to add additional columns into it, the question is how are you going to do it. Well, the answer to that is to use the ADD COLUMN command. ADD COLUMN is used to add a column to your existing table. Syntax: ALTER […]

read more

How to get information from a database?

What if you forget the name of a database or table, or what the structure of a given table is (for example, what its columns are called)? MySQL addresses this problem through several statements that provide information about the databases and tables it supports. You have previously seen SHOW DATABASES, which lists the databases managed […]

read more

How to load data from a table?

If you want to see the inserted data into your table, you can use this simple SELECT command: SELECT what_to_select FROM which_table Example: SELECT * FROM products; This will show the output: +——————+—————–+———-+———————-+ |name               |  description   |  price    |  customername    | +——————+—————–+———-+———————-+ |Mongol          […]

read more

How to load data in a database table?

LOADING DATA INTO A TABLE When you want to add new records one at a time, the INSERT statement is useful. In its simplest form, you supply values for each column, in the order in which the columns were listed in the CREATE TABLE statement. Suppose that customer JOHN bought a pencil named “Monggol.” You […]

read more

How to create a table in database?

CREATING A TABLE Creating the database is the easy part, but at this point it is empty, as SHOW TABLES tells you: mysql> SHOW TABLES; Empty set (0.00 sec) The harder part is deciding what the structure of your database should be: what tables you need and what columns should be in each of them. […]

read more