rdms

Oracle: Update from within procedure not working

穿精又带淫゛_ 提交于 2021-01-29 10:20:56
问题 In my Oracle PL/SQL procedure I am trying to update a row like this: UPDATE personal p SET p.surname = surname, p.name = name, p."alter" = alter, p.sex = sex, p.jobcode = jobcode, p.year_wage = month_wage * 12 WHERE p.personalnr = personalnr; COMMIT; I have added these two statements right after the commit to confirm the code is reached and executed with the right arguments (e.g. here I want to change the name): DBMS_OUTPUT.put_line('updated ' || name); DBMS_OUTPUT.put_line('personalnr ' ||

How to display all columns and its data type in a table via SQL query

假装没事ソ 提交于 2020-02-06 15:44:45
问题 I am trying to print the column names from a table called 'meta' and I need also its data types. I tried this query SELECT meta FROM INFORMATION_SCHEMA.TABLES; but it throws an error saying no information schema available. Could you please help me, I am a beginner in SQL. Edit: select tables.name from tables join schemas on tables.schema_id=schemas.id where schemas.name=’sprl_db’ ; This query gives me all the tables in database 'sprl_db' 回答1: You can use the monetdb catalog: select c.name, c

How do I get around this relational database design smell?

自古美人都是妖i 提交于 2020-01-30 09:20:09
问题 I have a really simple mediaTypes table which contains the following columns: id string name string Each mediaType record can have many "placements", which could easily be designed as follows: Placements id string mediaTypeId string (links to mediaTypes.id) name string detail_col_1 detail_col_2 ...etc However depending on the media type, a placement can contain different details, so if I designed the schema this way I may end up with a lot of nullable columns. To get around this, I could have

How do I get around this relational database design smell?

心已入冬 提交于 2020-01-30 09:20:06
问题 I have a really simple mediaTypes table which contains the following columns: id string name string Each mediaType record can have many "placements", which could easily be designed as follows: Placements id string mediaTypeId string (links to mediaTypes.id) name string detail_col_1 detail_col_2 ...etc However depending on the media type, a placement can contain different details, so if I designed the schema this way I may end up with a lot of nullable columns. To get around this, I could have

SQL one to one relationship vs. single table

耗尽温柔 提交于 2019-12-18 11:51:58
问题 Consider a data structure such as the below where the user has a small number of fixed settings. User [Id] INT IDENTITY NOT NULL, [Name] NVARCHAR(MAX) NOT NULL, [Email] VNARCHAR(2034) NOT NULL UserSettings [SettingA], [SettingB], [SettingC] Is it considered correct to move the user's settings into a separate table, thereby creating a one-to-one relationship with the users table? Does this offer any real advantage over storing it in the same row as the user (the obvious disadvantage being

how to solve the issue with group by and aggregate function in postgresql

拟墨画扇 提交于 2019-12-10 18:19:24
问题 I am trying to write a query for dividing the two SQL statements but it shows me ERROR: column "temp.missed" must appear in the GROUP BY clause or be used in an aggregate function SQL state: 42803 although when I do group by temp.missed, it seems to be working but shows wrong results because of multiple group by. I have following tables in PostgreSQL create table test.appointments ( appointment_id serial , patient_id integer references test.patients(id) , doctor_id integer references test

Postgres update with an inner join across 2 tables?

江枫思渺然 提交于 2019-12-05 19:02:44
问题 I have 3 tables in my local Postgres database: [myschema].[animals] -------------------- animal_id animal_attrib_type_id (foreign key to [myschema].[animal_attrib_types]) animal_attrib_value_id (foreign key to [myschema].[animal_attrib_values]) [myschema].[animal_attrib_types] -------------------------------- animal_attrib_type_id animal_attrib_type_name [myschema].[animal_attrib_values] -------------------------------- animal_attrib_value_id animal_attrib_value_name At runtime I will know

Does the foreign keys automatically get updated as primary table is updated?

☆樱花仙子☆ 提交于 2019-12-04 13:30:04
问题 Above is my simple database design, just wanted to gain information about how things happen as I'm really new at database. Following are my questions: as I update wall_id in walls table, does the wall_id in wall_categories table also get updated? as the wall_id in wall_categories table references to wall_id in walls table. same with desktop_id in walls table since it is a foreign key referencing to desktop_id in desktop_wall table, so when I update desktop_id in walls table does the desktop

Postgres update with an inner join across 2 tables?

若如初见. 提交于 2019-12-04 02:39:24
I have 3 tables in my local Postgres database: [myschema].[animals] -------------------- animal_id animal_attrib_type_id (foreign key to [myschema].[animal_attrib_types]) animal_attrib_value_id (foreign key to [myschema].[animal_attrib_values]) [myschema].[animal_attrib_types] -------------------------------- animal_attrib_type_id animal_attrib_type_name [myschema].[animal_attrib_values] -------------------------------- animal_attrib_value_id animal_attrib_value_name At runtime I will know the animal_id . I need to run SQL to update the animal_attribute_value_name associated with this item, so

How to retrieve all recursive children of parent row in Oracle SQL?

安稳与你 提交于 2019-12-03 04:28:43
问题 I've got a recursive query that's really stretching the limits of this Java monkey's SQL knowledge. Now that it's finally 1:30 in the AM, it's probably time to start looking for some help. This is one of the few times Google has failed me. The table is as follows: Parent_ID CHILD_ID QTY 25 26 1 25 27 2 26 28 1 26 29 1 26 30 2 27 31 1 27 32 1 27 33 2 I'm trying to get the following result, where the parent has every child listed below them. Note that the qty's cascade as well. BASE PARENT_ID