filmov
tv
Practically understanding on SQL constraints in SQL server.

Показать описание
===Not Null
CREATE TABLE employees1 (
id INT NOT NULL ,
name VARCHAR(50) NOT NULL,
age INT);
select * from employees1
insert into employees1(id,name,age) values(102,'lav',40)
insert into employees1(id,name,age) values(102,'lav',40)
====UNIQUE Constraint
CREATE TABLE students (
id int,
email VARCHAR(50),
phone VARCHAR(20));
select * from students
=========PRIMARY KEY Constraint
CREATE TABLE customers (
id INT PRIMARY KEY,
name VARCHAR(50),
address VARCHAR(100)
);
insert into customers values(104,'lavlesh',null)
select * from customers
===FOREIGN KEY Constraint
CREATE TABLE orders (
id INT,
customer_id INT,
order_date DATE,
FOREIGN KEY (id) REFERENCES customers(id)
);
drop table orders
select * from orders
insert into orders values(103,105, '2023-03-10')
CREATE TABLE employees1 (
id INT NOT NULL ,
name VARCHAR(50) NOT NULL,
age INT);
select * from employees1
insert into employees1(id,name,age) values(102,'lav',40)
insert into employees1(id,name,age) values(102,'lav',40)
====UNIQUE Constraint
CREATE TABLE students (
id int,
email VARCHAR(50),
phone VARCHAR(20));
select * from students
=========PRIMARY KEY Constraint
CREATE TABLE customers (
id INT PRIMARY KEY,
name VARCHAR(50),
address VARCHAR(100)
);
insert into customers values(104,'lavlesh',null)
select * from customers
===FOREIGN KEY Constraint
CREATE TABLE orders (
id INT,
customer_id INT,
order_date DATE,
FOREIGN KEY (id) REFERENCES customers(id)
);
drop table orders
select * from orders
insert into orders values(103,105, '2023-03-10')