Вы находитесь на странице: 1из 5

SQL-Structured query language

Using sql we can communicate with databases.

It is the standard language for relational database management system.

SQL is a combination of 5 different languages

1.DDL 2.DML 3.TCL 4.DCL 5.DRL

1.DDL:

In DDL we have CREATE,ALTER,DROP,TRUNCATE COMMANDS

CREATE:

CREATE command is used to create database objects like tables,views ets.,

Synatx:

create table <table name>

<column name> datatype(width),

<column name> datatype(width)

);

Rules for naming a tables & columns:

1.Must start with alphabet.

2.space characters are invalid.

3.oracle keywords are invalid.

4.oracle names are not case sensitive.

5.The exist names or objects are not allowed.

DATA TYPES:

1.CHAR(SIZE)

To store fixed length char strings

2.Varchar2(size)

To store variable length.


Char(10)

R A J U

VARCHAR2(10)

R A J U U

3.Number(p,s)

p-prcision s-scale

ex:number(6,2) - 4 integer and 2 decimal places

4.DATE:

The default format is DD-MM-YY.

CONSTRAINT:

Constraint is a rule or restriction.

These constraints ensure that accuracy and reliability of the data in a table.

1.NOT NULL:

It is undefined value.

It is not equal to zero.

Null is not equal to null.

2.UNIQUE:

It is to maintain the distinct values.

3.PRIMARY KEY:

The combination of not null and unique.

4.CHECK:

To restrict or validate the values in the list in specified range

5.REFERENCES:

It is to establish the relation between the columns of different tables.

FOREIGN KEY
ALTER:

To change the defination of db objects

Syntax:

ALTER TABLE <TABLE NAME> KEYWORD(<COLNAME> DATATYPE(WIDTH),

<COL NAME> DATATYPE(WIDTH));

Keywords used in the alter command are:

1.Modify 2.Add 3.Enable/disable/drop 4.Rename.

Modify:

Used to increase or decrease the size of the column.

Modify null to not null or not null to null

To change the data type.

ADD:

This class is used to add new columns to the existing table.

We can add a new constraint to the existing table.

DROP:

Delete the column permanently.

Delete the constraints permanently.

Syntax:alter table <table name> drop column <column name>.

Rename:

Used to rename the column names.

Syntax:alter table <table name> rename column <oldname> to <newname>

DROP:

Drop a table

Syntax: drop table <tablename>;


DML:

In DML we have insert,update,delete commands.

Insert:

To insert rows of information into database tables.

Insert into <table name> values(<val>,<val>......);

Update:

This command is used to modify the existing data of a database table.

Syntax:

UPDATE <TABLENAME> SET <COLUMN NAME>=<VALUEEXPRESSION>,

COLUMN NAME>=<VALUEEXPRESSION>,

..............................................................................................,

WHERE <CONDITION>;

Delete:

Delete from <table name> where <condition>.