Friday, April 28, 2023

Sql Constraints? #sql

 1. DEFAULT Constraint: Provides a default value for a column when none is specified.

2. UNIQUE Constraint: Ensures that all the values in a column are different.

3. PRIMARY Key: Uniquely identifies each row/record in a database table.

4. FOREIGN Key: Uniquely identifies a row/record in any another database table.

5. CHECK Constraint: The CHECK constraint ensures that all values in a column satisfy

certain conditions.

6. INDEX: Used to create and retrieve data from the database very quickly.

7. NOT NULL Constraint: Ensures that a column cannot have a NULL value.



CREATE TABLE EMPLOYEES

(

   [Name] VARCHAR(50) PRIMARY KEY,

   ID INT NOT NULL,

   IsActive BIT DEFAULT(1),

   AGE INT UNIQUE

)


SELECT ID,IsActive,AGE,[Name] FROM EMPLOYEES


INSERT INTO EMPLOYEES(ID,[Name],AGE) VALUES(1,'Mohit17',40)


INSERT INTO EMPLOYEESALARY(SALARY,NAME_PR) VALUES(100000,'Mohit1722')


Select *from EMPLOYEESALARY


--CREATE TABLE EMPLOYEESALARY

--(

--    SALARY INT NOT NULL,

-- NAME_PR VARCHAR(50) FOREIGN KEY REFERENCES EMPLOYEES([Name])

--)


CREATE TABLE EmployeeAddress

(

    AGE INT NOT NULL CHECK(AGE >=18)

)


SELECT *from EmployeeAddress


INSERT INTO EmployeeAddress(AGE) VALUES(18)



CREATE INDEX INDEX_AGE

ON EmployeeAddress(AGE)

No comments:

Post a Comment

Mastering Angular Reactive Forms: Part 1 - Building Dynamic and Interactive Forms

  #AngularReactiveForms #AngularForms #ReactiveFormsTutorial #AngularTutorial #AngularFormsPart1 #AngularFormValidation #AngularFormSu...