delete values from dataset - asp.net

i have an dataset with 3 tables in it they have a masterchild relationship,
lets say the dataset is like this
department table
deptID departmentname
1 IT
2 CS
3 EC
employee table
empID Empname DeptID
1 kiran 1
2 manu 2
3 kumar 3
4 ajay 3
now i have to delete value deptID =3 from department table
then all the employee who have DeptID ='3' have to be deleted from Employee table
how do we do in dataset , is there any builtin function
thanks
Prince5

You have to define a ForeignKeyConstraint and set the rule to cascade:
ForeignKeyConstraint fk = new ForeignKeyConstraint(dtDepartment.Columns["deptID"], dtEmployee.Columns["DeptID"]);
fk.DeleteRule = Rule.Cascade;
Now when you delete records in the parent it will delete them in the children as well.

You can add a constraint to you dataset and enable cascade deleting
http://msdn.microsoft.com/en-us/library/st1t2c35.aspx

Related

How to assign a 0 for count if the value doesnt exist in the table

I have a table of ratings
|EMPLOYEE|Rating|
1 B
2 B
3 C
4 NULL
5 NULL
6 NULL
and i want to retrieve the count of the grades by each grading like so
Result set
|Rating|Count|
A 0
B 2
C 1
D 0
E 0
I used this query but the grades that isnt in the table will jsut appear as null
select rating,count(rating) from table group by rating
I also used this query which is basically a pivot of the above result set but for some reason it shows 3 rows of repeating data instead of just 1
select (select count(rating) from table where rating = 'E'),(select count(rating) from table where rating = 'D'),(select count(rating) from table where rating = 'C'),(select count(rating) from table where rating = 'B'),(select count(rating) from table where rating = 'A') from table group by rating
If you had a table for the assignable ratings then it would be quite simple (and flexible)
e.g. consider :-
Your existing table.
DROP TABLE IF EXISTS mytable;
CREATE TABLE IF NOT EXISTS mytable (employee TEXT, rating text);
INSERT INTO mytable VALUES (1,'B'),(2,'B'),(3,'C'),(4,null),(5,null),(6,null);
The rating table.
DROP TABLE IF EXISTS rating;
CREATE TABLE IF NOT EXISTS rating (rating);
INSERT INTO rating VALUES('A'),('B'),('C'),('D'),('E');
Then :-
SELECT rating.rating, (SELECT count(*) FROM mytable WHERE rating.rating = mytable.rating) FROM rating;
Results in :-
Flexibility
Add some new ratings e.g. as per :-
INSERT INTO rating VALUES('X'),('Y'),('Z');
And then run:--
SELECT rating.rating, (SELECT count(*) FROM mytable WHERE rating.rating = mytable.rating) FROM rating;
results in :-

How can I do join in hive with array datatype?

I have employee table which have employee id as int, employee name as string and department id as array of integer data type as the columns. Give below are the records for the Employee table.
employee5.empid employee5.empname employee5.deptid
1 Emp1 [2,3,1,4]
2 Emp2 [5,2,3,4]
3 Emp3 [1,4,2,3]
4 Emp4 [5,3,4,1]
5 Emp5 [1,2,3,4]
6 Emp6 [5,3,1,2]
7 Emp7 [3,2,4,5]
8 Emp8 [1,4,2,3]
9 Emp9 [5,2,3,1]
10 Emp10 [2,4,3,5]
I also have the department table which have department id as int, department name as string and department location as string columns. Give below are the records for the department table.
department.deptid department.deptname department.location
1 IT Delhi
2 Support Bangalore
3 HR Pune
4 Finance Mumbai
5 Call Center Mysore
As I am new to the hive, please help me in displaying the employee name and his corresponding department using the hive join.Thanks in advance.
I haven't tested however, this is might work.
First, you need to explode the array into multiple rows and then need the join, I don't think is a direct way to join.
select * from
(select empid, empname, dept_id from employee5 lateral view explode(deptid) d as dept_id) emp
join
department
on
department. deptid = emp.dept_id

SQlite how to display employee and manager names in this table?

I am new to SQLite. I want to display the name of each employee and his/her manager's name. But I am a little confused about how to link the managerID with EmployeeID? Do I need to use subquery?
table: Employee
Columns: EmployeeID [pk], EmployeeName, ManagerID
Like:
EmployeeID EmployeeName ManagerID
1 Alice 2
2 Peter null
3 John 2
4 Mary 1
means Peter is Alice and John's manager and Alice is Mary's manager.
SELECT EmployeeName AS Employee, EmployeeName AS Manager
FROM Employee
WHERE
You need to join the table on itself with a LEFT OUTER join. Since the boss won't have a manager (null), use 'ifnull':
select A.EmployeeName as 'EmployeeName',
ifnull(B.EmployeeName, 'BOSS') as 'ManagerName'
from employee A left outer join employee B
on A.managerId = B.employeeId;

need help to build a query that takes the dynamic column name return by another query as record

I have 2 tables:
Employee_tbl
empid empname empsalary emplocation
----- ------- --------- ------------
1 santhosh 15000 East godavari
2 Srinivas 25000 Westgodavari
3 sandeep 35000 Hyderabad
4 prathap 55000 Hyderabad
5 praveen 45000 West godavari
configuration_tbl
config_id column_name
--------- -----------
1 empid
2 empname
3 empsalary
4 emplocation
When I pass input as config_id it should display the values from that column.
Ex: If I pass config_id then it should display all empname from employee_tbl.
When there is only a limited number of columns I advice you to use a SQL with a case statement. Depending on whether you want to fold numbers into one text field or not, you may need two case columns. Execute immediate is possible but has additional overhead.

Parent Child table record - Building SQL query

Here is my table and data of these tables
Table name: Code
CID Code
1 abc
2 def
3 xyz
Table Name : Details
ID Name CID
1 a 1
2 b 2
Resultant Table:
ID Code Name
1 abc a
2 abc Null
3 def b
4 def Null
5 xyz Null
6 xyz Null
I nned to get all record from the code table and against each code I have to get all the rows from the details table, if some code have value their need value and if not then Null
Thanks
Sounds like you're looking for the cartesian product:
SELECT
c.CID * d.ID AS ID,
c.Code,
CASE
WHEN c.CID = d.CID THEN d.Name
ELSE NULL
END AS Name
FROM Code c
CROSS JOIN Details d
Although cartesian products are quite slow for larger tables... so be sure that this is what you really want.

Resources