-
Data Manipulation Language (DML) statements Allow you to modify the contents of tables. There are three DML statements:
-
INSERT Allows you to add rows to a table.
-
UPDATE Allows you to change a row.
-
DELETE Allows you to remove rows.
-
Showing posts with label MySQL. Show all posts
Showing posts with label MySQL. Show all posts
Data Manipulation Language (DML) statements ?
PMA01:53
What Is a Relational Database?
PMA01:52
The basic concepts of a relational database are fairly easy to
understand. A relational database is a collection of
related information that has been organized into structures known as tables. Each table contains rows
that are further organized into columns. These tables are
stored in the database in structures known as schemas,
which are areas where database users may store their tables. Each user may also
choose to grant permissions to other users to access their tables.
MySQL Subqueries?
PMA05:07
You can use the result of a query like you use a list of values
with the IN operator to filter a query based on the result of another
query. The subquery appears in parentheses after the IN keyword.
The following query fetches all columns from the products
table, but only for those product codes that were part of order number 1:
mysql> SELECT * -> FROM products -> WHERE product_code IN ( -> SELECT product_code -> FROM order_lines -> WHERE order_id = 1 -> ); +--------------+---------------+--------+--------+ | product_code | name | weight | price | +--------------+---------------+--------+--------+ | MINI | Small product | 1.50 | 5.99 | | MAXI | Large product | 8.00 | 15.99 | +--------------+---------------+--------+--------+ 2 rows in set (0.00 sec)
MySQL Triggers
PMA05:05
To create a new trigger, use the CREATE TRIGGER
statement. You must give the trigger a unique name and then provide the timing,
action, and table that will cause the trigger to fire. For example, to create a
trigger that will fire every time a row is deleted from the products table, you
would construct a trigger as follows:
CREATE TRIGGER trigger_name BEFORE DELETE ON products FOR EACH ROW BEGIN ... END
The timing for a trigger can be BEFORE or
AFTER, indicating whether the trigger code should be executed
immediately before or immediately after the SQL statement that causes the
trigger to fire.
The keywords FOR EACH ROW are part of the CREATE
TRIGGER syntax and are required in every trigger.
what is Triggers?
PMA05:04
A trigger is a stored database object that contains a series of
SQL commands, set to activate automatically when certain events take place.
Each trigger is associated with a table. You can create a
trigger that will fire when an INSERT, UPDATE, or
DELETE takes place on the named table.
Learning the MySQL Data Types
PMA03:59
MySQL uses many different data types, broken into three categories: numeric, date and time, and string types.
INT—A normal-sized integer that can be signed or unsigned. If signed, the
allowable range is from –2147483648 to 2147483647. If unsigned, the allowable
range is from 0 to 4294967295. You can specify a width of up to 11 digits.
. TINYINT—A small integer that can be signed or unsigned. If signed, the allowable
range is from –128 to 127. If unsigned, the allowable range is from 0 to
255. You can specify a width of up to 4 digits.
SMALLINT—A small integer that can be signed or unsigned. If signed, the
allowable range is from –32768 to 32767. If unsigned, the allowable range is
from 0 to 65535. You can specify a width of up to 5 digits.
MEDIUMINT—A medium-sized integer that can be signed or unsigned. If signed,
the allowable range is from –8388608 to 8388607. If unsigned, the allowable
range is from 0 to 16777215. You can specify a width of up to 9 digits.
BIGINT—A large integer that can be signed or unsigned. If signed, the allowable
range is from –9223372036854775808 to 9223372036854775807. If
unsigned, the allowable range is from 0 to 18446744073709551615. You can
specify a width of up to 11 digits.
FLOAT(M,D)—A floating-point number that cannot be unsigned. You can
define the display length (M) and the number of decimals (D). This is not
required and defaults to 10,2, where 2 is the number of decimals and 10 is the
total number of digits (including decimals). Decimal precision can go to 24
places for a FLOAT.
DOUBLE(M,D)—A double-precision floating-point number that cannot be
unsigned. You can define the display length (M) and the number of decimals
(D). This is not required and will default to 16,4, where 4 is the number of
decimals. Decimal precision can go to 53 places for a DOUBLE. REAL is a synonym
for DOUBLE.
DECIMAL(M,D)—An unpacked floating-point number that cannot be unsigned.
In unpacked decimals, each decimal corresponds to 1 byte. Defining the display
length (M) and the number of decimals (D) is required. NUMERIC is a synonym
for DECIMAL.
INT—A normal-sized integer that can be signed or unsigned. If signed, the
allowable range is from –2147483648 to 2147483647. If unsigned, the allowable
range is from 0 to 4294967295. You can specify a width of up to 11 digits.
. TINYINT—A small integer that can be signed or unsigned. If signed, the allowable
range is from –128 to 127. If unsigned, the allowable range is from 0 to
255. You can specify a width of up to 4 digits.
SMALLINT—A small integer that can be signed or unsigned. If signed, the
allowable range is from –32768 to 32767. If unsigned, the allowable range is
from 0 to 65535. You can specify a width of up to 5 digits.
MEDIUMINT—A medium-sized integer that can be signed or unsigned. If signed,
the allowable range is from –8388608 to 8388607. If unsigned, the allowable
range is from 0 to 16777215. You can specify a width of up to 9 digits.
BIGINT—A large integer that can be signed or unsigned. If signed, the allowable
range is from –9223372036854775808 to 9223372036854775807. If
unsigned, the allowable range is from 0 to 18446744073709551615. You can
specify a width of up to 11 digits.
FLOAT(M,D)—A floating-point number that cannot be unsigned. You can
define the display length (M) and the number of decimals (D). This is not
required and defaults to 10,2, where 2 is the number of decimals and 10 is the
total number of digits (including decimals). Decimal precision can go to 24
places for a FLOAT.
DOUBLE(M,D)—A double-precision floating-point number that cannot be
unsigned. You can define the display length (M) and the number of decimals
(D). This is not required and will default to 16,4, where 4 is the number of
decimals. Decimal precision can go to 53 places for a DOUBLE. REAL is a synonym
for DOUBLE.
DECIMAL(M,D)—An unpacked floating-point number that cannot be unsigned.
In unpacked decimals, each decimal corresponds to 1 byte. Defining the display
length (M) and the number of decimals (D) is required. NUMERIC is a synonym
for DECIMAL.