Lecturer: Mukhtar Mohamed Ali “Hakaale”

Slides:



Advertisements
Similar presentations
SQL DDL constraints Restrictions on the columns and tables 1SQL DDL Constraints.
Advertisements

Database Constraints. Database constraints are restrictions on the contents of the database or on database operations Database constraints provide a way.
Database Lecture # 1 By Ubaid Ullah.
INTERNET APPLICATION DEVELOPMENT For More visit:
 SQL stands for Structured Query Language.  SQL lets you access and manipulate databases.  SQL is an ANSI (American National Standards Institute) standard.
Constraints  Constraints are used to enforce rules at table level.  Constraints prevent the deletion of a table if there is dependencies.  The following.
15/10/20151 PHP & MySQL 'Slide materials are based on W3Schools PHP tutorial, 'PHP website 'MySQL website.
CpSc 462/662: Database Management Systems (DBMS) (TEXNH Approach) Constraints, Triggers and Index James Wang.
SQL: DDL. SQL Statements DDL - data definition language –Defining and modifying data structures (metadata): database, tables, views, etc. DML - data manipulation.
SQL Basics. What is SQL? SQL stands for Structured Query Language. SQL lets you access and manipulate databases.
Chapter 9 Constraints. Chapter Objectives  Explain the purpose of constraints in a table  Distinguish among PRIMARY KEY, FOREIGN KEY, UNIQUE, CHECK,
Oracle 11g: SQL Chapter 4 Constraints.
Chapter 4 Constraints Oracle 10g: SQL. Oracle 10g: SQL 2 Objectives Explain the purpose of constraints in a table Distinguish among PRIMARY KEY, FOREIGN.
INCLUDING CONSTRAINTS lecture5. Outlines  What are Constraints ?  Constraint Guidelines  Defining Constraint  NOT NULL constraint  Unique constraint.
Visual Programing SQL Overview Section 1.
Lecture5: SQL Overview, Oracle Data Type, DDL and Constraints Ref. Chapter6 Lecture4 1.
Constraints Lesson 8. Skills Matrix Constraints Domain Integrity: A domain refers to a column in a table. Domain integrity includes data types, rules,
Session 1 Module 1: Introduction to Data Integrity
Understand Primary, Foreign, and Composite Keys Database Administration Fundamentals LESSON 4.2.
Relational Database Management System(RDBMS) Structured Query Language(SQL)
IS6146 Databases for Management Information Systems Lecture 3: SQL III – The DDL Rob Gleasure robgleasure.com.
Including Constraints. What Are Constraints? Constraints enforce rules at the table level. You can use constraints to do the following: – Enforce rules.
Chapter 3: Relational Databases
SQL constrains and keys. SORTED RESULTS Sort the results by a specified criterion SELECT columns FROM tables WHERE predicates ORDER BY column ASC/DESC;
Constraints Advanced Database Systems Dr. AlaaEddin Almabhouh.
MySQL Tutorial. Databases A database is a container that groups together a series of tables within a single structure Each database can contain 1 or more.
Lec-7. The IN Operator The IN operator allows you to specify multiple values in a WHERE clause. SQL IN Syntax SELECT column_name(s) FROM table_name WHERE.
LEC-8 SQL. Indexes The CREATE INDEX statement is used to create indexes in tables. Indexes allow the database application to find data fast; without reading.
Standards and Conventions
Data Integrity & Indexes / Session 1/ 1 of 37 Session 1 Module 1: Introduction to Data Integrity Module 2: Introduction to Indexes.
Database Constraints Ashima Wadhwa. Database Constraints Database constraints are restrictions on the contents of the database or on database operations.
SQL IMPLEMENTATION & ADMINISTRATION Indexing & Views.
Getting started with Accurately Storing Data
CompSci 280 S Introduction to Software Development
Fundamentals of DBMS Notes-1.
Rob Gleasure robgleasure.com
Web Systems & Technologies
Fundamental of Database Systems
Database Constraints Ashima Wadhwa.
Rob Gleasure robgleasure.com
SQL Creating and Managing Tables
SQL – More Table Constraints
MIS2502: Data Analytics SQL – Putting Information Into a Database
Module 5: Implementing Data Integrity by Using Constraints
ISC440: Web Programming 2 Server-side Scripting PHP 3
STRUCTURED QUERY LANGUAGE
Normalization Referential Integrity
Session #, Speaker Name Indexing Chapter 8 11/19/2018.
Lecturer: Mukhtar Mohamed Ali “Hakaale”
Chapter 4 Indexes.
CH 4 Indexes.
Structured Query Language
Primary key Introduction Introduction: A primary key, also called a primary keyword, is a key in a relational database that is unique for each record.
Introduction To Structured Query Language (SQL)
SQL DATA CONSTRAINTS.
CS122 Using Relational Databases and SQL
CH 4 Indexes.
Rob Gleasure robgleasure.com
Lesson Plan Instructional Objective Learning Objective
Introduction To Structured Query Language (SQL)
Data Definition Language
CS122 Using Relational Databases and SQL
MIS2502: Data Analytics SQL 4– Putting Information Into a Database
CS1222 Using Relational Databases and SQL
CS122 Using Relational Databases and SQL
CS122 Using Relational Databases and SQL
Including Constraints
កម្មវិធីបង្រៀន SQL Programming ជាភាសាខ្មែរ Online SQL Training Course
SQL NOT NULL Constraint
SQL AUTO INCREMENT Field
Presentation transcript:

Lecturer: Mukhtar Mohamed Ali “Hakaale” SQL Constraints Lecturer: Mukhtar Mohamed Ali “Hakaale”

SQL Constraints SQL constraints are used to specify rules for the data in a table. Constraints are used to limit the type of data that can go into a table. This ensures the accuracy and reliability of the data in the table. If there is any violation between the constraint and the data action, the action is aborted. Constraints can be column level or table level. Column level constraints apply to a column, and table level constraints apply to the whole table.

SQL Constrains Cont … The following constraints are commonly used in SQL: NOT NULL - Ensures that a column cannot have a NULL value UNIQUE - Ensures that all values in a column are different PRIMARY KEY - A combination of a NOT NULL and UNIQUE. Uniquely identifies each row in a table FOREIGN KEY - Uniquely identifies a row/record in another table CHECK - Ensures that all values in a column satisfies a specific condition DEFAULT - Sets a default value for a column when no value is specified INDEX - Used to create and retrieve data from the database very quickly

SQL NOT NULL Constraint Description Example By default, a column can hold NULL values. The NOT NULL constraint enforces a column to NOT accept NULL values. This enforces a field to always contain a value, which means that you cannot insert a new record, or update a record without adding a value to this field. The following SQL ensures that the "ID", "LastName", and "FirstName" columns will NOT accept NULL values: CREATE TABLE Persons (     ID int NOT NULL,     LastName varchar(255) NOT NULL,     FirstName varchar(255) NOT NULL,     Age int );

SQL UNIQUE Constraint Description Example The UNIQUE constraint ensures that all values in a column are different. Both the UNIQUE and PRIMARY KEY constraints provide a guarantee for uniqueness for a column or set of columns. A PRIMARY KEY constraint automatically has a UNIQUE constraint. However, you can have many UNIQUE constraints per table, but only one PRIMARY KEY constraint per table. CREATE TABLE Persons (     ID int NOT NULL UNIQUE,     LastName varchar(255) NOT NULL,     FirstName varchar(255),     Age int );

SQL PRIMARY KEY Constraint Description Example The PRIMARY KEY constraint uniquely identifies each record in a database table. Primary keys must contain UNIQUE values, and cannot contain NULL values. A table can have only one primary key, which may consist of single or multiple fields. CREATE TABLE Persons (     ID int NOT NULL,     LastName varchar(255) NOT NULL,     FirstName varchar(255),     Age int,     PRIMARY KEY (ID) );

SQL FOREIGN KEY Constraint Description Example A FOREIGN KEY is a key used to link two tables together. A FOREIGN KEY is a field (or collection of fields) in one table that refers to the PRIMARY KEY in another table. The table containing the foreign key is called the child table, and the table containing the candidate key is called the referenced or parent table. ALTER TABLE Orders ADD FOREIGN KEY (PersonID) REFERENCES  Persons(PersonID);

SQL CHECK Constraint Description Example The CHECK constraint is used to limit the value range that can be placed in a column. If you define a CHECK constraint on a single column it allows only certain values for this column. If you define a CHECK constraint on a table it can limit the values in certain columns based on values in other columns in the row. CREATE TABLE Persons (     ID int NOT NULL,     LastName varchar(255) NOT NULL,     FirstName varchar(255),     Age int CHECK (Age>=18) );

SQL DEFAULT Constraint Description Example The DEFAULT constraint is used to provide a default value for a column. The default value will be added to all new records IF no other value is specified. CREATE TABLE Persons (     ID int NOT NULL,     LastName varchar(255) NOT NULL,     FirstName varchar(255),     Age int,     City varchar(255) DEFAULT 'Sandnes' );

SQL CREATE INDEX Statement Description Example The CREATE INDEX statement is used to create indexes in tables. Indexes are used to retrieve data from the database very fast. The users cannot see the indexes, they are just used to speed up searches/queries. CREATE INDEX index_name ON table_name (column1, colu mn2, ...);