NOTES 2 Constraints and Assignment
NOTES 2 Constraints and Assignment
The SQL INSERT INTO Statement is used to add new rows of data to a table in the
database.
a.If you are adding values for all the columns of the table, you do not need to
specify the column names in the SQL query. However, make sure the order of the
values is in the same order as the columns in the table.
Here, the INSERT INTO syntax would be as follows:
Assignment
===========
Create table with the name of your choice and then add
columns which must consists 6 records
for example:
FirstName LastName Age salary
---------||--------||----||------
Girish Kumar 30 66000
Hema kumari 26 45000
Constraints
-----------
Constraints are the rules enforced on the data columns of a table. These 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 database.
Constraints could be either on a column level or a table level. The column level
constraints are applied only to one column,
whereas the table level constraints are applied to the whole table.
The constraints in SQL are
==========================
1) NOT NULL : This constraint can be used on the data in a table , whenever the
column should not be left empty.
1) NOT NULL:
Employee
Name | Id | salary | department_Id
CREATE TABLE Employee
(
Name varchar2(20) NOT NULL,
);
2) UNIQUE : This constraint can be applied on the column whenever the values
to be stored without any duplicates.
2)UNIQUE
CREATE TABLE Employee
(
Name varchar2(20) NOT NULL,
Id int UNIQUE AND NOT NULL
);
Assignment 2:
===================
EXAMPLE:
CREATE TABLE Atom
(
ID int PRIMARY KEY,
name varchar2(20) NOT NULL,
age int CHECK(age>=18),
salary int,
isMarried varchar2(4) DEFAULT 'NO'
);