20
General Commands for tables Creating a table Command: create table <table name> (<attribute1> data type, <attribute2> data type,………………..<attribute N> data type); Describing a table Command: Descibe tablename; Inserting values into table Command: insert into <table name> values (<attribute1> , <attribute2> ,………………..<attribute N> data type);

Dbms file

Embed Size (px)

DESCRIPTION

A practical file on Database Management System on the Oracle-SQL software..

Citation preview

Page 1: Dbms file

General Commands for tables

Creating a tableCommand:

create table <table name> (<attribute1> data type, <attribute2> datatype,………………..<attribute N> data type);

Describing a tableCommand:

Descibe tablename;

Inserting values into tableCommand:

insert into <table name> values (<attribute1> , <attribute2> ,………………..<attributeN> data type);

Page 2: Dbms file

Creating Table with Primary Key ConstraintCommand:

Create table tablename( <attribute1> datatype primary key);

Viewing the tableCommand:

select * from <table name>;

Viewing selected columns in tableCommand:

select * from <table name> where <attribute >=;

Page 3: Dbms file

Altering the table to modifyCommand:

Alter table tablename modify(<attribute> datatype);

Altering the table to add a columnCommand:

Alter table tablename add(<attribute> datatype);

To arrange data in some particular order in table(sorting)Command:

select * from <table name> order by <col 1>, <col 2>;

Page 4: Dbms file

To drop columns from a tableCommand:

Alter table tablename drop column columnname;

Deleting a specific entryCommand:

delete from <table name> where <attribute 1=att. Value>;

To change the name of existing tableCommand:

rename <old table name> to <new table name>;

Page 5: Dbms file

Count FunctionCommand:

Select count(columnname) from tablename;

Count Distinct FunctionCommand:

Select count(distinct columnname) from tablename;

Maximum FunctionCommand:

Select max(columnname) from tablename;

Page 6: Dbms file

Minimum FunctionCommand:

Select sum(columnname) from tablename;

Average FunctionCommand:

Select avg(columnname) from tablename;

Page 7: Dbms file

Numeric Functions

Absolute FunctionCommand:

Select abs(value) from dual;

Cosine FunctionCommand:

Select cos(value) from dual;

Inverse Cosine FunctionCommand:

Select acos(value) from dual;

Page 8: Dbms file

Hyperbolic CosineCommand:

Select cosh(value) from dual;

Sine FunctionCommand:

Select sin(value) from dual;

Inverse Sine FunctionCommand:

Select asin(value) from dual;

Page 9: Dbms file

Hyperbolic Sine FunctionCommand:

Select sinh(value) from dual;

Tangent FunctionCommand:

Select tan(value) from dual;

Inverse Tangent FunctionCommand:

Select atan(value) from dual;

Page 10: Dbms file

Hyperbolic Tangent FunctionCommand:

Select tanh(value) from dual;

Exponenetial FunctionCommand:

Select exp(value) from dual;

Mod FunctionCommand:

Select mod(num1 , num2) from dual;

Page 11: Dbms file

Power FunctionCommand:

Select power(num1 , num2) from dual;

Natural Log FunctionCommand:

Select ln(value) from dual;

Log FuctionCommand:

Select log(num , base) from dual;

Page 12: Dbms file

Ceiling FunctionCommand:

Select ceil(value) from dual;

Floor FunctionCommand:

Select floor(value) from dual;

Greatest Value FunctionCommand:

Select greatest(num1 , num2) from dual;

Page 13: Dbms file

Least Value FunctionCommand:

Select least(num1 , num2) from dual;

Sign FunctionCommand:

Select sign(num) from dual;

Square root of any valueCommand:

Select sqrt(value) from dual;

Page 14: Dbms file

Date Functions

To determine the system date of a computerCommand:

Select sysdate from dual;

To add months in a dateCommand:

Select add_months(sysdate , monthnum) from dual;

To determine months between two datesCommand:

Select months_between(sysdate , ‘new date’) from dual;

Page 15: Dbms file

To round off the month/year of a dateCommand:

Select round(sysdate, ‘month/year) from dual;

To round off the month/year of a date using truncateCommand:

select trunc(‘date’, ‘month/year’) from dual;

To determine the next day of the dateCommand:

select next_day(‘date’, ‘day’) from dual;

Page 16: Dbms file

CHARACTER FUNCTION

To change the lower case of a string to upper caseCommand:

select upper(‘string’) from dual;

To change the upper case of a string to lower caseCommand:

select lower(‘string’) from dual;

To change the first case of a string to upper caseCommand:

select initcap(‘string’) from dual;

Page 17: Dbms file

To take out the substring from a stringCommand:

select substr(‘string’ start, end) from dual;

To find the position of character in a stringCommand:

select instr(‘string’, ‘character’) from dual;

To find the length of a stringCommand:

select length(‘string’) from dual;

Page 18: Dbms file

To concatenate the two stringsCommand:

select concat(‘string 1’, ‘string 2’) from dual;

To insert symbol on left side in a stringCommand:

select lpad(‘string’,size,’symbol’) from dual;

To insert symbol on right side in a stringCommand:

select rpad(‘string’,size,’symbol’) from dual;

Page 19: Dbms file

To trim the characters from left side in a stringCommand:

select ltrim(‘string’,’characters’) from dual;

To trim the characters from right side in a stringCommand:

select rtrim(‘string’,’characters’) from dual;

To replace the characters from a stringCommand:

select replace(‘string’, ‘characters’, ’replacing characters’) from dual;

Page 20: Dbms file