SQL_Notes

download SQL_Notes

If you can't read please download the document

description

SQL_Notes

Transcript of SQL_Notes

SQL NOTESstopped at pdf pg. 28

Each table in a relational database includes information that uniquely identifies a row in that table (known as the primary key ), along with additional information needed to describe the entity completely.Every database server provides a mechanism for generating unique sets of numbers to use as primary key values, so you won't need to worry about keeping track of what numbers have been assigned.

A primary key consisting of two or more columns is known as a compound key

In this example, choosing fname /lname as the primary key would be referred to as a natural key, whereas the choice of cust_id would be referred to as a surrogate key . The decision whether to employ natural or surrogate keys is a topic of widespread debate, but in this particular case the choice is clear, since a person's last name may change (such as when a person adopts a spouse's last name), and primary key columns should never be allowed to change once a value has been assigned.

Foreign keys are used to connect one entity to another.

Entity -Something of interest to the database user community. Examples include customers, parts, geographic locations, etc.

Column - An individual piece of data stored in a table.

Row -A set of columns that together completely describe an entity or some action on an entity. Also called a record.

Table - A set of rows, held either in memory (nonpersistent) or on permanent storage (persistent).

Result set - Another name for a nonpersistent table, generally the result of an SQL query.

Primary key - One or more columns that can be used as a unique identifier for each row in a table.

Foreign key - One or more columns that can be used together to identify a single row in another table.

A procedural language defines both the desired results and the mechanism, or process, by which the results are generated. Nonprocedural languages also define the desired results, but the process by which the results are generated is left to an external agent.

The manner in which a statement is executed is left to a component of your database engine known as the optimizer.

Most SQL implementations treat any text between the /* and */ tags as comments.

The maximum length for char columns is currently 255 bytes, whereas varchar columns can be up to 65,535 bytes.

the concept of normalization, which is the process of ensuring that there are no duplicate (other than foreign keys) or compound columns in your database design.

MySQL allows a check constraint to be attached to a column definition, as in the following: gender CHAR(1) CHECK (gender IN ('M','F')),

MySQL does provide another character data type called enum that merges the check constraint into the data type definition.If you want to make sure that the person table does, in fact, exist, you can use the describe command (or desc for short) to look at the table definition: mysql> DESC person;The order by clause tells the server how to sort the data returned by the query. Without the order by clause, there is no guarantee that the data in the table will be retrieved in any particular order.

all database servers on the market today provide a safe, robust method for generating numeric keys. In some servers, such as the Oracle Database, a separate schema object is used (called a sequence); in the case of MySQL, however, you simply need to turn on the auto-increment feature for your primary key column. Normally, you would do this at table creation, but doing it now provides the opportunity to learn another SQL schema statement, alter table, which is used to modify the definition of an existing table: ALTER TABLE person MODIFY person_id SMALLINT UNSIGNED AUTO_INCREMENT;

If you will be working with XML data, you will be happy to know that most database servers provide a simple way to generate XML output from a query. With MySQL, for example, you can use the --xml option when invoking the mysql tool, and all your output will automatically be formatted using XML.

stopped at pg. 46 in pdf