Dec 102014
 

Solved 51 SQL Queries

1) SQL query to create partition by range on a table

create table product (product_id number, product_name varchar2(30), Manufactured_Date date)

partition by range (Manufactured_Date)

(

partition part1 values less than (TO_DATE('2013-01-01 00:00:00', 'YYYY-MM-DD HH24:MI:SS')),

partition part2 values less than (TO_DATE('2014-01-01 00:00:00', 'YYYY-MM-DD HH24:MI:SS'))

);

2) SQL query to create database link

CREATE DATABASE LINK <DATABASE_LINK_NAME>

CONNECT TO <SCHEMA_NAME>

IDENTIFIED BY <PWD>

USING <DATABASE_NAME>;

3) SQL query to create comments on a table

Comment on table temp is 'This is a Test Table';

[Where “temp” is a table]

4) SQL query to create comments on a table column

Comment on column temp.user_name is 'This is a Test User'

[Where “temp” is a table name and “user_name” is a column]

5) SQL query to create bitmap index on a table

Create bitmap index idx_gender on employee (gender);

[Where “idx_gender” is an Index name]

6) SQL query to create function-based index on a table

create index idx_empname_upper on employee (upper(empname));

[Where “idx_empname_upper” is an Index name]

7) SQL query to disable and enable constraints on a table

Alter table employee disable constraint <constraint_name>;

Alter table employee enable constraint <constraint_name>;

8) SQL query to add foreign key constraint on a table

Alter table employee add constraint emp_mgr_fk foreign key (manager_id) references employee (employee_id);

[Where “emp_mgr_fk” is a constraint name]

9) SQL query to drop constraint from a table

Alter table employee drop constraint <constraint_name>;

10) SQL query to rename table name

Rename employee to employee_new;

[Where”employee” is old table name and “employee_new” is a new table name]

11) SQL query to rename column name

Alter table employee rename column empname to emp_name;

[Where”empname” is old column name and “emp_name” is a new column name]

12) SQL query to make table read only

Alter table employee read only;

Write below query to make table read and write.

Alter table employee read write;

 

 Leave a Reply

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

(required)

(required)