Geeks Talk

Prepare for your Next Interview


Welcome to the Geeks Talk forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload content and access many other special features. Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact contact us.

Sql Questions For You

This is a discussion on Sql Questions For You within the SQL forums, part of the Databases category; 1.> Can We update a View. 2.> How will You establish many to many relationship in sql. 3.>write sql statement for deleting duplicates values in table....

Go Back   Geeks Talk > Databases > SQL
Register Blogs FAQ Tag Cloud Calendar Mark Forums Read
  #1 (permalink)  
Old 10-08-2009
Contributing Member
 
Join Date: May 2008
Location: India
Posts: 67
Thanks: 27
Thanked 5 Times in 5 Posts
aman15490 is on a distinguished road
Thumbs up Sql Questions For You

1.> Can We update a View.
2.> How will You establish many to many relationship in sql.
3.>write sql statement for deleting duplicates values in table.
Reply With Quote
The Following User Says Thank You to aman15490 For This Useful Post:
Sponsored Links
  #2 (permalink)  
Old 10-08-2009
Junior Member
 
Join Date: Sep 2009
Location: India
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
raut.shubhangi1 is on a distinguished road
Re: Sql Questions For You

SQL Statements for deleting duplicate values?
SQL> delete from table_name where rowid not in (select max(rowid ) from table group by
duplicate_values_field_name);
or
SQL> delete duplicate_values_field_name dv from table_name ta where rowid <(select min(rowid) from
table_name tb where ta.dv=tb.dv);
Example.
Table Emp
Empno Ename
101 Scott
102 Jiyo
103 Millor
104 Jiyo
105 Smith
delete ename from emp a where rowid < ( select min(rowid) from emp b where a.ename = b.ename);
The output like,
Empno Ename
101 Scott
102 Millor
103 Jiyo
104 Smith
Reply With Quote
  #3 (permalink)  
Old 10-08-2009
Junior Member
 
Join Date: Sep 2009
Location: India
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
raut.shubhangi1 is on a distinguished road
Re: Sql Questions For You

can we update a view?
we can replace a view.
ie when we create it if we specify replace then if the view exists then it is replaced by other and if not a new view is created.
Reply With Quote
  #4 (permalink)  
Old 10-08-2009
Moderator
 
Join Date: Jun 2007
Location: Bangalore,India
Posts: 1,853
Thanks: 9
Thanked 168 Times in 142 Posts
debasisdas has a spectacular aura aboutdebasisdas has a spectacular aura about
Re: Sql Questions For You

a join view can't be updated if it contains
---------------------------
1.hierarchical query clause start with & connect by
2.group by & order by.
3.model query.
4.set operations.
5.aggragate functions
6.a subquery or a collection expresion in the select list.
7.the distinct operator
8.the rownum pseudo column
9.read only option.

A dml statment on a join view can modify only one base table of the view .to be modifiable,a join view must preserve a key from at least one of its tables.
------ key-preserved table ------------
in a join,a table is called a key-preserve table if its keys are preserved through the join.every key of the table can also be a key of the resultant join resultset.every primary key or unique key value in the base table must also be unique in the result set of the join.

A)key-preservation is a property of the table inside the join view not the table itself independently.a table may be key preseved in one join view and may not be key preserved in another join view.
B)it is not necessary for the key columns of a table to be selected in the join view for the table to be key preserved.
C)if the key columns of a table is selected in the view defination ,it does not make the the table key preserved. D)the key-preserved property of the table in a join view does not depend on the data inside the table.it depends on the schema design and the relationship between the tables.
E)a join view may select data from many tables ,any dml operation can modify data from only one underlying table. F)user can't refer to the columns of a non-key-preserved table in an insert statement.
G)delete operation can be performed on a join view if the join view has one and only one key-preserved table.


Many to many relationship depends on database architecture.


Try this sample sql statement for deleting duplicates values in table.
------------------------------------------------------------------
Code:
Delete from emp e 
where rowid>(select min(rowid) from emp 
where e.empno=empno)

OR

Delete from emp 
where rowid not in(select max(rowid) from emp group  by empno)

NOTE:------This is oracle query.
Reply With Quote
The Following 3 Users Say Thank You to debasisdas For This Useful Post:
  #5 (permalink)  
Old 6 Days Ago
Junior Member
 
Join Date: Sep 2008
Location: NOIDA
Posts: 12
Thanks: 1
Thanked 1 Time in 1 Post
aditi14 is on a distinguished road
Thumbs up Re: Sql Questions For You

you can update a simple view(update v_t1 set sal=200 where sal=50000) but complex view(have join from two or more table) is not updatble

u can delete duplicate row from table vai these commands
1)create table t2 as select distinct * from t1;
2) drop table t1;
3)rename table t2 to t1;
Reply With Quote
Reply

  Geeks Talk > Databases > SQL

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is On
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads

Thread Thread Starter Forum Replies Last Post
my questions.... Abhisek Bhattacharjee Oracle 2 03-08-2009 08:58 PM
jsp questions dhanyasraj JSP 3 10-01-2008 11:19 AM
OS Questions JobHelper Windows 5 05-15-2008 02:10 AM
Bo questions alvi.jayasudha Data Warehousing 1 12-13-2007 04:48 AM
HR questions sakshi_2801 Brainteasers 1 06-20-2007 02:31 AM


All times are GMT -4. The time now is 11:43 PM.


Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.3.1
Copyright © 2009 GeekInterview.com. All Rights Reserved