0% found this document useful (0 votes)
16 views5 pages

PR 06 and 07

Uploaded by

Shreya Dhone
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
16 views5 pages

PR 06 and 07

Uploaded by

Shreya Dhone
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

Difference between primary key constraint and not null

constraint
Primary Key:

The PRIMARY KEY constraint uniquely identifies each record in a


database table.

Primary keys must contain unique values.

A primary key column cannot contain NULL values.

Most tables should have a primary key, and each table can have only
ONE primary key.

NOT NULL constraint:

The NOT NULL constraint enforces a column to NOT accept NULL


values.

The NOT NULL constraint enforces a field to always contain a value.


This means that you cannot insert a new record, or update a record
without adding a value to this field.

The following SQL enforces the "PId" column and the "Name" column
to not accept NULL values:

CREATE TABLE Persons


(
PId int NOT NULL PRIMARY KEY,
Name varchar(255) NOT NULL,

PID Name
1 AAAA
2 AAAA
3 BBBB

List different operators used in check condition in SQL

Operator Description
this operator is used to compare the value
ANY
in list according to the condition.
this operator is used to search for values, that are
BETWEEN
within a set of values
this operator is used to compare a value to that
IN
specified list value

Write the signification of maintaining order of attributes


while inserting values in tables
Whenever you insert the elements into the database. It is
important to mention the table name, But not the Column name
in SQL query. It is imp to make the order of the given values is
in the same order as the columns in the table.

write the consequences of entering values of varied data


type in attribute in sql

 Every attribute should have its own data type. Different data
types are used for different attributes these are- String (the
number, character and letter combination of data type). It has
different varieties like- graphic, character, clob, db- clob,
binary, etc; Numeric (data off numbers).
 These include- integer, smallint, bigint, decimal, etc. and Date
time (data that include time and date). The values of different
data types would not be supported in an attribute.

Insert Command:-
1.Insert values into table give reference of other table
Syntax:-
insert into emp5 select * from emp2;

2.Insert Multiple values inti table:-

CREATE TABLE department


(dno INT
PRIMARY KEY,
dname VARCHAR(20) NOT NULL,
loc VARCHAR(50) NOT NULL
);
INSERT INTO department
(dno,
dname,
loc
)
VALUES
(10,
'ENGINEERING',
'New York'
);

INSERT INTO department


(dno,
dname,
loc
)
VALUES
(40,
'Sales',
'NJ'
),
(50,
'Marketting',
'MO'
),
(60,
'Testing',
'MN'
);

CREATE TABLE demo


(id INT DEFAULT 0,
hirdate DATETIME DEFAULT GETDATE()
);

INSERT INTO demo

DEFAULT VALUES;

SELECT *

FROM demo;

You might also like