How to create trigger to insert a value in a column same as value of another column of same table of a newly inserted row in the table. Suppose I have table like below I want columnB value to be inserted into ColumnA as soon as row gets inserted into table or columnB value gets updated . But it should
Sql server – recursive delete
I’m trying to delete user’s data and all it’s related data that is located in different tables. All the tables have Foreign Keys but without cascade delete. I investigated some options: Enable cascade delete on all FK, delete and remove the cascade delete. Delete from bottom UP, loop up for …
A query with 3 tables in django
I have 3 classes like this: My question is: How can I make a query to get the devices used by the person “name”? Which needs to pass through the uses class. Answer Life will be easier if you use ManyToManyField, i.e. add this field to the Person model: Then, to get the list, you just need to get t…
sql to combine two unrelated tables into one
I have tables table1 and table2 I want to combine the two tables, which have no common field into one table looking like: table 3 ie, it is like putting the two tables side by side. I’m stuck! Please help! Answer Get a row number for each row in each table, then do a full join using those row numbers:
Database structure for “customer” table having many orders per customer and many items per order
I am trying to create a database where each customer has several orders(new orders daily) and each order has several items. I had planned creating a table of customers and creating a table per order …
Avoid division by zero in PostgreSQL
I’d like to perform division in a SELECT clause. When I join some tables and use aggregate function I often have either null or zero values as the dividers. As for now I only come up with this method …
How to find a specific Foreign Key of a table through T-SQL?
i want to bring ONE foreign key from several ones in a table. in the GUI interface in sql server if we expand the table options we can see a folder called “Keys”, in this folder there is one primary …
What is type 1,2,3 or 4 of a JDBC Driver?
To connect to a database using Java, most of us use JDBC API. We normally include driver like ojdbc14 (Intended for Java 1.4) in class path, and in program we use Class.forName to use it. Unlike …
SQL auto_increment behaviour
My first question is: Can I manually input ID into an auto_increment column of a table? For example: I have 10 records with ID from 1 to 10. Can I manually input the 11 record with the ID of 3 (yes, it’s a duplication!) My second question is: I assume that it’s possible to manually input ID number…
How to find out 2nd highest salary of employees?
Created table named geosalary with columns name, id, and salary: name id salary patrik 2 1000 frank 2 2000 chinmon 3 1300 paddy 3 1700 I tried this below code to find 2nd …