Professional Documents
Culture Documents
Expt No 2
Expt No 2
Expt No 2
Name
Theory:
1.1Introduction to SQL
Structured Query Language is a special-purpose programming language designed for
managing data held in a relational database management system (RDBMS) Originally based
upon relational algebra and tuple relational calculus,
SQL consists of a data definition language and data manipulation language. The scope of SQL
includes data insert, query, update and delete, schema creation and modification, and data
access control. Although SQL is often described as, and to a great extent is, a declarative
language (4GL).
SQL was one of the first commercial languages for Edgar F. Codd's relational model. Despite not
entirely adhering to the relational model as described by J.F.Codd’s, it became the most widely
used database language.
Datatype Description
Date Stores dates from January 1, 4712 B.C. to December 31, 4712 A.D.
Oracle predefine format of Date data type is DD-MON-YYYY.
Raw(Size) Stores binary data of length size. Maximum size is 2000 bytes. One
must have to specify size with RAW type data, because by default it
does not specify any size.Long Raw Store binary data of variable
length up to 2GB(Gigabytes).
BLOB To store a Binary Large Object such graphics, video clips and sound
files.Maximum size is 4GB
BFILE Contains a locator to a large Binary File stored outside the database.
Enables byte stream I/O access to external LOBs residing on the
database server. Maximumsize is 4GB
1.6 Data Definition Language The Data Definition Language (DDL) is used to create and
modify database schema and database objects.
5) TRUNCATE: remove all records from a table, including all spaces allocated for the
records are removed
1.6.2 ALTER TABLE : ALTER TABLE command to add and drop various constraints on an
existing table.
The basic syntax of ALTER TABLE to ADD COLUMN in an existing table is as follows −
The basic syntax of ALTER TABLE to change the DATA TYPE of a column in a table is as
follows −
The basic syntax of ALTER TABLE to add a NOT NULL constraint to a column in a table is as
follows −
1.6.3 DROP TABLE statement is used to remove a table definition and all associated
data, indexes, rules, triggers, and constraints for that table.
1.6.4 TRUNCATE TABLE command is used to delete complete data from an existing
table
The UNIQUE and PRIMARY KEY constraints both provide a guarantee for uniqueness
for a column or set of columns.
1.8 Dropping Constraints: To remove a constraint you need to know its name. If the name is
known, it's easy to drop. Else you need to find out the system generated name. The psql
command \d tablename can be helpful here; the general syntax is:
LAB EXERCISES: