Lecture2 SQL ConstraintII
Lecture2 SQL ConstraintII
◼ Create a table
CREATE TABLE animals (
id INT NOT NULL AUTO_INCREMENT,
name CHAR(30) NOT NULL,
PRIMARY KEY (id)
);
C:\Users\Islam>cd ..
C:\xampp>cd mysql Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
C:\xampp\mysql>cd bin Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
# cd mysql
Lab-2@DESKTOP-UGV9ION c:\xampp\mysql
# cd bin
Lab-2@DESKTOP-UGV9ION c:\xampp\mysql\bin
# mysql.exe -u root -p
Enter password:
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MariaDB [(none)]>
◼ Adding values
◼ Insert
insert into users (userID)values(104)
◼ Drop
The "P_Id" column in the "Orders" table is a FOREIGN KEY in the "Orders" table.
customer
orders
customer
UPDATE customer
SET CustomerID=1000
WHERE CustomerID = 1001;
Child table has
dependency
◼ CASCADE:
❑ If a row from the parent table is deleted or
updated,
◼ the values of the matching rows in the child table
automatically deleted or updated.
categories
products
categories
UPDATE categories
SET categoryId=1000
WHERE categoryId = 1
Delete phone