SQL Overview, SQL Data Type, DDL and Constraints: Ref. Chapter7
SQL Overview, SQL Data Type, DDL and Constraints: Ref. Chapter7
SQL Overview, SQL Data Type, DDL and Constraints: Ref. Chapter7
1
SQL overview
• Official pronunciation is ‘S-Q-L‘ or ( see-qual)
• SQL: Structured Query Language
ﻓﻲ اﻟﺪاﺗﺎ ﺑ(ﺲSQL ﻞ راح =ﺴﺘﺨﺪم5…ﻒ واﻟﺘﻌﺪŽﻋﺸﺎن =ﺴﻮي اﻟﺘﻌ
• It is a non-procedural language:
• you specify what information you require, rather than how to get it.
In other words, SQL does not require you to specify the access
2
methods to the data
.ﺠﻴﺒﻬﺎ5 ﻒ4ﺎﻧﻬﺎ او ﻛƒ( ﻣﺎ اﻗﻮﻟﻪ و…ﻦ ﻣhow) ﻐﻰ ﻣﻦ دون8( اwhat)@ﺲ اﻗﻮﻟﻪ وش
The Process of Database Design
Database Design ﺎة4دورة ﺣ
ER,EER Logical model اﺣﻂ اﻟﺪاﺗﺎ ﻓﻲ اﻟﺪاﺗﺎ ﺑ(ﺲ ا=ﺸﺊ اﻟﺪاﺗﺎ ﺑ(ﺲ
)اﻟﺮوز واﻟ™ﻮﻟﻤﺰ واذا @ﺴﻮي
(ﺖ4ﻠ5ﺖ او د5ﺪ8ا
3
SQL Overview
ﻓﻴﻬﺎ؟SQL اﻟﻠﻲ ﺗﺨﺪﻣﻨﻲ الtasks ا©ﺶ ال
• SQL provides statements for a variety of tasks, including:
1. Querying data( Select command) ٤ اﻟﻄﻼب اﻟﻠﻲ ﻣﻌﺪﻟﻬﻢ ا•ﺒﺮ ﻣﻦselect :ﻣﺜﺎل
select ﺎﺳﺘﺨﺪام8 (…ﺰŽ…ª™ﺔ اﺳﺘﺮﺟﺎع ﻣﻦ اﻟﺪاﺗﺎ ﺑ(ﺲ)اﻟ4اﺳﻮي ﻋﻤﻠ
4
SQL Identifier
ﻛﻮﻟﻤﺰ ﻻزم اﻋﻄﻴﻬﺎ اﺳﻢ، ﻓﻴﻮ،}ﻞ± ﺗ،ﻴﻮت²ﺖ اي اﺗﺘﺮ³اذا ا=ﺸ
• SQL identifiers are used to identify objects in the database,
such as table names, view names, and columns.
• The following restrictions are imposed on an identifier:
ﺎت4ﻫﻨﺎ ﻗﻴﻮد ﻋﻠﻰ اﻟﻤﺴﻤ
5
ISO SQL Data Types
اذا ا=ﺸ³ﺖ اﺗﺘﺮ²ﻴﻮت ﻻزم اﻗﻮل ا©ﺶ ﻧªع اﻟﺪاﺗﺎ اﻟﻠﻲ ﺑ4ﺤﻤﻠﻬﺎ وﻫﻨﺎ ﻧﺤﺪد )(Data Type
6
ﻧ}ﺪا ﺑﺘﻔﺼ4ﻠﻬﺎ 8ﺎﻟﺴﻼ5ﺪ اﻟﻠﻲ 8ﻌﺪە
• Boolean data …0,1 ﺎ5 true, false ﺎ5 yes,no ﺎ5 ﻔﻲ4ﻤﺘﻴﻦ ﻓﻘﻂ واﺳﻤﻴﻬﺎ ﻋﻠﻰ ﻛ4ﺗﺤﻤﻞ ﻗ
• Boolean data consists of the distinct truth values TRUE and FALSE
• Character data
• To store strings
• The format for specifying a character data type is:
Lecture4
HH24 Military hour 1-24
DD day of month 1-31 (depends on month)
DAY day of the week Sunday-Saturday
D day of the week 1-7
MM month number 1-12
MON month abbreviated Jan—Dec
Month Month spelled out January-December
YY last 2 digits of year eg, 98
11
YYYY full year value eg, 1998
Lecture4
• ‘mm-dd-yy hh:mi:ss’ 12-01-01 12:30:59
12
Data Definition language ( DDL )
Lecture4
Table Creation
13
Data Definition (Creating a table)
• Creating a table
create table table-name (
column-name1 datatype ,
……..
Lecture4
column-nameN datatype );
Lecture4
constraints. Tables constraints can, for example, identify
several columns such as Primary key.
• If the results of an INSERT or UPDATE statement violate an
integrity constraint, the statement will be rolled back.
ﻣﺎراحnull ﻤﺔ اﻟﺒﻮزﺷﻦ4ﻌﺪﻳﻦ اﺳﻮي ا=ﺴﺮت واﺣﻂ ﻗ8 ﻜﻮن ﻋﻨﺪە ﺑﻮزﺷﻦ5 ﺪ ان ﻻزم اﻟﻤﻮﻇﻒ4ﻟﻮ ﻣﺜﻼ اﻧﺎ اﺣﻂ ﻗ
rolled back ﺴﻤﻰàﺔ اﻻ=ﺴﺮت و4ﺤﻪ ﻗ}ﻞ ﻋﻤﻠ4ﻳﺮﺿﻰ ©ﺴﻮي ﻟﻲ ا=ﺴﺮت ﻓﺮاح ﻳﺮﺟﻊ اﻟﺪاﺗﺎ ﺑ(ﺲ ﻻﺧﺮ ﺣﺎﻟﻪ ﺻﺤ
• Note : If you don’t give the constraint name, the system will
generate a name automatically, but the name is hard for 15
human understanding.
Integrity Constraints
• Constraint clauses can appear in the following statements:
Integrity ﺪ4ﻒ اي ﻗ4ﻤﺪﻳﻨﻲ اﺿ4ﻴﻮت اﻟﻤﻮﺟﻮدة ﻓ²ﻞ اﻻﺗﺘﺮÌ }ﻞ راح اﺣﻂ±ﺖ ا=ﺸﺊ ﺗ4اذا ﺟ
: ﻓﻲ اﻟﺤﺎﻻت ﻫﺬيConstraints
1. CREATE TABLE
2. ALTER TABLE
Lecture4
3. CREATE VIEW
4. ALTER VIEW
16
The Five types of integrity constraint
ﺔ4ﺎت ﺛﺎﻧ4ﻣﺴﻤ
Lecture4
5. check constraint -> Domain constraint
17
NOT NULL constraint
Lecture4
value. This means that you cannot insert a new record, or
update a record without adding a value to this field.
Syntax:
create table table-name (
column-name1 datatype NOT NULL );
18
NOT NULL constraint
• Example : The following SQL enforces the "P_Id" column and the
"LastName" column to not accept NULL values:
Lecture4
LastName varchar(255) NOT NULL,
FirstName varchar(255),
Address varchar(255),
City varchar(255) );
19
SQL NULL
زي ﺗﻮnull ﻌﻨﻲ ﻣﻮ5
• If a column in a table is optional, we can insert a new record or
update an existing record without adding a value to this column.
This means that the field will be saved with a NULL value.
null ﺤﻂ ﻫﻮ اﻧﻬﺎ5 ﻤﻪ اوﻛﻲ اذا ﻣﺎﺣﻄﻴﺘﻲ راح4ﺸﻨﻞ اذا ﺣﻄﻴﺘﻲ ﻗåﻪ او4اﺧﻠ
Lecture4
• NULL is used as a placeholder for unknown or inapplicable values.
ﺪ8ﻞ ﻣﺆﻗﺖ ﻻﻧﻲ ﻣﺎﻋﺮف اﻟﻔﺎﻟﻴﻮ او ﻣﻮ ﻣﺘﻮﻓﺮە ﺑﻬﺎﻟﻮﻗﺖ @ﺲ ﻣﺎ اﺧﻠﻴﻬﺎ ﻟﻼƒ اﺳﺘﺨﺪﻣﻬﺎ @ﺸnull ال
• Note: It is not possible to compare NULL and 0; they are not
equivalent.
• It is not possible to test for NULL values with comparison
operators, such as =, <, or <>.
• We will have to use the IS NULL and IS NOT NULL operators 20
instead.
is null or is not null ﺪاﻟﻬﺎ اﺳﺘﺨﺪم8 null ﻣﺎ اﺳﺘﺨﺪم ا•ﺒﺮ واﺻﻐﺮ وﻫﺬوﻟﻲ ﻣﺎراح ﺗﻤﺸﻲ ﻣﻊ ال
UNIQUE constraint ﻣﺎﻳﺘﻜﺮر
Lecture4
Syntax:
create table table-name (
column-name1 datatype UNIQUE );
OR
create table table-name (
…….
……. 21
[constraint constraint-name] UNIQUE (Columns_list) ;
Example
• The following SQL creates a UNIQUE constraint on the
"P_Id" column when the "Persons" table is created:
Lecture4
(
P_Id char(5) NOT NULL UNIQUE,
LastName varchar(255) NOT NULL,
FirstName varchar(255),
Address varchar(255),
City varchar(255),
Constraint Unique (LastName, FirstName)
22
);
ﺴﻤﻴﻨﻪà ﻜﻮن ﺻﻌﺐ زي ﻣﺎﻗﻠﻨﺎ ﻗ}ﻞ ﻓﺎﻻﻓﻀﻞ اﻧﻚ4²ﺤﻂ اﺳﻢ ﻣﻦ ﻋﻨﺪە و5 ﻫﻨﺎ ﻫﻮ ﻣﺎﺳﻤﻰ اﻟ™ﻮ=ﺴﺘﺮ…ﺖ ﻓﺮاح
Primary key Constraints <- null ﺎل8 ﺎﻟﺘﻜﺮار وﻻ8 ﻣﺎ©ﺴﻤﺢ ﻻ
Lecture4
• A PRIMARY KEY constraint automatically has a UNIQUE
constraint defined on it.
• Note that you can have many UNIQUE constraints per table,
but only one PRIMARY KEY constraint per table.
ﻤﺮي5}ﻞ ﻣﺎﻋﻨﺪي اﻻ ﺑﺮا±< اﻗﺪر اﺳﻮي @ﺲ واﺣﺪ ﻻن اﺻﻼ اﻟﺘ- Primary key Constraints
.ﻴﻮﺗﺰ²ﻴﻮت وﺣﺪە او ﻣﺠﻤﻮﻋﻪ ﻣﻦ اﻻﺗﺘﺮ²ﺎن اﺗﺘﺮÌ ﻛﻲ واﺣﺪ ﺳﻮاء
. ﻋﺎديas many as I can < اﻗﺪر اﺣﻂ- UNIQUE constraints 23
Lecture4
OR
Example :
create table Department (
dept_no char(4),
Lecture4
Dept_name varchar(25),
CONSTRAINT dept_PK PRIMARY KEY(dept_no));
25
Foreign Keys constraint
}ﻞ زي ﻣﺎﻗﻠﻨﺎ ﻗ}ﻞ± ﺗparent }ﻞ ﻻزم ﺗﻜﻮن ﻣﻮﺟﻮدە او ﺗﺮﺟﻊ ﻟﻞ± ﺗchildﺎل8 اﻟﺮوز اﻟﻠﻲ ﻣﻮﺟﻮدە
foreign key constraint requires values in one table to match
values in another table.
Syntax:
Lecture4
create table table-name (
column-name1 datatype,
……
……
[constraint constraint-name] Foreign key (Column_name)
references referenced_table (column_in_referenced_table) );
26
Foreign Keys constraint
Create table Staff(
staff_no char(3),
staff_name varchar(20),
dept_no char(4),
Lecture4
CONSTRAINT staff_PK PRIMARY KEY(staff_no ),
Constraint staff_fk foreign key (dept_no) references
department (dept_no));
27
referential integrity constraints
ﺸﺎﺑﺘﺮzﺎﻟ8 ﻔﻴﻦ ﻫﺎﻟﻔﻘﺮە5ﺷﺎ
ﻪ4اﻟﻠﻲ ﻗ}ﻞ ﻟ™ﻦ ﺑﻨﻤﺮ ﻋﻠ
…ﺘﺮيŽﻞ اﻧﺘﻘ4…ﻔﺮ=ﺸŽ راح اﺧﺘﺮق اﻟparent ﺎل8 ﺤﺪث داﺗﺎ ﻣﻮﺟﻮدە8 ﻤﺴﺢ او8 اذا
• When you delete or update a value of the columns
referenced by other tables, the referential integrity
constraints may be violated.
• ON DELETE/UPDATE Clause
Lecture4
• The ON DELETE / ON UPDATE clause lets you determine
how Database automatically maintains referential
integrity if you remove or update a referenced primary
key value. If you omit this clause, then database does
not allow you to delete referenced key values in the
parent table that have dependent rows in the child
table.
28
٦٦ او ﻏﻴﺮﺗﻪ ل٦ ﻟﻮ ﺣﺬﻓﺖ دﻳ}ﺎرﺗﻤﻨﺖ، دﻳ}ﺎرﺗﻤﻨﺘﺰ @ﺲ٤ ﺎول8 دﻳ}ﺎرﺗﻤﻨﺘﺰ واﻟﻤﻮﻇﻔﻴﻦ ©ﺸﺘﻐﻠﻮن٦ ﺎن ﻋﻨﺪيÌ ﻟﻮ اﻧﺎ
اﻻوﻟﻰ ﻣﺎﻧﻘﺪر ﻻن٤ﻪ ﻓﻌﺎدي اﻋﺪل او اﺣﺬف ﻟ™ﻦ اﻟﺪﻳ}ﺎرﺗﻤﻨﺘﺰ ال4ﺘﻐﻴﺮ؟ ﻻ ﻻن ﻣﺎﻋﻨﺪي اﺣﺪ ﻓ±ﻪ ﺷﻲ ﺑ4ﻫﻞ ﻓ
.ﻪ ﻣﺎراح ©ﺴﻤﺢ ﻟﻲ اﺣﺬف4ﻪ روز ﻣﺮﺗ}ﻄﻪ ﻓ4 وﻓon delete\update ﺼﻴﺮ ف5 ﻓﺎﻧﺎ اذا ﻣﺎﺣﺪدت ا©ﺶ،ﻓﻴﻬﺎ داﺗﺎ
On delete -> CASCADE اﺳﻮء ﺷﻲ ال
Referential integrity constraints On update-> CASCADE اﻗﻀﻞ ﺷﻲ ال
Four options are supported when the user attempt to delete the CK and there
matching FKs:
• ON DELETE/UPDATE CASCADE: delete or update the CK row from the parent table
and all matching FK rows in the child table. }ﻞ±ﻠﺪ ﺗ5ﻜﻮن ﻋﻠﻰ اﻟﺸﺎ5 اﻟﺘﻐﻴﻴﺮ راح
ﻞ اﻟﻤﻮﻇﻔﻴﻦ اﻟﻠﻲ ﻓﻴﻬﺎÌ وﻓﻴﻬﺎ ﻣﻮﻇﻔﻴﻦ٣ ﻟﻮ اﺣﺬف دﻳ}ﺎردﻣﻨﺖCASCADE ﺪ اﻟﻠﻲ راح ﻓﻲ ال5ﺎﻟﺴﻼ8 ﻟﻮ ﻧﻤﺸﻲ ﻋﻠﻰ ﻧﻔﺲ اﻟﻤﺜﺎل اﻟﻠﻲ
ON DELETE <- ﻠﻲƒ اوﺗﻮﻣﺘchild ﺴﻮى بz راح ﻳparent ﺎل8 …ﻪªﺑﻴﺮوﺣﻮن ﻻن اﻟﻠﻲ اﺳ
ﺼﻴﺮون ©ﺸﺘﻐﻠﻮن ﻓﻲ4 ﺑ٣ ﺼﻴﺮ اﻟﻤﻮﻇﻔﻴﻦ اﻟﻠﻲ ©ﺸﺘﻐﻠﻮن ﻓﻲ4ﺘﻐﻴﺮ ﻋﺎدي ﺑ± ﺑ٣٣ وﺧﻠﻴﺘﻪ٣ ﺖ ﻋﻠﻰ اﻟﺪﻳ}ﺎردﻧﺖ رﻗﻢ5ﺪ8…ﺖ اªﻟﻮ ﺳ
ON UPDATE <- ٣٣
• ON DELETE/UPDATE SET NULL: delete or update the CK row from the parent table
Lecture4
and set the FK values to NULL in the child table.
ﺎﻣﻞÌ ﻜﻮﻧﻮن ﻣﻮﺟﻮدﻳﻦ ﻣﻊ4ﻞ اﻟﻤﻮﻇﻔﻴﻦ اﻟﻠﻲ ﻓﻴﻬﺎ ﺑÌ وﻓﻴﻬﺎ ﻣﻮﻇﻔﻴﻦ٣ ﻟﻮ اﺣﺬف دﻳ}ﺎردﻣﻨﺖSET NULL ﻟﻮ ﻧﻤﺸﻲ ﻋﻠﻰ ﻧﻔﺲ اﻟﻤﺜﺎل ﻓﻲ ال
ON DELETE/UPDATE <- null ﻜﻮن4 ﺑ٣٣ اﻟﻰ٣ ﻌﺪ ﻟﻮ اﺣﺪث رﻗﻢ اﻟﺪﻳ}ﺎردﻣﻨﺖ ﻣﻦ² و،null ﻜﻮن4ﺎﻧﺎﺗﻬﻢ @ﺲ رﻗﻢ اﻟﺪﻳ}ﺎردﻣﻨﺖ ﺑ4ﺑ
• This is valid only if the foreign key columns do not have the NOT NULL qualifier
specified.
• ON DELETE/UPDATE SET Default: delete or update the CK row from the parent
table and set the FK values to the specified default value in the child table.
ﻔﻮﻟﺖ ﻓﺎﻟﻴﻮ5ﻞ ﺷﻲ اﺧﺘﺎر دÌ ﻟﻮ راح اﺧﺘﺎر ﻫﺬي ﻻزم ﻗ}ﻞ،ﻔﻮﻟﺖ ﻓﺎﻟﻴﻮ5ﺎﺧﺬون اﻟﺪ5 ﺖ راح5ﺪ8 ﻟﻮ اﺣﺬف او اﺳﻮي اSET Default ﻫﻨﺎ ﻓﻲ
• Valid only if DEFAULT constraint is specified
29
• No action: Reject ﺗﻤﻨﻊthe deleteﺖ5ﺪ8 واﻻoperation from the parent table.
ﻔﻮﻟﺖ5ﺖ اذا ﻣﺎﺣﺪدت وش ©ﺴﻮي اﻟﺪ4ﻠ5اﻻون د
• This is the default setting if the ON DELETE rule is omitted. ﻔﻮﻟﺖ ﻻزم5ﺖ ﻣﺎﻋﻨﺪي ﺷﻲ د5ﺪ8 اﻻون ا،ﻧﻮ ا•ﺸﻦ
اﺣﺪد
ﻪ اﺣﺪ ﻣﺮﺗ}ﻂ ﻋﺎدي4ﺖ اذا ﻣﺎﻓ4ﻠ5ﺖ او د5ﺪ8ﺴﻤﺢ ﻟﻲ اﺳﻮي ﺷﻲ ﺗﻤﻨﻌﻨﻲ اﺳﻮي اà ﻪ ﻣﺎراح4ﻪ اﺣﺪ ﻣﺮﺗ}ﻂ ﻓ4اذا ﻓ
PK EmpId EmpName
ﺎرuﺎﻻﺧﺘx وﻣﻤﻜﻦ ﺗﺠ|ﺐ ﻛﺬا،ﻣﺜﺎل
1 Ali
• CREATE TABLE EmpMaster 2 Slaut
(EmpId CHAR(1) PRIMARY KEY, 3 John
EmpName VARCHAR(25)); FK
EmpId DeptNo DeptName
1 101 AAA
• CREATE TABLE EmpDetails 2 101 AAA
(DeptId CHAR(3) PRIMARY KEY, 3 103 CCC
DeptName VARCHAR(20)
Lecture4
EmpId CHAR(1) FOREIGN KEY REFERENCES EmpMaster(EmpId)
ON DELETE CASCADE );
parent child
PK EmpId EmpName
ﺎرuﺎﻻﺧﺘx وﻣﻤﻜﻦ ﺗﺠ|ﺐ ﻛﺬا،ﻣﺜﺎل
1 Ali
• CREATE TABLE EmpMaster 2 Slaut
(EmpId CHAR(1) PRIMARY KEY, 3 John
EmpName VARCHAR(25)); FK
EmpId DeptNo DeptName
1 101 AAA
• CREATE TABLE EmpDetails 2 101 AAA
(DeptId CHAR(3) PRIMARY KEY, 3 103 CCC
DeptName VARCHAR(20)
Lecture4
EmpId CHAR(1) FOREIGN KEY REFERENCES EmpMaster(EmpId)
ON DELETE SET NULL );
Lecture4
allows only certain values for this column.
32
Check Constraints
Syntax: ﺑﻴﻦ ﻗﻮﺳﻴﻦ ﺗﺤﻄﻴﻦ اﻟﺸﺮط ﺣﻘﻚ
create table table-name (
column-name1 datatype Check (Check_condition)
);
Lecture4
OR
Lecture4
Staff_salary numeric (8,2) not null,
Dept_no char(4) not null ,
Constraint staff_pk Primary key (staff_no),
Constraint staff_fk Foreign key (dept_no) references department
(dept_no),
Constraint staff_sal check (staff_salary >10000.00));
34
To allow naming of a
CHECK constraint
DEFAULT constraint
Lecture4
Syntax:
create table table-name (
column-name1 datatype Default (Default_value)
);
35
DEFAULT constraint
Lecture4
(
P_Id char(5) NOT NULL,
LastName varchar(255) NOT NULL,
FirstName varchar(255),
Address varchar(255),
City varchar(255) DEFAULT 'Sandnes'
)
36
Example : All Constraints
Create table staff(
Staff_no char(3),
Staff_name varchar(20) not null,
DateofBirth date,
Staff_nationality char(10) default ‘Saudi’,
Lecture4
Staff_salary numeric(8,2) not null,
Dept_no char(4),
[
Constraint staff_pk Primary key (staff_no),
Constraint staff_fk Foreign key (dept_no) references
department (dept_no) on delete set null,
Constraint staff_sal check (staff_salary >10000.00),
37
UNIQUE(staff_name, DateofBirth));
Modifying Table Definitions (alter )
Lecture4
• Add a new table constraint.
• Drop a table constraint.
• Set a default for a column.
• Drop a default for a column.
38
Modifying Table Definitions ˆﻘﺔ ﻛﺘﺎﺑﺘﻬﺎ‰ﻃ
Lecture4
39
Examples
alter table orders
add (quantity numeric (3) not null);
Lecture4
drop COLUMN DOB ;
Lecture4
• (2) CASCADE: The DROP operation proceeds and automatically drops
the column from any database objects it is referenced by.
• If Cascade Constraints is used, the constraints will be dropped first.
ﻌﺪﻳﻦ اﺣﺬﻓﻪ ﻫﻮ8 ﻪ اول4}ﻠﺰ اﻟﻠﻲ ﻣﺮﺗ}ﻄﻪ ﻓ±ﻫﻨﺎ راح اﺣﺬف اﻟﺘ
• example
• Drop table Staff;
ﻪ4}ﻞ ﻣﺮﺗ}ﻂ ﻓ±ﻪ ﺗ4 راح ‘ﻤﻨﻊ اﻟﺤﺬف ﻻن ﻓ،Restrict ﻔﻮﻟﺖ اﻟﻠﻲ ﻫﻲ5ﺨﺘﺎر ﻟﻲ اﻟﺪ5 ﻫﻨﺎ ﻣﺎ اﺧﺘﺮﻧﺎ ﺷﻲ ﻓﺎراح
• Drop table Department;
ﻪ4}ﻞ ﻣﺮﺗ}ﻂ ﻓ±ﻪ ﺗ4 ﻟ™ﻦ راح ‘ﺤﺬف ﻻن ﻣﺎﻓ،Restrict ﻔﻮﻟﺖ اﻟﻠﻲ ﻫﻲ5ﺨﺘﺎر ﻟﻲ اﻟﺪ5 ﻫﻨﺎ ﻣﺎ اﺧﺘﺮﻧﺎ ﺷﻲ ﻓﺎراح 41
• Drop table Department cascade constraints;
cascade ﻪ ﻻﻧﻨﺎ اﺧﺘﺮﻧﺎ4ﻞ ﺷﻲ ﻣﺮﺗ}ﻂ ﻓÌ ﺤﺬف و…ﺤﺬف5 ﻫﻨﺎ راح
Dropping Constraints
Lecture4
constraint_name;
42
Example
• To DROP a CHECK Constraint
Lecture4
• To DROP a FOREIGN KEY Constraint
ALTER TABLE Orders
DROP CONSTRAINT fk_PerOrders;
43
ALTER/MODIFY COLUMN
Lecture4
ALTER COLUMN column_name datatype;
Example:
ALTER TABLE Persons
ALTER COLUMN DateOfBirth year;
44
ﺎﻟﻤ|ﺪ ﺗﻴﺮم ﻻﻧﻨﺎ ﺑ—ﺴﺘﺨﺪﻣﻬﺎx ˆﻨﺎ ﻋﻠﻴﻬﺎ ﻣﺎراح ﺗﻄﻠﺐ ﻧﻜﺘﺒﻬﺎ‰ اﻟﻠﻲ ﻣsyntaxﺎﻟﻨﻬﺎ‘ﺔ الx
.¡ﻪ وˆﻜﻮن ﻋﻠﻴﻬﺎ ﺳﺆال¢ﺲ اﻟﻤﻬﻢ ﻧﻔﻬﻤﻬﺎ ﻻن ﻣﻤﻜﻦ ﺗﺠﻴﺒﻬﺎ ﻣﻜﺘc ﺎﻟﺒﺮوﺟﻜﺖx