Tool/Web URL Features phpmyadmin. More on phpmyadmin under User Intefaces. MySQL Query Browser

Size: px
Start display at page:

Download "Tool/Web URL Features phpmyadmin. More on phpmyadmin under User Intefaces. MySQL Query Browser"

Transcription

1 To store data in MySQL, we will set up a database and then place tables, relationships and other objects in that database, following a design that maps to our application requirements. We will use a command-line tool - mysql, running a script to generate our objects. Several other options are available to create components via User Interfaces such as phpmyadmin, MySQL Query Browser and MySQL Workbench. Tool/Web URL Features phpmyadmin More on phpmyadmin under User Intefaces. MySQL Query Browser A product from MySQL that provides a good set of drag-and-drop tools to visually define, run, manage SQLyog MySQL SQLyog MySQL GUI is the most powerful MySQL manager and admin tool, Syntax <database definition>::= CREATE DATABASE [IF NOT EXISTS] <database name> [[DEFAULT] CHARACTER SET <character set name>] [[DEFAULT] COLLATE <collation name>] combining the featur Note: If the database named above already exists, the statement above will throw an error. By specifying the IF NOT EXISTS clause, MySQL returns just a note (warning). The CHARACTER SET specifies the default character set to use and the COLLATE clause selects default collation for ordering. More on these later. We will now set up our new database sakilakubili using mysql. 1 / 25

2 CREATE DATABASE sakilakubili; USE sakilakubili; The 1 row affected response from mysql indicates that one row was changed in the internal MySQL table containing the list of all databases. On statement execution, a database named sakilakubili is added to MySQL server. The database uses the default character set and collation as we didn't specify any. Note:On Windows, all object names, such as databases and tables, are converted to lowercase. In Linux and other Unix-like operating systems, the case is preserved. More on case- senstivity in other lessons. Here, we actually specify the character set and collation to use: CREATE DATABASE sakilakubili DEFAULT CHARACTER SET latin1 DEFAULT COLLATE latin1_bin; Deleting Databases A database is dropped via the DROP DATABASE statement. Syntax DROP DATABASE [IF EXISTS] <database name> DROP DATABASE sakilakubili; Warning: When a database is dropped, the tables and their data stored in that database are also deleted. Exercise extreme caution executing the DROP DATABASE command. 2 / 25

3 Creating Tables We will now create additional tables in the sakila database using CREATE TABLE. First, we must specify the database we will be working with. The USE database sets the default database to which further commands will be applied. In other words, the USE command selects an active database among several databases under MySQL management. Tables provide a structure for storing and securing the data. All data exists within the structure of the tables, and tables are grouped inside of the database. In addition to creating tables, you can also modify the table definitions or drop the tables from the database. The CREATE TABLE statement includes appropriate column definitions and constraints to be used for the entity associated with the table. The fundamental CREATE TABLE statement is complex and contains various clauses and options to complete its definition. This lesson focuses on the essential clauses in a table definition. The syntax block below shows the basic CREATE TABLE syntax. We will discuss theses clauses one by one in this lesson. Syntax <table definition>::= CREATE [TEMPORARY] TABLE [IF NOT EXISTS] <table name>( <table element> [{, <table element>}...] ) {ENGINE = {MEMORY INNODB MERGE MYISAM}} <additional table options> Here is an example: 3 / 25

4 DROP TABLE IF EXISTS film_review; CREATE TABLE film_review ( review_id INTEGER, film_id SMALLINT NOT NULL, review_text VARCHAR(255) NOT NULL ) ENGINE=InnoDB; Tip:The CREATE TABLE command can span multiple lines, and each line is terminated with a Carriage Return. Dropping Tables To drop or delete a table, use the DROP TABLE statement. Syntax DROP [TEMPORARY] TABLE [IF EXISTS] <table name> [{, <table name>}...] Some Tips: - The optional TEMPORARY keyword prevents the inadvertent loss of a permanent table. - When the IF EXISTS clause is used with a non-existent table, a warning is thrown instead of an error. Warnings do not stop the execution of a multi-statement script in its tracks. - We can use the DROP statement to drop several tables. DROP TABLE IF EXISTS reservation; Warning: A master table referenced in a foreign key cannot be dropped without first removing the reference. Defining Table Types One especially important MySQL table options allows us to define the type of table that you create in your table definition. Syntax CREATE TABLE table-name ( 4 / 25

5 ... columns... ) ENGINE = {MYISAM INNODB MEMORY MERGE} Each ENGINE or table type in MySQL is designed for specific purpose and is processed by associated storage engine. Engines are discussed in more detail in other lessons. Table type Description MyISAM This is default table type in MySQL. MyISAM tables support extensive in InnoDB A transaction-safe table that is managed by the InnoDB handler. As a result MERGE A virtual table that is made up of identical MyISAM tables. Data is not stored MEMORY A table whose contents are stored in memory, available only as long as the We will create a table called film_info of type ISAM. DROP TABLE IF EXISTS film_info; CREATE TABLE film_info ( film_id SMALLINT NOT NULL, info_text VARCHAR(10000) NOT NULL ) ENGINE=MyISAM; Altering Existing Table Structures Using ALTER TABLE, MySQL allows you to change an existing table in several ways, such as adding or dropping columns, change existing column definitions, adding P RIMARY KEY and FOREIGN KEY constraints, or remove constraints. Altering table requires a good understanding of columns and constraints which are discussed in subsequent lessons. Syntax ALTER TABLE <table name> <alter option> [{, <alter option>}...] <alter option>::= {ADD [COLUMN] <column definition> [FIRST AFTER <column name>]} {ADD [COLUMN] (<table element> [{, <table element>}...])} 5 / 25

6 {ADD [CONSTRAINT <constraint name>] PRIMARY KEY (<column name> [{, <column name>}...])} {ADD [CONSTRAINT <constraint name>] FOREIGN KEY [<index name>] (<column name> [{, <column name>}...]) <reference definition>} {ADD [CONSTRAINT <constraint name>] UNIQUE [<index name>] (<column name> [{, <column name>}...])} {ADD INDEX [<index name>] (<column name> [{, <column name>}...])} {ADD FULLTEXT [<index name>] (<column name> [{, <column name>}...])} {ALTER [COLUMN] <column name> {SET DEFAULT <value> DROP DEFAULT}} {MODIFY [COLUMN] <column definition> [FIRST AFTER <column name>]} {CHANGE [COLUMN] <column name> <column definition> [FIRST AFTER <column name>]} {DROP [COLUMN] <column name>} {DROP PRIMARY KEY} {DROP INDEX <index name>} {DROP FOREIGN KEY <constraint name>} {RENAME [TO] <new table name>} {ORDER BY <column name> [{, <column name>}...]} CONVERT TO CHARACTER SET charset_name [COLLATE collation_name] [DEFAULT] CHARACTER SET charset_name [COLLATE collation_name] {<table option> [<table option>...]} Each of the alter options relates to a table definition option, and is preceded with an action keyword - ADD, ALTER, or DROP. Add a column A basic use of altering table is to add columns. In this demo, we are adding a column we forgot to add. ALTER TABLE film_review ADD COLUMN review_date DATETIME; Renaming Tables An existing table can be renamed with another name, as shown CREATE TEMPORARY TABLE temp_table( column1 SMALLINT ); ALTER TABLE temp_table RENAME temp2_table; DROP TABLE temp_table; -- Should give an error! 6 / 25

7 DROP TABLE temp2_table; -- That works!! Temporary Tables A TEMPORARY option make the table local or available only during the current session to the current user. We created a temporary table in the previous demo. Once we end that session, the table will be automatically deleted in case you forget to do so. Exercise: Confirm a Table is temporary Duration: 5 to 10 minutes. In this exercise, we will ensure the temp table above is not available. 1. Start another mysql session, while the previous session is still active. 2. Ensure that temp2_table above does not exist. 3. The table should not be available whether the previous session is still running or not. Creating Column Definitions We will create column definitions for each column that needs to be part of the table. Two core elements required in a column definition are the column name (any acceptable MySQL identifier) and a supported data type, but several other elements can be specified with a column as shown in the syntax for table elements below. Syntax <table element>::= <column definition> {[CONSTRAINT <constraint name>] PRIMARY KEY (<column name> [{, <column name>}...])} {[CONSTRAINT <constraint name>] FOREIGN KEY [<index name>] (<column name> [{, <column name>}...]) <reference definition>} {[CONSTRAINT <constraint name>] UNIQUE [INDEX] [<index name>] (<column name> [{, <column name>}...])} {{INDEX KEY} [<index name>] (<column name> [{, <column name>}...])} {FULLTEXT [INDEX] [<index name>] (<column name> [{, <column name>}...])} <column definition>::= <column name> <type> [NOT NULL NULL] [DEFAULT <value>] [AUTO_INCREMENT] [PRIMARY KEY] [COMMENT '<string>'] [<reference definition>] 7 / 25

8 <type>::= <numeric data type> <string data type> <data/time data type> <reference definition>::= REFERENCES <table name> [(<column name> [{, <column name>}...])] [ON DELETE {RESTRICT CASCADE SET NULL NO ACTION SET DEFAULT }] [ON UPDATE {RESTRICT CASCADE SET NULL NO ACTION SET DEFAULT }] [MATCH FULL MATCH PARTIAL] Data Types in MySQL Every table is composed of a number of columns. For each column, an intended data type must be specified. This section provides an overview of the data types available in MySQL. A data type is essentially a constraint on a column which defines and limits the type of values that can be stored in that column. Numeric Data Types Numeric data types fall under two key categories: integer or fractional. UNSIGNED option disallows negative values in the column. There are several integer types in MySQL to store various range of values as shown: Data type Acceptable values Storage TINYINT Signed: -128 to 127 Unsigned: 0 to byte SMALLINT Signed: to Unsigned: 0 to bytes MEDIUMINT Signed: to Unsigned: 0 to bytes INT/INTEGER Signed: to Unsigned: 0 to bytes BIGINT Signed: Unsigned: to to bytes The fractional data types support the use of data in post decimals places. Data type Range of Values Storage FLOAT E+38 to E-38 4 bytes E-38 to DOUBLE [PRECISION]/REAL E bytes to E DEC/DECIMAL/NUMERIC/FIXED Range and Storage requirements Depends depend on the <length> and <decimals> v String Data Types 8 / 25

9 The string data types can hold wide range of data from individual bits to large files. MySQL supports four varieties of string data types. <character data type> CHAR (<length>) [BINARY ASCII UNICODE] VARCHAR (<length>) [BINARY] <binary data type> TINYBLOB BLOB MEDIUMBLOB LONGBLOB <text data type> TINYTEXT TEXT MEDIUMTEXT LONGTEXT <list data type> {ENUM SET} (<value> [{, <value>}...]) The CHAR data type is a fixed in length and can store up to 255 characters. The actual value can have fewer characters than the amount specified, still the amount of storage is fixed at the specified amount. If character count in the column is variable, we can use a VARCH AR type, where storage is based roughly on the number of characters in the value. The following options can be used with CHAR type. - BINARY: Makes sorting and comparisons case sensitive. - ASCII: Assigns the latin1 character set to the column. - UNICODE: Assigns the ucs2 character set to the column. Binary data types are designed to store large amounts of data, such as pictures and varying messages. The main difference between Text data and Binary data types is that text data types are associated with a specific character set. Binary columns are treated as strings, and sorting is case sensitive. Text columns are treated according to their character sets, and sorting is based on the collation for that character set. The advantage here is that we can use a character set / collation for the column that differs from the table, database or server. 9 / 25

10 Data type Maximum size TINYBLOB/TINYTEXT 255 characters (355 bytes) BLOB/TEXT 65,535 characters (64 KB) MEDIUMBLOB/MEDIUMTEXT 16,777,215 characters (16 MB) LONGBLOB/LONGTEXT 4,294,967,295 characters (4 GB) 10 / 25

11 For example, the film information table may include a BLOB column named title_photo. ALTER TABLE film_info ADD COLUMN film_photo BLOB; Character Set Fundamentals For TEXT columns, we can use the additional attributes CHARACTER SET character-set-name COLLATE sortorder. Character sets specify the code-set is used to represent the various characters. In general, character sets incorporate the 128 English ASCII characters. Representation of international characters is a challenge however. - Latin Character Sets: In earlier years of computing, the linguistic regions evolved various one-byte character sets. Latin character sets have achieved the most widespread use: Latin1, alias ISO , contains all characters usual in Western Europe (??????? etc.). Latin2, alias ISO , contains characters from CEE (Central and East European) languages. Latin0, alias Latin9, alias ISO , is the same as Latin 1, but with the euro symbol included. None of these character sets contains all the characters of all the European languages, so there is no single Latin character set for all of Europe. - Unicode Variants: To handle this issue, a 2-byte Unicode character set was developed. With 65,535 characters allowed, the set covers all of Europe and most of the Asian languages. However, Unicode determines only which code is associated with which character, not how the codes are internally stored, and we discuss two common storage variants: - UCS-2/UTF-16 (Universal Character Set): Each character is stored in 2 bytes or 16 bits. However, this format has downsides: The storage requirement for characters is simply doubled, even in the routine and very common situations where only European/ASCII 11 / 25

12 characters are used, as these never go beyond 1 byte. Also, the byte code 0 is common in Unicode character strings. For 1-byte English ASCII characters, every second byte is zero. Many older, non-unicode programs cannot handle zero bytes in strings and some even use a zero byte as the end of a string. - UTF-8 (Unicode transfer format): This is a popular alternative to UTF-16 where the 7-bit ASCII characters are stored as a single byte. The other Unicode characters are stored as 2 to 4 bytes. There is no obvious relationship between the number of bytes and characters. But this format is compatible with existing programs, a big advantage. UTF-8 is therefore a standard under Unix/Linux and most other components important for Web development. Set Types The ENUM type restricts a column to a given list of values. A SET type is similar to an ENUM type, but SET type allows multiple values to be stored in the column from the list. In the example below, the trust status of information on a film is a single value from a limited set whereas the entities the info can be shown for of film, actor and / or studio. Similarly, we also record who was the information submitted by from a select set of values. ALTER TABLE film_info ADD status ENUM('ACTIVE', 'NOTVERIFIED'), ADD show_in SET('FILM', 'ACTOR', 'STUDIO'), ADD submitted_by ENUM('PROF','VIEWER','STAFF','STUDIO'); Date/Time Data Types 12 / 25

13 The date/time data types store temporal values such as dates and times. DATE TIME DATETIME YEAR TIMESTAMP Data type Format Range DATE YYYY-MM-DD through 9999 TIME HH:MM:SS -838:59:59 to 838:59:59 DATETIME 13 / 25

14 YYYY-MM-DD HH:MM:SS :00:00 through 9999 YEAR YYYY 1901 to 2155 (and 0000) TIMESTAMP YYYY-MM-DD HH:MM:SS :00:00 to partway through 2037 ALTER TABLE film_review ADD review_date DATETIME NOT NULL; The reserve_date column is a date and time combination. TIMESTAMP: A Special Type 14 / 25

15 Columns of TIMESTAMP play a special role as they are automatically updated whenever the record is inserted or updated with the time of last change. This is more of a tracking field rather than for storing actual data. For a TIMESTAMP to be automated well, the column must not have any explicit value assigned or be a NULL where MySQL will set the current time. We can manage variations TIMESTAMP columns through two attributes shown below. TIMESTAMP [DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP ] (Default) The column is automatically updated both when a new record is created and for each change in a record. The specification in square brackets [] is optional. TIMESTAMP DEFAULT CURRENT_TIMESTAMP Time is set on the column when a new record is added, but column is left unchanged thereafter. TIMESTAMP ON UPDATE CURRENT_TIMESTAMP The column is set to zero on creation but updated with current time on subsequent changes. TIMESTAMP DEFAULT 'yyyy-mm-dd hh:mm:ss' ON UPDATE CURRENT_TIMESTAMP When created, column is set to given time; but current time is stored on subsequent updates. Tip: To manage a date-time column yourself, use DATETIME data type and NOT a TIMESTAM P column. 15 / 25

16 Options and Attributes A variety of options and additional attributes can be specified when a column is created. Table below lists the most important options. Note that many attributes are suitable only for particular data types. Important Column Attributes and Options MySQL Keyword Meaning NULL The column may contain NULL values. (default) NOT NULL The value NULL is not permitted. DEFAULT xxx The value xxx will be used as a default if v PRIMARY KEY Defines the column as a primary key. AUTO_INCREMENT A incrementing sequential number is automatically input for integer values. The column should also be a NOT NULL and a PRIMARY KEY or a UNSIGNED Integers are stored without a sign. Warning: calculations are then also made CHARACTER SET name[collate sort] For strings, specifies the character set and optionally Unfortunately, MySQL does not allow a function to be given as default value. It is also impossible, for example, to specify DEFAULT RAND() if you wish to have a random number automatically stored in a column. It is also impossible to define validation rules for columns (so that, for example, only values between 0 and 100 can be stored). Constraints MySQL also supports many types of constraints to support data integrity. A constraint can be part of a column definition or be given a specific name so that it can be referenced later. Constraint violations are generally checked after execution of each statement. NOT NULL Constraint: Defining a Column's Nullability For some columns, it is acceptable to set null or unknown values. A null value is not the same 16 / 25

17 as zero or blank, instead it indicates absence of value. By default, NULL is assumed, and null values are permitted in the column. Warning: You must provide values for NOT NULL columns during Inserts and Updates. There are two exceptions to this rule when a column is of data type TIMESTAMP or tagged with AUTO_INCREMENT option. For example, after executing the following, review_date below can never be set to null. ALTER TABLE film_review MODIFY review_date DATETIME NOT NULL; UNIQUE Constraint The UNIQUE constraint specifies that the combined value of given columns must either be unique across the table or have NULL values. If using just one column, UNIQUE constraint can be specified as part of the column definition. Syntax CONSTRAINT constraintname UNIQUE(column1,column2,...)... or for single column... <column-def> UNIQUE PRIMARY KEY Constraint: Defining a Master Key PRIMARY KEY constraint is similar to UNIQUE constraint as well as a PK column cannot be N ULL. A primary key is one or more columns in a table used uniquely identify each row in that table. For nearly any table you create, you should define a primary key for that table. A table can have only one PRIMARY KEY constraint. CONSTRAINT constraintname PRIMARY KEY(column1,column2...)... or for single column... <column-def> PRIMARY KEY 17 / 25

18 Use PRIMARY KEY option in the column definition. film_id INT NOT NULL PRIMARY KEY,... or define a separate constraint... sprimary KEY (film_id) Defining Auto-Increment Columns review_id INT UNSIGNED NOT NULL AUTO_INCREMENT, ); In this demo, we are making review_id a TRUE key and set it as an AUTO_INCREMENT column. USE sakilakubili; ALTER TABLE film_review MODIFY review_id MEDIUMINT NOT NULL AUTO_INCREMENT PRIMARY KEY; Now, when we add a new row to the film_review table, a new number is automatically assigned to the review_id, incremented by 1, based on the highest value existing in that column. Note: AUTO_INCREMENT can only be used on an integer type column as NOT NULL. The table must be set up as a primary key or with a unique index, and only one AUTO_INCREMENT column per table is allowed. No DEFAULTS are allowed for AUTO_INCREMENT column. Referential Integrity Constraints: Defining Foreign Keys Referential integrity or FK constraints ensure data in the referencing table has related and needed data in the foreign or referenced table. Specifically, each element of the column specified as a foreign key must match an element of a key column (or a set of columns comprising the key) of the specified foreign (referenced) table. Several example of FK constraints are part of schemas included with this courseware. 18 / 25

19 In order to implement relationships in MySQL, we define foreign keys on the referencing tables. You define the foreign key on the column or columns in the originating child table that references the column or columns in the referenced parent table. A foreign key leads to consistency between the child table the parent table. Syntax REFERENCES referenced-table(column)... or as a separate constraint... FOREIGN KEY(referencing-table-columns) REFERENCES referenced-table(columns) There are two key Foreign Key rules generally applied: - Insert & Update Rule (Referencing Table): Inserting a non-null foreign key or updating a foreign key in the referencing table is permitted when the new or modified foreign key matches a key in the specified referenced table. - Update & Delete Rule (Referenced Table): A key in the referenced table cannot be altered or removed if being used as a foreign key in any referencing table. In this demo, we are adding a FOREIGN KEY constraint. ALTER TABLE film_review ADD INDEX(film_id); ALTER TABLE film_review ADD CONSTRAINT fk_film_review_film FOREIGN KEY (film_id) REFERENCES film(film_id) ON DELETE CASCADE ON UPDATE CASCADE; ON DELETE clause and an ON UPDATE clause set with CASCADE option are out of scope for this lesson. CHECK Constraint The CHECK constraint specifies a condition that must not be violated, and is used commonly for limiting values that can be stored in a column. Syntax CONSTRAINT constraintname CHECK(condition) 19 / 25

20 ... <column-def> CHECK(condition) Here are two sample CHECK constraints. budget must be greater than 50,000 and release_year must be 20th century or newer. budget FLOAT CHECK(budget > ), release_year CHECK(release_year >= 2000), Constraint Checking on a Transaction By default, MySQL does not abort the transaction violating a constraint. If the statements are executed as part of a transaction. START TRANSACTION;... constraint error ROLLBACK; ALTER TABLE category DROP INDEX uniq_cat_name; ALTER TABLE category ADD UNIQUE uniq_cat_name(name); START TRANSACTION; INSERT INTO category(name) VALUES('Bizarre'); INSERT INTO category(name) VALUES('Bizarre'); INSERT INTO category(name) VALUES('Outlandish'); COMMIT; SELECT * FROM category WHERE name in ('Bizarre','Outlandish'); DELETE FROM category WHERE name in ('Bizarre','Outlandish'); Code Explanation - Alter the category table to add a UNIQUE constraint on name. - Start a transaction - Insert three rows, with two being same names, defying the unique constraint. - Eventhough only two rows are inserted, the UNIQUE failure on the second insert did not stop the transaction from proceeding. if you would like to abort the transaction explicitly on error, instead of committing after the last I NSERT statement, ensure that the table is not changed by any of these INSERT statements. All changes made by these statements will be rolled back. 20 / 25

21 MySQL is flexible in its handling of constraint violations. For example, instead of flagging an error and simply not executing the statement violating a constraint, MySQL can be instructed to abort the transaction containing the offending statement. This is done by setting the MySQL variable sql_mode to the value STRICT_TRANS_TABLES when starting the MySQL server or from the MySQL client. Deferred Checking With some databases, the timing to execute Constraint checks can be specified as: - IMMEDIATE: After execution of each statement using the IMMEDIATE clause (default) or - DEFERRED: At end of a transaction using the DEFERRED clause. One issue with immediate constraint checking after each statement is slowing down of transaction processing. However, this may be a good thing as an error can be detected immediately, resulting to a transaction abort (or error indication), statement that violated the constraint. MySQL does not support Deferred constraint checks. Defining Default Values DEFAULT values can also be used for undefined values.... ReviewBy VARCHAR(50) NOT NULL DEFAULT '**'... It is likely that the review writer may not be known and is set to '**" via DEFAULT option followed by the default value to use. If a column accepts null values, the default is NULL. If a column does not accept null values, MySQL has a way of handling defaults as shown: - TIMESTAMP: the default value for the first TIMESTAMP column is the current date and time. The default values for any other TIMESTAMP columns in the table are zero values in place of the date and time. 21 / 25

22 - For columns configured with a date/time data type other than TIMESTAMP, the default values are zero values in place of the date and time. - For numeric columns configured with the AUTO_INCREMENT option, the default value is the next number in the incremented sequence of numbers. (The AUTO_INCREMENT option is discussed later in the lessons.) - For numeric columns that are not configured with the AUTO_INCREMENT option, the default value is 0. - For columns configured with the ENUM data type, the default value is the first value specified in the column definition. - For columns configured with a string data type other than the ENUM type, the default value is an empty string. Warning: RDBMSs differ considerably on handling defaults and many do not automatically assign default values to all columns. MySQL is however more forgiving and this laxity may actually cause issues. Managing Indexes Indexes on data tables speed up searches which cut down the time it takes to execute complex queries. Scanning a sorted index is quicker and more efficient access than reading a whole table. MySQL supports several index types that can be created on a table. Unique Indexes require that a value or a set of values be unique across the table in the columns on which the index is defined. But unlike primary key indexes, null values are allowed. We can also create Regular (non-unique) indexes that permits duplicate values and null values on the indexed columns. MySQL will automatically create an index on column(s) used as a Primary key. When using a foreign key on columns in a child InnoDB table, the child's foreign key columns and the referenced columns in the parent table must both be indexed. 22 / 25

23 Full-text indexes support full-text searches of the values in the columns on which the index is defined. A full-text index can be used only with tables of MyISAM type and only on CHAR, VARCHAR, and TEXT columns. To add indexes on a table, we can use indexing options in column definition, either at Creation time or via an ALTER TABLE statement; or create indexes later by using the CREATE INDEX statement explicitly. Tip: Adding or dropping keys via ALTER TABLE statement can also be used to add or drop indexes once tables have been already created. Defining Indexes when Creating Tables When we define keys in CREATE TABLE statement, MySQL automatically creates appropriate indexes on the columns participating in a particular key. In Database parlance, the keywords KEY and INDEX are used interchangeably. We can create unique indexes using a UNIQUE constraint on a set of columns, and we can define a regular index by specifying the INDEX or KEY keyword and the name of the indexed column, and optionally provide a name for your index. The next demo shows a more-or-less complete film_review table as a summary of concepts just learnt. DROP TABLE IF EXISTS film_review; 23 / 25

24 CREATE TABLE film_review ( review_id MEDIUMINT UNSIGNED NOT NULL AUTO_INCREMENT, film_id SMALLINT UNSIGNED NOT NULL, review_text VARCHAR(255) NOT NULL, review_by VARCHAR(50) NOT NULL DEFAULT '-', review_category ENUM('PROF','VIEWER','PUBLIC','STAFF') NOT NULL DEFAULT 'PUBLIC', review_date DATETIME NOT NULL, PRIMARY KEY (review_id), UNIQUE idx_uq_film_review(review_by,film_id), KEY idx_fk_review_film (film_id), CONSTRAINT fk_review_film FOREIGN KEY (film_id) REFERENCES film (film_id) ON DELETE RESTRICT ON UPDATE CASCADE )ENGINE=InnoDB DEFAULT CHARSET=utf8; CREATE INDEX Statement A CREATE INDEX statement can be used to explicitly create indexes on various tables. Using CREATE INDEX, you can add unique, regular, and full-text indexes to a table, but not primary key or foreign key indexes. CREATE INDEX idx_film_review_date ON film_review(review_date); Full-Text Indexes Adding a full-text index is similar to a regular index using keyword FULLTEXT. This example create a special full-text index on the info_text column of VARCHAR data type in film_info table. DROP INDEX idx_text_film_info ON film_info; CREATE FULLTEXT INDEX idx_text_film_info ON film_info (info_text); Deleting Indexes Indexes can be dropped either via ALTERing the TABLE or by explicit DROP INDEX statement. 24 / 25

25 In this demo, we are dropping the UNIQUE constraint. ALTER TABLE film_review DROP INDEX idx_uq_film_review; -- This works as well -- DROP INDEX idx_uq_film_review ON film_review; Code Explanation Drop the unique index from film review table. In this demo, we create a table called film_studio with several indexes. DROP TABLE IF EXISTS studio; CREATE TABLE studio ( studio_id MEDIUMINT NOT NULL AUTO_INCREMENT PRIMARY KEY, studio_name VARCHAR(100) NOT NULL, UNIQUE( studio_name ) )ENGINE=MyISAM AUTO_INCREMENT=101 DEFAULT CHARSET=utf8; Creating Databases and Components Conclusion This lesson covered the mechanisms to create a database and some components. To continue to learn MySQL go to the top of this page and click on the next lesson in this MySQL Tutorial's Table of Contents. 25 / 25

To insert a record into a table, you must specify values for all fields that do not have default values and cannot be NULL.

To insert a record into a table, you must specify values for all fields that do not have default values and cannot be NULL. Once tables have been created, the database sits like an empty container. To initially fill this database container with data, we need to use INSERT statements to add data in a MySQL database. To insert

More information

TINYINT[(M)] [UNSIGNED] [ZEROFILL] A very small integer. The signed range is -128 to 127. The unsigned range is 0 to 255.

TINYINT[(M)] [UNSIGNED] [ZEROFILL] A very small integer. The signed range is -128 to 127. The unsigned range is 0 to 255. MySQL: Data Types 1. Numeric Data Types ZEROFILL automatically adds the UNSIGNED attribute to the column. UNSIGNED disallows negative values. SIGNED (default) allows negative values. BIT[(M)] A bit-field

More information

Data Definition Language with mysql. By Kautsar

Data Definition Language with mysql. By Kautsar Data Definition Language with mysql By Kautsar Outline Review Create/Alter/Drop Database Create/Alter/Drop Table Create/Alter/Drop View Create/Alter/Drop User Kautsar -2 Review Database A container (usually

More information

Lab # 2 Hands-On. DDL Basic SQL Statements Institute of Computer Science, University of Tartu, Estonia

Lab # 2 Hands-On. DDL Basic SQL Statements Institute of Computer Science, University of Tartu, Estonia Lab # 2 Hands-On DDL Basic SQL Statements Institute of Computer Science, University of Tartu, Estonia Part A: Demo by Instructor in Lab a. Data type of MySQL b. CREATE table c. ALTER table (ADD, CHANGE,

More information

Data and Tables. Bok, Jong Soon

Data and Tables. Bok, Jong Soon Data and Tables Bok, Jong Soon Jongsoon.bok@gmail.com www.javaexpert.co.kr Learning MySQL Language Structure Comments and portability Case-sensitivity Escape characters Naming limitations Quoting Time

More information

ALTER TABLE Improvements in MARIADB Server. Marko Mäkelä Lead Developer InnoDB MariaDB Corporation

ALTER TABLE Improvements in MARIADB Server. Marko Mäkelä Lead Developer InnoDB MariaDB Corporation ALTER TABLE Improvements in MARIADB Server Marko Mäkelä Lead Developer InnoDB MariaDB Corporation Generic ALTER TABLE in MariaDB CREATE TABLE ; INSERT SELECT; RENAME ; DROP TABLE ; Retroactively named

More information

Introducing Transactions

Introducing Transactions We have so far interactively executed several SQL statements that have performed various actions in your MySQL database. The statements were run in an isolated environment one statement at a time, with

More information

Careerarm.com. 1. What is MySQL? MySQL is an open source DBMS which is built, supported and distributed by MySQL AB (now acquired by Oracle)

Careerarm.com. 1. What is MySQL? MySQL is an open source DBMS which is built, supported and distributed by MySQL AB (now acquired by Oracle) 1. What is MySQL? MySQL is an open source DBMS which is built, supported and distributed by MySQL AB (now acquired by Oracle) 2. What are the technical features of MySQL? MySQL database software is a client

More information

Introduction to SQL on GRAHAM ED ARMSTRONG SHARCNET AUGUST 2018

Introduction to SQL on GRAHAM ED ARMSTRONG SHARCNET AUGUST 2018 Introduction to SQL on GRAHAM ED ARMSTRONG SHARCNET AUGUST 2018 Background Information 2 Background Information What is a (Relational) Database 3 Dynamic collection of information. Organized into tables,

More information

1 INTRODUCTION TO EASIK 2 TABLE OF CONTENTS

1 INTRODUCTION TO EASIK 2 TABLE OF CONTENTS 1 INTRODUCTION TO EASIK EASIK is a Java based development tool for database schemas based on EA sketches. EASIK allows graphical modeling of EA sketches and views. Sketches and their views can be converted

More information

Data Types in MySQL CSCU9Q5. MySQL. Data Types. Consequences of Data Types. Common Data Types. Storage size Character String Date and Time.

Data Types in MySQL CSCU9Q5. MySQL. Data Types. Consequences of Data Types. Common Data Types. Storage size Character String Date and Time. - Database P&A Data Types in MySQL MySQL Data Types Data types define the way data in a field can be manipulated For example, you can multiply two numbers but not two strings We have seen data types mentioned

More information

The Top 20 Design Tips

The Top 20 Design Tips The Top 20 Design Tips For MySQL Enterprise Data Architects Ronald Bradford COO PrimeBase Technologies April 2008 Presented Version By: 1.1 Ronald 10.Apr.2008 Bradford 1. Know Your Technology Tools Generics

More information

Chapter 8 How to work with data types

Chapter 8 How to work with data types Chapter 8 How to work with data types Murach's MySQL, C8 2015, Mike Murach & Associates, Inc. Slide 1 Objectives Applied Code queries that convert data from one data type to another. Knowledge Describe

More information

Chapter 8: Working With Databases & Tables

Chapter 8: Working With Databases & Tables Chapter 8: Working With Databases & Tables o Working with Databases & Tables DDL Component of SQL Databases CREATE DATABASE class; o Represented as directories in MySQL s data storage area o Can t have

More information

Overview of MySQL Structure and Syntax [2]

Overview of MySQL Structure and Syntax [2] PHP PHP MySQL Database Overview of MySQL Structure and Syntax [2] MySQL is a relational database system, which basically means that it can store bits of information in separate areas and link those areas

More information

Basis Data Terapan. Yoannita

Basis Data Terapan. Yoannita Basis Data Terapan Yoannita SQL Server Data Types Character strings: Data type Description Storage char(n) varchar(n) varchar(max) text Fixed-length character string. Maximum 8,000 characters Variable-length

More information

Lab # 4. Data Definition Language (DDL)

Lab # 4. Data Definition Language (DDL) Islamic University of Gaza Faculty of Engineering Department of Computer Engineering ECOM 4113: Lab # 4 Data Definition Language (DDL) Eng. Haneen El-Masry November, 2014 2 Objective To be familiar with

More information

The M in LAMP: MySQL CSCI 470: Web Science Keith Vertanen Copyright 2014

The M in LAMP: MySQL CSCI 470: Web Science Keith Vertanen Copyright 2014 The M in LAMP: MySQL CSCI 470: Web Science Keith Vertanen Copyright 2014 MySQL Setup, using console Data types Overview Creating users, databases and tables SQL queries INSERT, SELECT, DELETE WHERE, ORDER

More information

Basic SQL. Basic SQL. Basic SQL

Basic SQL. Basic SQL. Basic SQL Basic SQL Dr Fawaz Alarfaj Al Imam Mohammed Ibn Saud Islamic University ACKNOWLEDGEMENT Slides are adopted from: Elmasri & Navathe, Fundamentals of Database Systems MySQL Documentation Basic SQL Structured

More information

CSCI-UA: Database Design & Web Implementation. Professor Evan Sandhaus

CSCI-UA: Database Design & Web Implementation. Professor Evan Sandhaus CSCI-UA:0060-02 Database Design & Web Implementation Professor Evan Sandhaus sandhaus@cs.nyu.edu evan@nytimes.com Lecture #10: Open Office Base, Life on the Console, MySQL Database Design and Web Implementation

More information

Lab # 2. Data Definition Language (DDL) Eng. Alaa O Shama

Lab # 2. Data Definition Language (DDL) Eng. Alaa O Shama The Islamic University of Gaza Faculty of Engineering Department of Computer Engineering ECOM 4113: Database Lab Lab # 2 Data Definition Language (DDL) Eng. Alaa O Shama October, 2015 Objective To be familiar

More information

Like all programming models, MySQL identifiers follow certain rules and conventions.

Like all programming models, MySQL identifiers follow certain rules and conventions. Identifier Names Like all programming models, MySQL identifiers follow certain rules and conventions. Here are the rules to adhere to for naming identifiers to create objects in MySQL: - Contain any alphanumeric

More information

Constraints. Primary Key Foreign Key General table constraints Domain constraints Assertions Triggers. John Edgar 2

Constraints. Primary Key Foreign Key General table constraints Domain constraints Assertions Triggers. John Edgar 2 CMPT 354 Constraints Primary Key Foreign Key General table constraints Domain constraints Assertions Triggers John Edgar 2 firstname type balance city customerid lastname accnumber rate branchname phone

More information

MySQL: an application

MySQL: an application Data Types and other stuff you should know in order to amaze and dazzle your friends at parties after you finally give up that dream of being a magician and stop making ridiculous balloon animals and begin

More information

Information Systems Engineering. SQL Structured Query Language DDL Data Definition (sub)language

Information Systems Engineering. SQL Structured Query Language DDL Data Definition (sub)language Information Systems Engineering SQL Structured Query Language DDL Data Definition (sub)language 1 SQL Standard Language for the Definition, Querying and Manipulation of Relational Databases on DBMSs Its

More information

Programming and Database Fundamentals for Data Scientists

Programming and Database Fundamentals for Data Scientists Programming and Database Fundamentals for Data Scientists Database Fundamentals Varun Chandola School of Engineering and Applied Sciences State University of New York at Buffalo Buffalo, NY, USA chandola@buffalo.edu

More information

Mastering phpmyadmiri 3.4 for

Mastering phpmyadmiri 3.4 for Mastering phpmyadmiri 3.4 for Effective MySQL Management A complete guide to getting started with phpmyadmin 3.4 and mastering its features Marc Delisle [ t]open so 1 I community experience c PUBLISHING

More information

CIS 363 MySQL. Chapter 4 MySQL Connectors Chapter 5 Data Types Chapter 6 Identifiers

CIS 363 MySQL. Chapter 4 MySQL Connectors Chapter 5 Data Types Chapter 6 Identifiers CIS 363 MySQL Chapter 4 MySQL Connectors Chapter 5 Data Types Chapter 6 Identifiers Ch. 4 MySQL Connectors *** Chapter 3 MySQL Query Browser is Not covered on MySQL certification exam. For details regarding

More information

GridDB Advanced Edition SQL reference

GridDB Advanced Edition SQL reference GMA022C1 GridDB Advanced Edition SQL reference Toshiba Solutions Corporation 2016 All Rights Reserved. Introduction This manual describes how to write a SQL command in the GridDB Advanced Edition. Please

More information

SQL Functionality SQL. Creating Relation Schemas. Creating Relation Schemas

SQL Functionality SQL. Creating Relation Schemas. Creating Relation Schemas SQL SQL Functionality stands for Structured Query Language sometimes pronounced sequel a very-high-level (declarative) language user specifies what is wanted, not how to find it number of standards original

More information

SQL DDL II. CS121: Relational Databases Fall 2017 Lecture 8

SQL DDL II. CS121: Relational Databases Fall 2017 Lecture 8 SQL DDL II CS121: Relational Databases Fall 2017 Lecture 8 Last Lecture 2 Covered SQL constraints NOT NULL constraints CHECK constraints PRIMARY KEY constraints FOREIGN KEY constraints UNIQUE constraints

More information

More MySQL ELEVEN Walkthrough examples Walkthrough 1: Bulk loading SESSION

More MySQL ELEVEN Walkthrough examples Walkthrough 1: Bulk loading SESSION SESSION ELEVEN 11.1 Walkthrough examples More MySQL This session is designed to introduce you to some more advanced features of MySQL, including loading your own database. There are a few files you need

More information

SQL: Data Definition Language

SQL: Data Definition Language SQL: Data Definition Language CSC 343 Winter 2018 MICHAEL LIUT (MICHAEL.LIUT@UTORONTO.CA) DEPARTMENT OF MATHEMATICAL AND COMPUTATIONAL SCIENCES UNIVERSITY OF TORONTO MISSISSAUGA Database Schemas in SQL

More information

SQL Fundamentals. Chapter 3. Class 03: SQL Fundamentals 1

SQL Fundamentals. Chapter 3. Class 03: SQL Fundamentals 1 SQL Fundamentals Chapter 3 Class 03: SQL Fundamentals 1 Class 03: SQL Fundamentals 2 SQL SQL (Structured Query Language): A language that is used in relational databases to build and query tables. Earlier

More information

CSCI-UA: Database Design & Web Implementation. Professor Evan Sandhaus

CSCI-UA: Database Design & Web Implementation. Professor Evan Sandhaus CSCI-UA:0060-02 Database Design & Web Implementation Professor Evan Sandhaus sandhaus@cs.nyu.edu evan@nytimes.com Lecture #15: Post Spring Break Massive MySQL Review Database Design and Web Implementation

More information

Chapter 3 Introduction to relational databases and MySQL

Chapter 3 Introduction to relational databases and MySQL Chapter 3 Introduction to relational databases and MySQL Murach's PHP and MySQL, C3 2014, Mike Murach & Associates, Inc. Slide 1 Objectives Applied 1. Use phpmyadmin to review the data and structure of

More information

618 Index. BIT data type, 108, 109 BIT_LENGTH, 595f BIT VARYING data type, 108 BLOB data type, 108 Boolean data type, 109

618 Index. BIT data type, 108, 109 BIT_LENGTH, 595f BIT VARYING data type, 108 BLOB data type, 108 Boolean data type, 109 Index A abbreviations in field names, 22 in table names, 31 Access. See under Microsoft acronyms in field names, 22 in table names, 31 aggregate functions, 74, 375 377, 416 428. See also AVG; COUNT; COUNT(*);

More information

Basic SQL. Dr Fawaz Alarfaj. ACKNOWLEDGEMENT Slides are adopted from: Elmasri & Navathe, Fundamentals of Database Systems MySQL Documentation

Basic SQL. Dr Fawaz Alarfaj. ACKNOWLEDGEMENT Slides are adopted from: Elmasri & Navathe, Fundamentals of Database Systems MySQL Documentation Basic SQL Dr Fawaz Alarfaj Al Imam Mohammed Ibn Saud Islamic University ACKNOWLEDGEMENT Slides are adopted from: Elmasri & Navathe, Fundamentals of Database Systems MySQL Documentation MIDTERM EXAM 2 Basic

More information

Exam Questions 1z0-882

Exam Questions 1z0-882 Exam Questions 1z0-882 Oracle Certified Professional, MySQL 5.6 Developer https://www.2passeasy.com/dumps/1z0-882/ 1.Which statement describes the process of normalizing databases? A. All text is trimmed

More information

*this is a guide that was created from lecture videos and is used to help you gain an understanding of what is mysql used for.

*this is a guide that was created from lecture videos and is used to help you gain an understanding of what is mysql used for. mysql. 1 what is mysql used for. *this is a guide that was created from lecture videos and is used to help you gain an understanding of what is mysql used for. MySQL Installation MySQL is an open source

More information

Lecture 07. Spring 2018 Borough of Manhattan Community College

Lecture 07. Spring 2018 Borough of Manhattan Community College Lecture 07 Spring 2018 Borough of Manhattan Community College 1 SQL Identifiers SQL identifiers are used to identify objects in the database, such as table names, view names, and columns. The ISO standard

More information

Department of Computer Science University of Cyprus. EPL342 Databases. Lab 2

Department of Computer Science University of Cyprus. EPL342 Databases. Lab 2 Department of Computer Science University of Cyprus EPL342 Databases Lab 2 ER Modeling (Entities) in DDS Lite & Conceptual Modeling in SQL Server 2008 Panayiotis Andreou http://www.cs.ucy.ac.cy/courses/epl342

More information

Full file at

Full file at SQL for SQL Server 1 True/False Questions Chapter 2 Creating Tables and Indexes 1. In order to create a table, three pieces of information must be determined: (1) the table name, (2) the column names,

More information

MySQL 5.0 Certification Study Guide

MySQL 5.0 Certification Study Guide MySQL 5.0 Certification Study Guide Paul DuBois, Stefan Hinz, and Carsten Pedersen MySQC Press 800 East 96th Street, Indianapolis, Indiana 46240 USA Table of Contents Introduction 1 About This Book 1 Sample

More information

Writing High Performance SQL Statements. Tim Sharp July 14, 2014

Writing High Performance SQL Statements. Tim Sharp July 14, 2014 Writing High Performance SQL Statements Tim Sharp July 14, 2014 Introduction Tim Sharp Technical Account Manager Percona since 2013 16 years working with Databases Optimum SQL Performance Schema Indices

More information

T-SQL Training: T-SQL for SQL Server for Developers

T-SQL Training: T-SQL for SQL Server for Developers Duration: 3 days T-SQL Training Overview T-SQL for SQL Server for Developers training teaches developers all the Transact-SQL skills they need to develop queries and views, and manipulate data in a SQL

More information

MySQL 101. Designing effective schema for InnoDB. Yves Trudeau April 2015

MySQL 101. Designing effective schema for InnoDB. Yves Trudeau April 2015 MySQL 101 Designing effective schema for InnoDB Yves Trudeau April 2015 About myself : Yves Trudeau Principal architect at Percona since 2009 With MySQL then Sun, 2007 to 2009 Focus on MySQL HA and distributed

More information

EGCI 321: Database Systems. Dr. Tanasanee Phienthrakul

EGCI 321: Database Systems. Dr. Tanasanee Phienthrakul 1 EGCI 321: Database Systems Dr. Tanasanee Phienthrakul 2 Chapter 10 Data Definition Language (DDL) 3 Basic SQL SQL language Considered one of the major reasons for the commercial success of relational

More information

Oracle SQL Developer. Supplementary Information for MySQL Migrations Release 2.1 E

Oracle SQL Developer. Supplementary Information for MySQL Migrations Release 2.1 E Oracle SQL Developer Supplementary Information for MySQL Migrations Release 2.1 E15225-01 December 2009 This document contains information for migrating from MySQL to Oracle. It supplements the information

More information

Today Learning outcomes LO2

Today Learning outcomes LO2 2015 2016 Phil Smith Today Learning outcomes LO2 On successful completion of this unit you will: 1. Be able to design and implement relational database systems. 2. Requirements. 3. User Interface. I am

More information

High Performance MySQL Practical Tuesday, April 01, :45

High Performance MySQL Practical Tuesday, April 01, :45 High Performance MySQL Practical Tuesday, April 01, 2014 16:45 1. Optimal Data Types: a. Choose Data Type Suggestion: i. Smaller is usually better ii. Simple is good iii. Avoid NULL if possible b. MySQL

More information

Acknowledgments About the Authors

Acknowledgments About the Authors Acknowledgments p. xi About the Authors p. xiii Introduction p. xv An Overview of MySQL p. 1 Why Use an RDBMS? p. 2 Multiuser Access p. 2 Storage Transparency p. 2 Transactions p. 3 Searching, Modifying,

More information

COSC 304 Introduction to Database Systems SQL DDL. Dr. Ramon Lawrence University of British Columbia Okanagan

COSC 304 Introduction to Database Systems SQL DDL. Dr. Ramon Lawrence University of British Columbia Okanagan COSC 304 Introduction to Database Systems SQL DDL Dr. Ramon Lawrence University of British Columbia Okanagan ramon.lawrence@ubc.ca SQL Overview Structured Query Language or SQL is the standard query language

More information

SQL. Often times, in order for us to build the most functional website we can, we depend on a database to store information.

SQL. Often times, in order for us to build the most functional website we can, we depend on a database to store information. Often times, in order for us to build the most functional website we can, we depend on a database to store information. If you ve ever used Microsoft Excel or Google Spreadsheets (among others), odds are

More information

Data Definition Language (DDL)

Data Definition Language (DDL) Islamic University of Gaza Faculty of Engineering Computer Engineering Dept. Database Lab (ECOM 4113) Lab 6 Data Definition Language (DDL) Eng. Mohammed Alokshiya November 11, 2014 Database Keys A key

More information

Data Storage and Query Answering. Data Storage and Disk Structure (4)

Data Storage and Query Answering. Data Storage and Disk Structure (4) Data Storage and Query Answering Data Storage and Disk Structure (4) Introduction We have introduced secondary storage devices, in particular disks. Disks use blocks as basic units of transfer and storage.

More information

SQL Data Definition and Data Manipulation Languages (DDL and DML)

SQL Data Definition and Data Manipulation Languages (DDL and DML) .. Cal Poly CPE/CSC 365: Introduction to Database Systems Alexander Dekhtyar.. SQL Data Definition and Data Manipulation Languages (DDL and DML) Note: This handout instroduces both the ANSI SQL synatax

More information

Data types String data types Numeric data types Date, time, and timestamp data types XML data type Large object data types ROWID data type

Data types String data types Numeric data types Date, time, and timestamp data types XML data type Large object data types ROWID data type Data types Every column in every DB2 table has a data type. The data type influences the range of values that the column can have and the set of operators and functions that apply to it. You specify the

More information

Data File Header Structure for the dbase Version 7 Table File

Data File Header Structure for the dbase Version 7 Table File Page 1 of 5 Data File Header Structure for the dbase Version 7 Table File Note: Unless prefaced by "0x", all s specified in the Description column of the following tables are decimal. 1.1 Table File Header

More information

SQL Interview Questions

SQL Interview Questions SQL Interview Questions SQL stands for Structured Query Language. It is used as a programming language for querying Relational Database Management Systems. In this tutorial, we shall go through the basic

More information

Mysql Information Schema Update Time Null >>>CLICK HERE<<< doctrine:schema:update --dump-sql ALTER TABLE categorie

Mysql Information Schema Update Time Null >>>CLICK HERE<<< doctrine:schema:update --dump-sql ALTER TABLE categorie Mysql Information Schema Update Time Null I want to update a MySQL database schema (with MySQL code) but I am unfortunately not sure 'name' VARCHAR(64) NOT NULL 'password' VARCHAR(64) NOT NULL fieldname

More information

MTAT Introduction to Databases

MTAT Introduction to Databases MTAT.03.105 Introduction to Databases Lecture #6 Constraints Ljubov Jaanuska (ljubov.jaanuska@ut.ee) Lecture 5. Summary E-R model according to Crow s Foot notation Model normalization Lecture 2-3. What

More information

Daffodil DB. Design Document (Beta) Version 4.0

Daffodil DB. Design Document (Beta) Version 4.0 Daffodil DB Design Document (Beta) Version 4.0 January 2005 Copyright Daffodil Software Limited Sco 42,3 rd Floor Old Judicial Complex, Civil lines Gurgaon - 122001 Haryana, India. www.daffodildb.com All

More information

MTAT Introduction to Databases

MTAT Introduction to Databases MTAT.03.105 Introduction to Databases Lecture #3 Data Types, Default values, Constraints Ljubov Jaanuska (ljubov.jaanuska@ut.ee) Lecture 1. Summary SQL stands for Structured Query Language SQL is a standard

More information

user specifies what is wanted, not how to find it

user specifies what is wanted, not how to find it SQL stands for Structured Query Language sometimes pronounced sequel a very-high-level (declarative) language user specifies what is wanted, not how to find it number of standards original ANSI SQL updated

More information

ASSIGNMENT NO 2. Objectives: To understand and demonstrate DDL statements on various SQL objects

ASSIGNMENT NO 2. Objectives: To understand and demonstrate DDL statements on various SQL objects ASSIGNMENT NO 2 Title: Design and Develop SQL DDL statements which demonstrate the use of SQL objects such as Table, View, Index, Sequence, Synonym Objectives: To understand and demonstrate DDL statements

More information

SQL Introduction. CS 377: Database Systems

SQL Introduction. CS 377: Database Systems SQL Introduction CS 377: Database Systems Recap: Last Two Weeks Requirement analysis Conceptual design Logical design Physical dependence Requirement specification Conceptual data model (ER Model) Representation

More information

DB Programming. Database Systems

DB Programming. Database Systems DB Programming Database Systems 1 Agenda MySQL data types Altering the Schema More Advanced MySQL JDBC DB Coding Tips 2 MySQL Data Types There are 3 main groups of types: Numeric Date String http://dev.mysql.com/doc/refman/5.6/en/data-types.html

More information

SQL: Concepts. Todd Bacastow IST 210: Organization of Data 2/17/ IST 210

SQL: Concepts. Todd Bacastow IST 210: Organization of Data 2/17/ IST 210 SQL: Concepts Todd Bacastow IST 210: Organization of Data 2/17/2004 1 Design questions How many entities are there? What are the major entities? What are the attributes of each entity? Is there a unique

More information

Simple Quesries in SQL & Table Creation and Data Manipulation

Simple Quesries in SQL & Table Creation and Data Manipulation Simple Quesries in SQL & Table Creation and Data Manipulation Based on CBSE Curriculum Class -11 By- Neha Tyagi PGT CS KV 5 Jaipur II Shift Jaipur Region Neha Tyagi, PGT CS II Shift Jaipur Introduction

More information

Tables From Existing Tables

Tables From Existing Tables Creating Tables From Existing Tables After completing this module, you will be able to: Create a clone of an existing table. Create a new table from many tables using a SQL SELECT. Define your own table

More information

Chapter 4. Basic SQL. Copyright 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley

Chapter 4. Basic SQL. Copyright 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 4 Basic SQL Copyright 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 4 Outline SQL Data Definition and Data Types Specifying Constraints in SQL Basic Retrieval Queries

More information

Model Question Paper. Credits: 4 Marks: 140

Model Question Paper. Credits: 4 Marks: 140 Model Question Paper Subject Code: BT0075 Subject Name: RDBMS and MySQL Credits: 4 Marks: 140 Part A (One mark questions) 1. MySQL Server works in A. client/server B. specification gap embedded systems

More information

Creating databases using SQL Server Management Studio Express

Creating databases using SQL Server Management Studio Express Creating databases using SQL Server Management Studio Express With the release of SQL Server 2005 Express Edition, TI students and professionals began to have an efficient, professional and cheap solution

More information

Creating Tables, Defining Constraints. Rose-Hulman Institute of Technology Curt Clifton

Creating Tables, Defining Constraints. Rose-Hulman Institute of Technology Curt Clifton Creating Tables, Defining Constraints Rose-Hulman Institute of Technology Curt Clifton Outline Data Types Creating and Altering Tables Constraints Primary and Foreign Key Constraints Row and Tuple Checks

More information

Code Centric: T-SQL Programming with Stored Procedures and Triggers

Code Centric: T-SQL Programming with Stored Procedures and Triggers Apress Books for Professionals by Professionals Sample Chapter: "Data Types" Code Centric: T-SQL Programming with Stored Procedures and Triggers by Garth Wells ISBN # 1-893115-83-6 Copyright 2000 Garth

More information

opencrx Installation Guide for MySQL 5

opencrx Installation Guide for MySQL 5 opencrx Installation Guide for MySQL 5 Version 2.5.1 www.opencrx.org License The contents of this file are subject to a BSD license (the "License"); you may not use this file except in compliance with

More information

Advanced SQL. Nov 21, CS445 Pacific University 1

Advanced SQL. Nov 21, CS445 Pacific University 1 Advanced SQL Nov 21, 2017 http://zeus.cs.pacificu.edu/chadd/cs445f17/advancedsql.tar.gz Pacific University 1 Topics Views Triggers Stored Procedures Control Flow if / case Binary Data Pacific University

More information

TUTORIAL FOR IMPORTING OTTAWA FIRE HYDRANT PARKING VIOLATION DATA INTO MYSQL

TUTORIAL FOR IMPORTING OTTAWA FIRE HYDRANT PARKING VIOLATION DATA INTO MYSQL TUTORIAL FOR IMPORTING OTTAWA FIRE HYDRANT PARKING VIOLATION DATA INTO MYSQL We have spent the first part of the course learning Excel: importing files, cleaning, sorting, filtering, pivot tables and exporting

More information

Database Foundations. 6-3 Data Definition Language (DDL) Copyright 2015, Oracle and/or its affiliates. All rights reserved.

Database Foundations. 6-3 Data Definition Language (DDL) Copyright 2015, Oracle and/or its affiliates. All rights reserved. Database Foundations 6-3 Roadmap You are here Introduction to Oracle Application Express Structured Query Language (SQL) Data Definition Language (DDL) Data Manipulation Language (DML) Transaction Control

More information

SQL language. Jaroslav Porubän, Miroslav Biňas, Milan Nosáľ (c)

SQL language. Jaroslav Porubän, Miroslav Biňas, Milan Nosáľ (c) SQL language Jaroslav Porubän, Miroslav Biňas, Milan Nosáľ (c) 2011-2016 SQL - Structured Query Language SQL is a computer language for communicating with DBSM Nonprocedural (declarative) language What

More information

Course Outline. MySQL Database Administration & Design. Course Description: Pre-requisites: Course Content:

Course Outline. MySQL Database Administration & Design. Course Description: Pre-requisites: Course Content: MySQL Database Administration & Design Course Description: MySQL is the open source community's most popular Relational Database Management System (RDBMS) offering, and is a key part of LAMP - Linux, Apache,

More information

System Pages (Setup Admins Only)

System Pages (Setup Admins Only) System Pages (Setup Admins Only) 1 Primary System Pages 2 More on Page Views & Sub Page Views 3 4 System Lookup Pages 5 6 7 Distinguishing Tables, Pages, Filtered Pages, & Page Views 8 9 Reasons to Create

More information

Using DDL Statements to Create and Manage Tables. Copyright 2006, Oracle. All rights reserved.

Using DDL Statements to Create and Manage Tables. Copyright 2006, Oracle. All rights reserved. Using DDL Statements to Create and Manage Tables Objectives After completing this lesson, you should be able to do the following: Categorize the main database objects Review the table structure List the

More information

Islamic University of Gaza Faculty of Engineering Department of Computer Engineering Fall 2011 ECOM 4113: Database System Lab Eng.

Islamic University of Gaza Faculty of Engineering Department of Computer Engineering Fall 2011 ECOM 4113: Database System Lab Eng. Islamic University of Gaza Faculty of Engineering Department of Computer Engineering Fall 2011 ECOM 4113: Database System Lab Eng. Ahmed Abumarasa Database Lab Lab 2 Database Table Introduction: The previous

More information

Working with DB2 Data Using SQL and XQuery Answers

Working with DB2 Data Using SQL and XQuery Answers Working with DB2 Data Using SQL and XQuery Answers 66. The correct answer is D. When a SELECT statement such as the one shown is executed, the result data set produced will contain all possible combinations

More information

Oracle 1Z0-882 Exam. Volume: 100 Questions. Question No: 1 Consider the table structure shown by this output: Mysql> desc city:

Oracle 1Z0-882 Exam. Volume: 100 Questions. Question No: 1 Consider the table structure shown by this output: Mysql> desc city: Volume: 100 Questions Question No: 1 Consider the table structure shown by this output: Mysql> desc city: 5 rows in set (0.00 sec) You execute this statement: SELECT -,-, city. * FROM city LIMIT 1 What

More information

SQL Server 2008 Tutorial 3: Database Creation

SQL Server 2008 Tutorial 3: Database Creation SQL Server 2008 Tutorial 3: Database Creation IT 5101 Introduction to Database Systems J.G. Zheng Fall 2011 DDL Action in SQL Server Creating and modifying structures using the graphical interface Table

More information

THE UNIVERSITY OF AUCKLAND

THE UNIVERSITY OF AUCKLAND VERSION 1 COMPSCI 280 THE UNIVERSITY OF AUCKLAND SECOND SEMESTER, 2015 Campus: City COMPUTER SCIENCE Enterprise Software Development (Time allowed: 40 minutes) NOTE: Enter your name and student ID into

More information

Pagina 1 di 5 13.1.4. INSERT Syntax 13.1.4.1. INSERT... SELECT Syntax 13.1.4.2. INSERT DELAYED Syntax INSERT [LOW_PRIORITY DELAYED HIGH_PRIORITY] [IGNORE] [INTO] tbl_name [(col_name,...)] VALUES ({expr

More information

Selections. Lecture 4 Sections Robb T. Koether. Hampden-Sydney College. Wed, Jan 22, 2014

Selections. Lecture 4 Sections Robb T. Koether. Hampden-Sydney College. Wed, Jan 22, 2014 Selections Lecture 4 Sections 4.2-4.3 Robb T. Koether Hampden-Sydney College Wed, Jan 22, 2014 Robb T. Koether (Hampden-Sydney College) Selections Wed, Jan 22, 2014 1 / 38 1 Datatypes 2 Constraints 3 Storage

More information

Creating and Managing Tables Schedule: Timing Topic

Creating and Managing Tables Schedule: Timing Topic 9 Creating and Managing Tables Schedule: Timing Topic 30 minutes Lecture 20 minutes Practice 50 minutes Total Objectives After completing this lesson, you should be able to do the following: Describe the

More information

System Characteristics

System Characteristics System Characteristics Performance is influenced by characteristics of the system hosting the database server, for example: - Disk input/output (I/O) speed. - Amount of memory available. - Processor speed.

More information

Introduction to SQL. IT 5101 Introduction to Database Systems. J.G. Zheng Fall 2011

Introduction to SQL. IT 5101 Introduction to Database Systems. J.G. Zheng Fall 2011 Introduction to SQL IT 5101 Introduction to Database Systems J.G. Zheng Fall 2011 Overview Using Structured Query Language (SQL) to get the data you want from relational databases Learning basic syntax

More information

SQL DATA DEFINITION LANGUAGE

SQL DATA DEFINITION LANGUAGE SQL DATA DEFINITION LANGUAGE DATABASE SCHEMAS IN SQL SQL is primarily a query language, for getting information from a database. DML: Data Manipulation Language SFWR ENG 3DB3 FALL 2016 MICHAEL LIUT (LIUTM@MCMASTER.CA)

More information

SQL: Data De ni on. B0B36DBS, BD6B36DBS: Database Systems. h p://www.ksi.m.cuni.cz/~svoboda/courses/172-b0b36dbs/ Lecture 3

SQL: Data De ni on. B0B36DBS, BD6B36DBS: Database Systems. h p://www.ksi.m.cuni.cz/~svoboda/courses/172-b0b36dbs/ Lecture 3 B0B36DBS, BD6B36DBS: Database Systems h p://www.ksi.m.cuni.cz/~svoboda/courses/172-b0b36dbs/ Lecture 3 SQL: Data De ni on Mar n Svoboda mar n.svoboda@fel.cvut.cz 13. 3. 2018 Czech Technical University

More information

Using DDL Statements to Create and Manage Tables. Copyright 2004, Oracle. All rights reserved.

Using DDL Statements to Create and Manage Tables. Copyright 2004, Oracle. All rights reserved. Using DDL Statements to Create and Manage Tables Copyright 2004, Oracle. All rights reserved. Objectives After completing this lesson, you should be able to do the following: Categorize the main database

More information

Introduction to SQL Server 2005/2008 and Transact SQL

Introduction to SQL Server 2005/2008 and Transact SQL Introduction to SQL Server 2005/2008 and Transact SQL Week 4: Normalization, Creating Tables, and Constraints Some basics of creating tables and databases Steve Stedman - Instructor Steve@SteveStedman.com

More information

DB Creation with SQL DDL

DB Creation with SQL DDL DB Creation with SQL DDL Outline SQL Concepts Data Types Schema/Table/View Creation Transactions and Access Control Objectives of SQL Ideally, database language should allow user to: create the database

More information

Oral Questions and Answers (DBMS LAB) Questions & Answers- DBMS

Oral Questions and Answers (DBMS LAB) Questions & Answers- DBMS Questions & Answers- DBMS https://career.guru99.com/top-50-database-interview-questions/ 1) Define Database. A prearranged collection of figures known as data is called database. 2) What is DBMS? Database

More information