0% found this document useful (0 votes)
23 views10 pages

Integrity &security

The document describes various data types in SQL including character, numeric, date, and time data types. It also discusses structured data types for creating complex data types as well as distinct data types for defining new types. The document covers integrity constraints such as not null, unique, check, primary key, and foreign key constraints. It provides examples of creating tables with constraints. Finally, it discusses security and authorization in SQL including the grant and revoke statements for providing and revoking privileges on database objects.

Uploaded by

Vivek Siva
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
23 views10 pages

Integrity &security

The document describes various data types in SQL including character, numeric, date, and time data types. It also discusses structured data types for creating complex data types as well as distinct data types for defining new types. The document covers integrity constraints such as not null, unique, check, primary key, and foreign key constraints. It provides examples of creating tables with constraints. Finally, it discusses security and authorization in SQL including the grant and revoke statements for providing and revoking privileges on database objects.

Uploaded by

Vivek Siva
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 10

• Basic data Types

Data type Description

CHARACTER(n) Character string, fixed length n. See


CHARACTER VARYING(n)
or Variable length character string, maximum length n.
VARCHAR(n)
BINARY(n) Fixed length binary string, maximum length n.
BINARY VARYING(n) or
Variable length binary string, maximum length n.
VARBINARY(n)
INTEGER(p) Integer numerical, precision p.
SMALLINT Integer numerical precision 5.
INTEGER Integer numerical, precision 10.
BIGINT Integer numerical, precision 19.
DECIMAL(p, s) Exact numerical, precision p, scale s.

NUMERIC(p, s) Exact numerical, precision p, scale s.

FLOAT(p) Approximate numerical, mantissa precision p.

REAL Approximate numerical ,mantissa precision 7.

FLOAT Approximate numerical ,mantissa precision 16.


DATE
Composed of a number of integer fields, represents an absolute point in time, depending on sub-
TIME
type.
TIMESTAMP
User defined data type

• Structured Data type-allows to create a complex data type


• Distinct data type –Create type cluase can be used to define
new types
• create domain Dollars numeric(12, 2)
• create domain Pounds numeric(12,2)
Create table account(acc number int,bname varchar(10),
balance dollars);
• One type can be converted to another type y using the
keyword cast
• Cast(account.balance to numeric(12,2))
Integrity Constraints
• Constraints on a single table
– Not Null
– Unique
– Check
• CREATE TABLE Persons
(
P_Id int NOT NULL,
LastName varchar(255) NOT NULL,
FirstName varchar(255),
Address varchar(255),
City varchar(255),
CONSTRAINT uc_PersonID UNIQUE (P_Id,LastName)
)
Integrity Constraints

• CREATE TABLE Persons


(
P_Id int NOT NULL CHECK (P_Id>0),
LastName varchar(255) NOT NULL,
FirstName varchar(255),
Address varchar(255),
City varchar(255)
)
Referential Integrity
• CREATE TABLE Orders
(
O_Id int NOT NULL PRIMARY KEY,
OrderNo int NOT NULL,
P_Id int FOREIGN KEY REFERENCES Persons(P_Id)
)
• CREATE TABLE Orders
(
O_Id int NOT NULL,
OrderNo int NOT NULL,
P_Id int,
PRIMARY KEY (O_Id),
CONSTRAINT fk_PerOrders FOREIGN KEY (P_Id)
REFERENCES Persons(P_Id)
)
• ALTER TABLE Orders
ADD FOREIGN KEY (P_Id)
REFERENCES Persons(P_Id)
Security
• Security - protection from malicious attempts to steal or
modify data.
• Authentication and authorization mechanisms to allow
specific users access only to required data
Forms of authorization on parts of the database:

• Read authorization - allows reading, but not modification of


data.
• Insert authorization - allows insertion of new data, but not
modification of existing data.
• Update authorization - allows modification, but not deletion
of data.
• Delete authorization - allows deletion of data
• The grant statement is used to confer authorization
grant <privilege list>
on <relation name or view name> to <user list>
• <user list> is:
– a user-id
– public, which allows all valid users the privilege granted
– A role
create role teller
create role manager

grant select on branch to teller


grant all privileges on account to manager

grant teller to alice, bob


grant manager to avi
Privileges in SQL

• select: allows read access to relation,or the ability to query using the view
– Example: grant users U1, U2, and U3 select authorization on the branch
relation:
grant select on branch to U1, U2, U3
• insert: the ability to insert tuples
• update: the ability to update using the SQL update statement
• delete: the ability to delete tuples.
• references: ability to declare foreign keys when creating relations
• all privileges: used as a short form for all the allowable privileges
Revoking Authorization in SQL

• The revoke statement is used to revoke authorization.


revoke<privilege list>
on <relation name or view name> from <user list>

You might also like