0% found this document useful (0 votes)
25 views

1.5. Operators

The document discusses SQL data definition language and various constraints that can be applied when creating tables in SQL. It provides examples of creating tables using NOT NULL, primary key, foreign key, unique, check, and default constraints. Primary keys can be single column or composite keys across multiple columns. Foreign keys define relationships between tables by referencing a primary key column. Check constraints validate column values meet a specified condition.

Uploaded by

crazz1
Copyright
© © All Rights Reserved
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
25 views

1.5. Operators

The document discusses SQL data definition language and various constraints that can be applied when creating tables in SQL. It provides examples of creating tables using NOT NULL, primary key, foreign key, unique, check, and default constraints. Primary keys can be single column or composite keys across multiple columns. Foreign keys define relationships between tables by referencing a primary key column. Check constraints validate column values meet a specified condition.

Uploaded by

crazz1
Copyright
© © All Rights Reserved
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 2

1.5.

Operators
Arithmetic operators like +, -, *, /
Logical operators: AND, OR, NOT
Relational operators: =, <=, >=, < >, < , >
1.6. SQL-Data Definition Language
1.6.1. Types Of Constraints
Column Level
Table
Primary Key Constraint
Foreign Key Constraint
Unique Constraint
Check Constraint
1.6.2. SQL - CREATE TABLE
Syntax:
CREATE TABLE tablename ( column_name data_ type constraints, )
Implementing NOT NULL and Primary Key
CREATE TABLE Customer_Details(
Cust_ID Number(5) CONSTRAINT Nnull1 NOT NULL,
Cust_Last_Name VarChar2(20) CONSTRAINT Nnull2 NOT NULL,
Cust_Mid_Name VarChar2(4),
Cust_First_Name VarChar2(20),
Account_No Number(5) CONSTRAINT Pkey1 PRIMARY KEY,
Account_Type VarChar2(10) CONSTRAINT Nnull3 NOT NULL,
Bank_Branch VarChar2(25) CONSTRAINT Nnull4 NOT NULL,
Cust_Email VarChar2(30)
);
Implementing Composite Primary Key
CREATE TABLE Customer_Details(
Cust_ID Number(5) CONSTRAINT Nnull7 NOT NULL,
Cust_Last_Name VarChar2(20) CONSTRAINT Nnull8 NOT NULL,
Cust_Mid_Name VarChar2(4),
Cust_First_Name VarChar2(20),
Account_No Number(5) CONSTRAINT Nnull9 NOT NULL,
Account_Type VarChar2(10) CONSTRAINT Nnull10 NOT NULL,
Bank_Branch VarChar2(25) CONSTRAINT Nnull11 NOT NULL,
Cust_Email VarChar2(30),
CONSTRAINT PKey3 PRIMARY KEY(Cust_ID,Account_No)
);
Implementation of Unique Constraint
Create Table UnqTable(
ECode Number(6) Constraint PK11 Primary Key,
EName Varchar2(25) Constraint NNull18 NOT NULL,
EEmail Varchar2(25) Constraint Unq1 Unique
);
Implementation of Primary Key and Foreign Key Constraints
CREATE TABLE EMPLOYEE_MANAGER(
Employee_ID Number(6) CONSTRAINT Pkey2 PRIMARY KEY,
Employee_Last_Name VarChar2(25),

Employee_Mid_Name VarChar2(5),
Employee_First_Name VarChar2(25),
Employee_Email VarChar2(35),
Department VarChar2(10),
Grade Number(2),
MANAGER_ID Number(6) CONSTRAINT Fkey2
REFERENCES EMPLOYEE_MANAGER(Employee_ID)
);
Implementation of Check Constraint
CREATE TABLE EMPLOYEE(
EmpNo NUMBER(5) CONSTRAINT PKey4 Primary Key,
EmpName Varchar(25) NOT NULL,
EmpSalary Number(7)
Constraint chk Check (EmpSalary > 0 and EmpSalary < 1000000)
)
Implementation of Default
CREATE TABLE TABDEF(
Ecode Number(4) Not Null,
Ename Varchar2(25) Not Null,
ECity char(10) DEFAULT Mysore
)

You might also like