7sql
7sql
databases.
can take i.e., it describes the legal values that an attribute can take.
□ Degree : It is the total number of attributes present in the relation.
□ Candidate Key
□ Super Key
□ Composite Key
□ Primary Key
□ Alternate Key
□ Foreign Key
□ Relational models make use of some rules to ensure the accuracy and
accessibility of the data.
□ These rules or constraints are known as Relational Integrity
Constraints.
a set of attributes (Primary Key) that can uniquely identify a tuple in that
relation. This key can never be NULL or contain the same value for two
different tuples.
□ Referential Integrity Constraint : It is defined between two inter-
□ Most modern RDBMS products use some type of SQL dialect as their primary
query language.
□ SQL can be used to create or destroy objects, such as tables, on the database server
and to do things with those objects, such as put data into them or query for data.
□ The Transact-SQL language is an enhancement to SQL, the American National Standards Institute
(ANSI) standard relational database language.
□ It provides a comprehensive language that supports defining tables, inserting, deleting, updating, and
accessing the data in the table.
© ISBAT UNIVERSITY - 2020. 21-Jan-23
Transact-SQL 1-2
SELECT LoginID
FROM Employee
WHERE JobTitle = 'Design Engineer'
□ Following figure shows the result of the SELECT statement:
□ Transact-SQL includes many syntax elements that are used by or that influence
most statements.
□ These elements include data types, predicates, functions, variables, expressions
21-Jan-23
TYPES OF SQL
(SUB LANGUAGES OR COMMANDS)
16
DDL is used to define and manage all attributes and properties of a database,
including row layouts, column definitions, key columns, file locations, and storage
strategy.
DDL statements are used to build and modify the structure of tables and other
objects such as views, triggers, stored procedures, and so on.
For each object, there are usually CREATE, ALTER, and DROP statements (such
as, CREATE TABLE, ALTER TABLE, and DROP TABLE).
Drop a Column
Syntax: Alter Table Tablename Drop Column ColumnName
Example: Alter Table Person Drop Column DOB
Drop:
21-Jan-23
Data Manipulation Language (DML)
All database users can use these commands during the routine operations on a
database.
21-Jan-23
INSERT Command
SELECT statement
Data is an important part of database, so proper steps should be taken to check that
no invalid user accesses the data.
Permissions are controlled by using the GRANT, REVOKE, and DENY statements.
DCL statements are also used for securing the database. The three basic DCL
statements are as follows:
□ A data type is an attribute defining the type of data that an object can contain.
□ Data types must be provided for columns, parameters, variables, and functions that
return data values, and stored procedures that have a return code.
□ Transact-SQL includes a number of base data types, such as varchar, text, and int.
□ All data that is stored in SQL Server must be compatible with one of the base data
types.
□ The following objects have data types:
Columns present in tables and views
Variables
Transact-SQL functions that return one or more data values of a specific data type
Stored procedures that have a return code belonging to the integer data type
Description
int
A column of this type occupies 4 bytes of memory space. Is
typically used to hold integer values. Can hold integer data
from -2*31 (-2,147,483,648) to 2*31-1 (2,147,483,647).
smallint A column of this type occupies 2 bytes of memory space.
Can hold integer data from -32,768 to 32,767.
tiny int A column of this type occupies 1 byte of memory space. Can
hold integer data from 0 to 255.
bigint
A column of this type occupies 8 bytes of memory space. Can
hold data in the range -2A63 (-9,223,372,036,854,7 75,808) to
2A63-1 (9,223,372,036,854,775,807).
numeric A column of this type has fixed precision and scale.
money
A column of this type occupies 8 bytes of memory space.
Represents monetary data values ranging from -2A63/10000
(-922,337,203,685,477.5808) to 2A63-1
© ISBAT UNIVERSITY - 2021 (922,337,203,685,477.5807). 21-Jan-23
Data Types
DDL Commnds:
1. Create
2. Alter
3. Drop
Create Syntax:
Example:
Drop:
£Xv<c »
CREATE TABLE Orders ( OrderID int NOT NULL, OrderNumber int NOT
NULL, PersonID int, PRIMARY KEY (OrderID), CONSTRAINT
FK_PersonOrder FOREIGN KEY (PersonID )
REFERENCES Persons(PersonID)
INSERT:
Syntax:
insert into tablename values (value1, value2....valueN)
Example:
insert into employee values(100,'George','Cloony',0781464113,
'15-Mar-2015',1500,'Entebbe')
using custom order:
insert into employee(EID,FIRST_NAME,LAST_NAME,SALARY,
HIRE-DATE,CITY,PHONE)
values(100,'ryan','reynolds',3000,'21-JUL-16','Entebbe',0752242243)
Syntax:
Example:
Example:
Delete from Employee where eid=105
Delete from Employee where eid in(105,106,109) (or)
Delete from Employee where eid=105 or eid=106 or eid=109