Database Administrators
Q&A for database professionals who wish to improve their database skills
Latest Questions
106
votes
9
answers
43390
views
Where are some useful SQL puzzles to teach SQL in a workplace?
I'm looking for beginner and intermediate level SQL puzzles, that I can point trainees at for practice. I'm aware of http://sqlzoo.net/ which is a great resource - is there anything else out there that you could suggest?
I'm looking for beginner and intermediate level SQL puzzles, that I can point trainees at for practice.
I'm aware of http://sqlzoo.net/ which is a great resource - is there anything else out there that you could suggest?
testerab
(477 rep)
Jan 3, 2011, 09:26 PM
• Last activity: Dec 9, 2022, 03:12 PM
0
votes
2
answers
446
views
Why are scalar functions special? A case study of trying to understand database terminology as a beginner
I am trying to learn the basics of databases, but I am finding the terminology especially impenetrable compared to other things I have learned. Most of the database tutorials and documentation I have looked at explain everything in terms of other database terminology. Most examples only show code bu...
I am trying to learn the basics of databases, but I am finding the terminology especially impenetrable compared to other things I have learned. Most of the database tutorials and documentation I have looked at explain everything in terms of other database terminology. Most examples only show code but not actual output, so I am often unclear as to what the expected output is. I am usually even less clear on what the intended use case is.
For example, take the term "scalar function" which I recently come across. It is defined here similarly to other definitions I found.
https://raima.com/database-terminology/ :
> Scalar Function – Either a built-in SQL function or a user-defined
> function that returns a single value computed only from the values of
> any required arguments at the time the function is called.
Why is that special? How is that different from just a function that outputs one value? Why is the fact that the arguments are "required arguments" a noteworthy distinction? Why, in practical terms, would it be important to specify that a scalar function is to be used?
I would appreciate both an answer to this specific question and references to database (preferably Postgres) learning materials that make a point to explain each technical term in the least technical way possible.
Stonecraft
(125 rep)
Jul 27, 2022, 08:52 PM
• Last activity: Jul 27, 2022, 10:16 PM
1
votes
2
answers
58
views
Best way to study a new type of database if you are experienced in another type
Does anyone have a good approach to learning a new type of database when they already are proficient in another one? I have thought about writing notes to myself about how to do various tasks that I am familiar with on the old db and showing the equivalent in the new one. For example, I like to read...
Does anyone have a good approach to learning a new type of database when they already are proficient in another one? I have thought about writing notes to myself about how to do various tasks that I am familiar with on the old db and showing the equivalent in the new one.
For example, I like to read manuals. But should I just read through a manual without taking any notes or should I read a section of a manual that corresponds to something I know on my main db and write a quick document about what I just learned?
If anyone has an approach that worked well for them I would love to hear about it.
Bobby
P.S. I am an Oracle DBA learning MongoDB.
Bobby Durrett
(231 rep)
Oct 22, 2021, 11:49 PM
• Last activity: Oct 24, 2021, 09:49 AM
0
votes
1
answers
89
views
What dataset(s) is Marcus Winand using in his book "SQL Performance Explained"?
I am currently reading [SQL Perfrmance Explained](https://sql-performance-explained.com/) by Marcus Winand. I would like to follow along with the queries and examples he used to explain database tuning. It would greatly allow me to understand by doing things hands on and experiment with my own queri...
I am currently reading [SQL Perfrmance Explained](https://sql-performance-explained.com/) by Marcus Winand. I would like to follow along with the queries and examples he used to explain database tuning. It would greatly allow me to understand by doing things hands on and experiment with my own queries.
I can set up a Docker container with an Oracle database and simply copy over the dataset(s) (perhaps in the form of CSV files?) into tables in the database. I just need the files themselves.
**Question: Anyone know where to find the dataset(s) Marcus Winand used in his book [SQL Perfrmance Explained](https://sql-performance-explained.com/)?**
luminare
(103 rep)
Aug 25, 2021, 02:45 PM
• Last activity: Aug 25, 2021, 02:51 PM
-2
votes
1
answers
43
views
How to read the select statement to understand the result
I am convinced that it is a very basic question, but I still have to ask it, making queries on the Oracle HR schema I notice that the result of these two queries is different: [![enter image description here][1]][1] Expected result: [![enter image description here][2]][2] I would like to know why th...
I am convinced that it is a very basic question, but I still have to ask it, making queries on the Oracle HR schema I notice that the result of these two queries is different:
Expected result:
I would like to know why this happens, when using the parentheses it gives me the result I want, while if I do not use the parentheses it gives me another record (Pat Fay) that does not make sense, how should I read this sentence to understand these outputs, thank you very much .


miguel ramires
(169 rep)
Dec 18, 2020, 03:34 AM
• Last activity: Dec 18, 2020, 04:02 AM
35
votes
5
answers
9434
views
How far should you go with normalization?
I have a decent amount of data in a database. I have well formed tables and good relationships between them with some redundancy in my data. But how far should I go with normalization? Are there performance drawbacks to too much normalization?
I have a decent amount of data in a database. I have well formed tables and good relationships between them with some redundancy in my data. But how far should I go with normalization? Are there performance drawbacks to too much normalization?
Fergus
(453 rep)
Jan 11, 2011, 04:49 AM
• Last activity: Feb 2, 2020, 06:18 PM
2
votes
1
answers
295
views
Understanding aggregate window functions
Consider the following table: ``` sql CREATE TABLE T1 ( keycol INT NOT NULL CONSTRAINT PK_T1 PRIMARY KEY, col1 VARCHAR(10) NOT NULL ); INSERT INTO T1 VALUES (2, 'A'),(3, 'A'), (5, 'B'),(7, 'B'),(11, 'B'), (13, 'C'),(17, 'C'),(19, 'C'),(23, 'C'); ``` Currently, I am looking into window functions and...
Consider the following table:
sql
CREATE TABLE T1
(
keycol INT NOT NULL CONSTRAINT PK_T1 PRIMARY KEY,
col1 VARCHAR(10) NOT NULL
);
INSERT INTO T1 VALUES
(2, 'A'),(3, 'A'),
(5, 'B'),(7, 'B'),(11, 'B'),
(13, 'C'),(17, 'C'),(19, 'C'),(23, 'C');
Currently, I am looking into window functions and am trying out aggregate window functions. Although I feel I understand how the windows are defined with the
and
clauses, I am unsure how the aggregate window functions are being calculated, such as () OVER ()
.
**I am looking to understand the following three queries**.
-- Query 1
SELECT keycol, col1, AVG(keycol) OVER (PARTITION BY col1) AS RowAvg
FROM T1
> > keycol | col1 | RowAvg > -----: | :--- | -----: > 2 | A | 2 > 3 | A | 2 > 5 | B | 7 > 7 | B | 7 > 11 | B | 7 > 13 | C | 18 > 17 | C | 18 > 19 | C | 18 > 23 | C | 18 >
-- Query 2
SELECT keycol, col1, AVG(keycol) OVER (ORDER BY keycol) AS RowAvg
FROM T1
> > keycol | col1 | RowAvg > -----: | :--- | -----: > 2 | A | 2 > 3 | A | 2 > 5 | B | 3 > 7 | B | 4 > 11 | B | 5 > 13 | C | 6 > 17 | C | 8 > 19 | C | 9 > 23 | C | 11 >
-- Query 3
SELECT keycol, col1, AVG(keycol) OVER (PARTITION BY col1 ORDER BY keycol) AS RowAvg
FROM T1
> > keycol | col1 | RowAvg > -----: | :--- | -----: > 2 | A | 2 > 3 | A | 2 > 5 | B | 5 > 7 | B | 6 > 11 | B | 7 > 13 | C | 13 > 17 | C | 15 > 19 | C | 16 > 23 | C | 18 >**Query 1**: I believe RowAvg should be the average of the rows for each col1 level. Are the numbers 2 and 7 the FLOOR of the average or is my understanding incorrect? **Query 2**: I am not too sure what is being done to produce RowAvg here. As no PARTITION or framing is used here, I believe the window should be the entire table, is this correct? Also, how is the RowAvg being found? **Query 3**: Is this finding the (FLOOR) average for each partition however doing this incrementally? That is, for row 1 of the first partition ('A'), we find the average of that row. Then, for row 2 of the first partition, we find the average of the first 2 rows. **General question**: Does introducing
BY
into the aggregate window function perform the aggregate function 'consecutively' such as in queries 1 and 2? It is interesting to see that in query 1,
is performed to each partition as a whole, whereas in queries 1 and 2 the RowAvg's are almost different for each row.
TMilliman
(85 rep)
Dec 27, 2019, 12:59 AM
• Last activity: Dec 27, 2019, 02:08 PM
0
votes
1
answers
39
views
Efficient method of inserting a column into a table based on another table
Consider the following tables ``` CREATE TABLE Main ( id INT PRIMARY KEY, state VARCHAR(255) DEFAULT NULL ) CREATE TABLE ColorTable ( color VARCHAR(255), state VARCHAR(255) ) INSERT INTO Main (id, state) VALUES (1, 'A'), (2, 'B'), (3, 'C'), (4, 'B'), (5, 'C'), (6, 'A'), (7, NULL) INSERT INTO ColorTa...
Consider the following tables
CREATE TABLE Main (
id INT PRIMARY KEY,
state VARCHAR(255) DEFAULT NULL
)
CREATE TABLE ColorTable (
color VARCHAR(255),
state VARCHAR(255)
)
INSERT INTO Main (id, state) VALUES
(1, 'A'),
(2, 'B'),
(3, 'C'),
(4, 'B'),
(5, 'C'),
(6, 'A'),
(7, NULL)
INSERT INTO ColorTable (color, state) VALUES
('Yellow', 'A'),
('Red', 'B'),
('Green', 'C'),
('Black', NULL)
I would like to add a new column 'color' into the table 'Main'. I want this such that the color for each id is based on the state in 'Main', and the corresponding color in 'ColorTable'.
I can achieve this through the following:
ALTER TABLE main
ADD color VARCHAR(255)
UPDATE main
SET main.color = ColorTable.color
FROM main
LEFT JOIN ColorTable ON main.state = ColorTable.state
UPDATE main
SET color = 'Red'
WHERE state IS NULL
I am curious as to alternative methods of doing this–can I achieve the same result using a SELECT INTO or something else?
TMilliman
(85 rep)
Dec 19, 2019, 10:09 AM
• Last activity: Dec 19, 2019, 10:20 AM
0
votes
1
answers
1501
views
Create Table with Int-attribute which can only use values between 6 and 36
Hello I'm learning for my databases examination and in one exercise they asking for creating a table with a attribute which can only use values between 6 and 36. How do I solve it? We used in the course always Oracle databases and not mysql. Here is the original text of the exercise (in german langu...
Hello I'm learning for my databases examination and in one exercise they asking for creating a table with a attribute which can only use values between 6 and 36. How do I solve it?
We used in the course always Oracle databases and not mysql.
Here is the original text of the exercise (in german language):
Erstellen Sie eine Tabelle PROJEKTE. Projekte haben einen Namen, eine
Projektnummer, die Personalnummer eines Professors, der die Rolle des Projektleiters
übernimmt, einen Starttermin und eine Laufzeit (ganze Zahlen zwischen 6 und 36).
Kingalione
(131 rep)
Feb 1, 2014, 08:38 PM
• Last activity: Oct 30, 2018, 08:00 AM
4
votes
2
answers
768
views
Getting to know SQL via the "short questions/simple answers style of learning"
Looking for a incremental SQL course that would likely be similar to the this [Ruby Koan course][1]; which is in fact inspired by the book, "[The Little Lisper][2]", which uses a short questions/simple answers style of learning. Basically the format is short questions are within a well defined conte...
Looking for a incremental SQL course that would likely be similar to the this Ruby Koan course ; which is in fact inspired by the book, "The Little Lisper ", which uses a short questions/simple answers style of learning.
Basically the format is short questions are within a well defined context, with a simple answer, that incrementally building and leveraging the student's knowledge within the subject matter, while keeping the to the short questions/simple answers style of learning.
Also, I just wanted to note that I know there are a number of ways to learn SQL, but I'm looking for an existing implementation of this way. This style provides a fixed-path with stepping stones, and if you do not finish a set of questions, you're not allowed to go on, and even if you were able to find a way to cheat this, it would just make things harder, not easier; meaning it's not just free-form learning with information present small packets.
blunders
(334 rep)
Feb 13, 2012, 02:30 PM
• Last activity: Oct 30, 2018, 07:58 AM
8
votes
2
answers
1481
views
Do agile software development approaches apply to SQL?
I would like to learn if agile software development methods/principles/patterns are valid to SQL programming as well. If yes, where would be a good place to start learning about that? Are there any articles or books targeting agile development in SQL context?
I would like to learn if agile software development methods/principles/patterns are valid to SQL programming as well. If yes, where would be a good place to start learning about that? Are there any articles or books targeting agile development in SQL context?
Κύριε ἐλέησον
(165 rep)
Feb 28, 2012, 10:07 PM
• Last activity: Oct 29, 2018, 09:46 AM
2
votes
1
answers
86
views
When creating a database using an ERD, what do the entities and relationships become (in database terms)?
MIS student, here. Learning about ERDs (entity relationship diagrams). ERDs are supposedly used for the purpose of later constructing a database. My question is this: - What will an entity (and, likewise, an entity's attributes) become upon implementing the database? For instance, will entities turn...
MIS student, here. Learning about ERDs (entity relationship diagrams). ERDs are supposedly used for the purpose of later constructing a database. My question is this:
- What will an entity (and, likewise, an entity's attributes) become upon implementing the database? For instance, will entities turn into rows and attributes into columns?
- In fact, now that I consider it, I'd like to know how one implements associative entities from ERD to database form as well. Is there a difference between what a regular entity and an associative entity represent in terms of database terminology?
chthonicThreat
(21 rep)
Oct 27, 2018, 03:38 AM
• Last activity: Oct 29, 2018, 04:03 AM
3
votes
2
answers
1564
views
Microsoft Certification - 70-764 Administering a SQL Database Infrastructure
Firstly, I apologise if this is not necessarily the best place to post such a question. I am currently preparing for my 70-764 exam. I have purchased the following book: [70-764][1] [1]: https://www.microsoftpressstore.com/store/exam-ref-70-764-administering-a-sql-database-infrastructure-97815093038...
Firstly, I apologise if this is not necessarily the best place to post such a question.
I am currently preparing for my 70-764 exam. I have purchased the following book:
70-764
I have a few questions regarding the book and its resources:
1. Previously, I have purchased other Microsoft Certification books and have normally got a PDF version, along with the printed book. Is this not the case anymore? Am I missing a disk or something?
2. The book has many URLS for supporting resources, however, these dont appear to be valid any longer. For example, early on within the book, there is a URL given for a list of useful links which accompany the book, I cannot find these online at all.
3. Practice tests also used to come with the book, however this does not appear to be the case any longer. Is this by design? Or am I just missing something here?
Many thanks in advance for any assistance.
grouchball
(191 rep)
Jun 24, 2018, 04:02 PM
• Last activity: Jun 25, 2018, 12:33 AM
4
votes
2
answers
5423
views
How long to learn PostgreSQL?
I want to learn PostgreSQL and How to make the learning process efficient, but really don't know how long it would take even after googling my question. I used MySQL before and knew relational database. However, I would like to use PostgreSQL the implement my web back end database management system....
I want to learn PostgreSQL and How to make the learning process efficient, but really don't know how long it would take even after googling my question.
I used MySQL before and knew relational database. However, I would like to use PostgreSQL the implement my web back end database management system. I want sufficient knowledge to do it, design not ugly structure, write not ugly code, like I used MySQL for another web app project before.
I am not asking the specific time, but at least I want a sketch in my mind. How much effort I need to invest? What kind of problem I would have? Any lessons you learned can be shared?
Thank you very much!
ChesterL
(141 rep)
Nov 24, 2014, 01:36 AM
• Last activity: Jun 21, 2018, 04:35 AM
0
votes
1
answers
1208
views
Where can I get best resources to learn sql?
I am very new to the databases just have basic knowledge about it. >I want to learn sql language and dont know where to start. Please help me to start with it. >And what is the difference between sql and PostgreSQL? What are the different languages to maintain databases. > >>Any help will be appreci...
I am very new to the databases just have basic knowledge about it.
>I want to learn sql language and dont know where to start. Please help me to start with it.
>And what is the difference between sql and PostgreSQL? What are the different languages to maintain databases.
>
>>Any help will be appreciated.
kashminder
(101 rep)
Feb 15, 2014, 04:43 PM
• Last activity: May 21, 2018, 10:53 AM
3
votes
2
answers
466
views
SQL Server MCSA Certification
I want to take MCSA: Sql Server 2016 Database Administration certification. I checked this link : https://www.microsoft.com/en-us/learning/mcsa-sql2016-database-administration-certification.aspx It says, I have to attend 70-464 and 70-465 exams. Is there any other precondition? I couldn't find clear...
I want to take MCSA: Sql Server 2016 Database Administration certification.
I checked this link :
https://www.microsoft.com/en-us/learning/mcsa-sql2016-database-administration-certification.aspx
It says, I have to attend 70-464 and 70-465 exams. Is there any other precondition? I couldn't find clear certification path.
PS: I never attend certifications exam before. This will be my first.
Thanks.
Banu Akkus
(389 rep)
Feb 22, 2018, 08:37 AM
• Last activity: Feb 22, 2018, 01:26 PM
1
votes
1
answers
91
views
MCSE: Data Management and Analytics requirements overlap with MCSA: SQL Server 2016 Database Development
I've been reviewing the requirements to get the [MCSE: Data Management and Analytics](https://www.microsoft.com/en-us/learning/mcse-data-management-analytics.aspx) certification, and was thinking of going the path of the [MCSA: SQL 2016 Database Development](https://www.microsoft.com/en-us/learning/...
I've been reviewing the requirements to get the [MCSE: Data Management and Analytics](https://www.microsoft.com/en-us/learning/mcse-data-management-analytics.aspx) certification, and was thinking of going the path of the [MCSA: SQL 2016 Database Development](https://www.microsoft.com/en-us/learning/mcsa-sql2016-database-development-certification.aspx) pre-req. The thing is there's an overlap in the requirements. The MCSA requires passing exam 70-761 and 70-762. To get the MCSE I need to take 1 exam from a list of about 12, 70-762 being one of the options. I'm confused about the requirement overlap of exam 70-762. Once I have the MCSA do I meet the stated requirements for the MCSE. Or do I need to take a 3rd exam from the list to qualify?
Darren
(125 rep)
Jan 31, 2018, 06:09 PM
• Last activity: Feb 3, 2018, 09:46 PM
1
votes
1
answers
790
views
Design feedback on my first database
Couldn't find a newbie forum; hope this is in the right place. In my quest to learn more about databases, analytics, and creating service APIs to work with them, I decided to scrape an [online archive of Jeopardy data][1] and plan to reconstruct the data into a functional db. Pretty sure this has be...
Couldn't find a newbie forum; hope this is in the right place.
In my quest to learn more about databases, analytics, and creating service APIs to work with them, I decided to scrape an online archive of Jeopardy data and plan to reconstruct the data into a functional db. Pretty sure this has been done before, but learning is the primary objective here :)
I'd like to get the data structured so I can run some advanced statistics on it. To do so, I'll need to query things like a player's score at any given point in the game, see who picked which clues and in what order, identify (and grade) players' wagering on daily doubles & Final Jeopardy, etc. If all goes to plan, it would be neat to expose this via public API so others can play with it too.
There's a decent amount of data here, though it's not very big compared to enterprise dbs:
- 6000 distinct games
- ~60 clues per game, so ~360k total unique clues.
- 12000 players, which includes duplicates (ex: Ken1 , Ken2 , Ken3 )
Below is the latest draft of my data model (
,
) based on the data available from j-archive, the general structure of Jeopardy games, and my limited understanding of database design. Appreciate any feedback -- especially on the clue_response table, which is the only table with transactional data.
Data is currently stored in an sqlite3 db. Will probably migrate it to MySQL once I settle on a structure.

brystmar
(11 rep)
Jan 23, 2018, 11:18 PM
• Last activity: Jan 24, 2018, 06:38 PM
2
votes
1
answers
299
views
What are the most relevant similarities between T-SQL and MDX?
I have used T-SQL (CTEs, windowed functions, recursive CTEs, large data, table-valued functions, APPLY, PIVOT, stored procedures, etc.), but have never queried a Microsoft SSAS cube. Are there similar concepts in MDX for the following T-SQL concepts? - PIVOT - UNPIVOT - Windowed functions - Recursiv...
I have used T-SQL (CTEs, windowed functions, recursive CTEs, large data, table-valued functions, APPLY, PIVOT, stored procedures, etc.), but have never queried a Microsoft SSAS cube.
Are there similar concepts in MDX for the following T-SQL concepts?
- PIVOT
- UNPIVOT
- Windowed functions
- Recursive Common Table Expressions
Are there any pitfalls for a T-SQL user using MDX?
I am hoping there are some common analogies between T-SQL and MDX, that will help someone good at T-SQL transition to MDX.
It would also be great if there was a guide for common mistakes that are made when coming from T-SQL into MDX.
Edmund
(733 rep)
Dec 5, 2017, 05:25 PM
• Last activity: Dec 7, 2017, 12:49 PM
0
votes
1
answers
906
views
Oracle Unified Auditing Update Table
I am trying to audit when a user UPDATEs a table in Oracle. The script I am running is below. All of the other auditing works fine, but not the UPDATE policies. I created two policies to try two different methods for catching it. -- statements needed to show commands as run and to make the tables re...
I am trying to audit when a user UPDATEs a table in Oracle. The script I am running is below. All of the other auditing works fine, but not the UPDATE policies. I created two policies to try two different methods for catching it.
-- statements needed to show commands as run and to make the tables readable
SET ECHO ON;
SET LINESIZE 200;
COLUMN event_timestamp FORMAT A30
COLUMN dbusername FORMAT A15
COLUMN action_name FORMAT A20
COLUMN object_schema FORMAT A15
COLUMN object_name FORMAT A20
-- create user with required permissions (a&b)
CREATE USER schemer IDENTIFIED BY power QUOTA UNLIMITED ON users;
GRANT CREATE SESSION, CREATE ANY TABLE, INSERT ANY TABLE TO schemer;
CREATE USER SDEV350User IDENTIFIED BY userpw QUOTA UNLIMITED ON USERS;
GRANT CREATE SESSION, CREATE ANY TABLE, DROP ANY TABLE, CREATE USER, DROP USER, UPDATE ANY TABLE, SELECT ANY TABLE,INSERT ANY TABLE TO SDEV350User;
CONN schemer/power;
CREATE TABLE imwatchingyou (
numberofeyes NUMBER,
CONSTRAINT imwatchingyou_pk PRIMARY KEY (numberofeyes)
);
INSERT INTO schemer.imwatchingyou VALUES (2);
CREATE TABLE fodder_table (
fodder_row NUMBER
);
-- policies to audit each of the five possible privileges (c)
CONN / as sysdba;
-- policy to audit creation of any table by user SDEV350User
CREATE AUDIT POLICY create_table_policy
PRIVILEGES CREATE ANY TABLE
WHEN 'SYS_CONTEXT(''USERENV'', ''SESSION_USER'') = ''SDEV350User'''
EVALUATE PER STATEMENT;
AUDIT POLICY create_table_policy;
-- policy to audit drop of any table by user SDEV350User
CREATE AUDIT POLICY drop_table_policy
PRIVILEGES DROP ANY TABLE
WHEN 'SYS_CONTEXT(''USERENV'', ''SESSION_USER'') = ''SDEV350User'''
EVALUATE PER STATEMENT;
AUDIT POLICY drop_table_policy;
-- policy to audit creation of any user by SDEV350User
CREATE AUDIT POLICY create_user_policy
PRIVILEGES CREATE USER
WHEN 'SYS_CONTEXT(''USERENV'', ''SESSION_USER'') = ''SDEV350User'''
EVALUATE PER STATEMENT;
AUDIT POLICY create_user_policy;
-- policy to audit drop of any user by SDEV350User
CREATE AUDIT POLICY drop_user_policy
PRIVILEGES DROP USER
WHEN 'SYS_CONTEXT(''USERENV'', ''SESSION_USER'') = ''SDEV350User'''
EVALUATE PER STATEMENT;
AUDIT POLICY drop_user_policy;
-- policy to audit update of any table by user SDEV350User
CREATE AUDIT POLICY update_table_policy
PRIVILEGES UPDATE ANY TABLE
WHEN 'SYS_CONTEXT(''USERENV'', ''SESSION_USER'') = ''SDEV350User'''
EVALUATE PER STATEMENT;
AUDIT POLICY update_table_policy;
CREATE AUDIT POLICY update_table_policy_2
ACTIONS DELETE,
INSERT,
UPDATE,
SELECT,
ALL,
SELECT
WHEN 'SYS_CONTEXT(''USERENV'', ''SESSION_USER'') = ''SDEV350User'''
EVALUATE PER STATEMENT;
AUDIT POLICY update_table_policy_2;
-- auditable actions(d)
CONN SDEV350User/userpw;
-- create table audit scenario
CREATE TABLE gonego (
rowgonego NUMBER
);
-- drop table audit scenario
DROP TABLE schemer.fodder_table;
-- create user audit scenario
CREATE USER fodder IDENTIFIED BY dropme;
-- drop user audit scenario
DROP USER fodder CASCADE;
-- update table audit scenario
UPDATE schemer.imwatchingyou
SET numberofeyes = 4;
COMMIT;
-- output of the audit trail showing that each action was audited (d)
CONN / as sysdba;
EXEC DBMS_AUDIT_MGMT.flush_unified_audit_trail;
SELECT
event_timestamp,
dbusername,
action_name,
object_schema,
object_name
FROM unified_audit_trail
WHERE dbusername = 'SDEV350USER'
ORDER BY event_timestamp;
HERE IS THE OUTPUT TO SPOOL WHEN RUNNING THE SCRIPT:
> SQL> @hw4-2 SQL> -- statements needed to show commands as run and to
> make the tables readable SQL> SET ECHO ON; SQL> SET LINESIZE 200; SQL>
> COLUMN event_timestamp FORMAT A30 SQL> COLUMN dbusername FORMAT A15
> SQL> COLUMN action_name FORMAT A20 SQL> COLUMN object_schema FORMAT
> A15 SQL> COLUMN object_name FORMAT A20 SQL> SQL> -- create user with
> required permissions (a&b) SQL> CREATE USER schemer IDENTIFIED BY
> power QUOTA UNLIMITED ON users;
>
> User created.
>
> SQL> GRANT CREATE SESSION, CREATE ANY TABLE, INSERT ANY TABLE TO
> schemer;
>
> Grant succeeded.
>
> SQL> CREATE USER SDEV350User IDENTIFIED BY userpw QUOTA UNLIMITED ON
> USERS;
>
> User created.
>
> SQL> GRANT CREATE SESSION, CREATE ANY TABLE, DROP ANY TABLE, CREATE
> USER, DROP USER, UPDATE ANY TABLE, SELECT ANY TABLE,INSERT ANY TABLE
> TO SDEV350User;
>
> Grant succeeded.
>
> SQL> SQL> CONN schemer/power; Connected. SQL> CREATE TABLE
> imwatchingyou ( 2 numberofeyes NUMBER, 3 CONSTRAINT
> imwatchingyou_pk PRIMARY KEY (numberofeyes) 4 );
>
> Table created.
>
> SQL> INSERT INTO schemer.imwatchingyou VALUES (2);
>
> 1 row created.
>
> SQL> CREATE TABLE fodder_table ( 2 fodder_row NUMBER 3 );
>
> Table created.
>
> SQL> SQL> -- policies to audit each of the five possible privileges
> (c) SQL> CONN / as sysdba; Connected. SQL> -- policy to audit creation
> of any table by user SDEV350User SQL> CREATE AUDIT POLICY
> create_table_policy 2 PRIVILEGES CREATE ANY TABLE 3 WHEN
> 'SYS_CONTEXT(''USERENV'', ''SESSION_USER'') = ''SDEV350User''' 4
> EVALUATE PER STATEMENT;
>
> Audit policy created.
>
> SQL> AUDIT POLICY create_table_policy;
>
> Audit succeeded.
>
> SQL> SQL> -- policy to audit drop of any table by user SDEV350User
> SQL> CREATE AUDIT POLICY drop_table_policy 2 PRIVILEGES DROP ANY
> TABLE 3 WHEN 'SYS_CONTEXT(''USERENV'', ''SESSION_USER'') =
> ''SDEV350User''' 4 EVALUATE PER STATEMENT;
>
> Audit policy created.
>
> SQL> AUDIT POLICY drop_table_policy;
>
> Audit succeeded.
>
> SQL> SQL> -- policy to audit creation of any user by SDEV350User SQL>
> CREATE AUDIT POLICY create_user_policy 2 PRIVILEGES CREATE USER
> 3 WHEN 'SYS_CONTEXT(''USERENV'', ''SESSION_USER'') =
> ''SDEV350User''' 4 EVALUATE PER STATEMENT;
>
> Audit policy created.
>
> SQL> AUDIT POLICY create_user_policy;
>
> Audit succeeded.
>
> SQL> SQL> -- policy to audit drop of any user by SDEV350User SQL>
> CREATE AUDIT POLICY drop_user_policy 2 PRIVILEGES DROP USER 3
> WHEN 'SYS_CONTEXT(''USERENV'', ''SESSION_USER'') = ''SDEV350User'''
> 4 EVALUATE PER STATEMENT;
>
> Audit policy created.
>
> SQL> AUDIT POLICY drop_user_policy;
>
> Audit succeeded.
>
> SQL> SQL> -- policy to audit update of any table by user SDEV350User
> SQL> CREATE AUDIT POLICY update_table_policy 2 PRIVILEGES UPDATE
> ANY TABLE 3 WHEN 'SYS_CONTEXT(''USERENV'', ''SESSION_USER'') =
> ''SDEV350User''' 4 EVALUATE PER STATEMENT;
>
> Audit policy created.
>
> SQL> AUDIT POLICY update_table_policy;
>
> Audit succeeded.
>
> SQL> SQL> CREATE AUDIT POLICY update_table_policy_2 2 ACTIONS
> DELETE, 3 INSERT, 4 UPDATE, 5 SELECT,
> 6 ALL, 7 SELECT 8 WHEN
> 'SYS_CONTEXT(''USERENV'', ''SESSION_USER'') = ''SDEV350User''' 9
> EVALUATE PER STATEMENT;
>
> Audit policy created.
>
> SQL> AUDIT POLICY update_table_policy_2;
>
> Audit succeeded.
>
> SQL> SQL> -- auditable actions(d) SQL> CONN SDEV350User/userpw;
> Connected. SQL> -- create table audit scenario SQL> CREATE TABLE
> gonego ( 2 rowgonego NUMBER 3 );
>
> Table created.
>
> SQL> SQL> -- drop table audit scenario SQL> DROP TABLE
> schemer.fodder_table;
>
> Table dropped.
>
> SQL> SQL> -- create user audit scenario SQL> CREATE USER fodder
> IDENTIFIED BY dropme;
>
> User created.
>
> SQL> SQL> -- drop user audit scenario SQL> DROP USER fodder CASCADE;
>
> User dropped.
>
> SQL> SQL> -- update table audit scenario SQL> UPDATE
> schemer.imwatchingyou 2 SET numberofeyes = 4;
>
> 1 row updated.
>
> SQL> SQL> COMMIT;
>
> Commit complete.
>
> SQL> SQL> -- output of the audit trail showing that each action was
> audited (d) SQL> CONN / as sysdba; Connected. SQL> EXEC
> DBMS_AUDIT_MGMT.flush_unified_audit_trail;
>
> PL/SQL procedure successfully completed.
>
> SQL> SELECT 2 event_timestamp, 3 dbusername, 4
> action_name, 5 object_schema, 6 object_name 7 FROM
> unified_audit_trail 8 WHERE dbusername = 'SDEV350USER' 9 ORDER
> BY event_timestamp;
>
> EVENT_TIMESTAMP DBUSERNAME ACTION_NAME
> OBJECT_SCHEMA OBJECT_NAME
>
> ------------------------------ --------------- -------------------- --------------- -------------------- 15-OCT-17 10.22.05.615000 AM SDEV350USER CREATE TABLE
> SDEV350USER GONEGO
> 15-OCT-17 10.22.05.662000 AM SDEV350USER DROP TABLE
> SCHEMER FODDER_TABLE
> 15-OCT-17 10.22.05.693000 AM SDEV350USER CREATE USER
> FODDER
> 15-OCT-17 10.22.05.787000 AM SDEV350USER DROP USER
> FODDER
>
>
> SQL> @scratch SQL> CONN / as sysdba; Connected. SQL> SQL> SELECT 2
> event_timestamp, 3 dbusername, 4 action_name, 5
> object_schema, 6 object_name 7 FROM unified_audit_trail 8
> WHERE object_schema = 'SCHEMER' 9 ORDER BY event_timestamp;
>
> EVENT_TIMESTAMP DBUSERNAME ACTION_NAME
> OBJECT_SCHEMA OBJECT_NAME
>
> ------------------------------ --------------- -------------------- --------------- -------------------- 15-OCT-17 10.22.05.256000 AM SCHEMER CREATE TABLE
> SCHEMER IMWATCHINGYOU
> 15-OCT-17 10.22.05.287000 AM SCHEMER CREATE TABLE
> SCHEMER FODDER_TABLE
> 15-OCT-17 10.22.05.662000 AM SDEV350USER DROP TABLE
> SCHEMER FODDER_TABLE
>
>
> SQL> SQL> SELECT 2 event_timestamp, 3 dbusername, 4
> action_name, 5 object_schema, 6 object_name 7 FROM
> unified_audit_trail 8 WHERE dbusername = 'SDEV350USER' 9 ORDER
> BY event_timestamp;
>
> EVENT_TIMESTAMP DBUSERNAME ACTION_NAME
> OBJECT_SCHEMA OBJECT_NAME
>
> ------------------------------ --------------- -------------------- --------------- -------------------- 15-OCT-17 10.22.05.615000 AM SDEV350USER CREATE TABLE
> SDEV350USER GONEGO
> 15-OCT-17 10.22.05.662000 AM SDEV350USER DROP TABLE
> SCHEMER FODDER_TABLE
> 15-OCT-17 10.22.05.693000 AM SDEV350USER CREATE USER
> FODDER
> 15-OCT-17 10.22.05.787000 AM SDEV350USER DROP USER
> FODDER
>
>
> SQL> SQL> SELECT 2 event_timestamp, 3 dbusername, 4
> action_name, 5 object_schema, 6 object_name 7 FROM
> unified_audit_trail 8 ORDER BY event_timestamp;
>
> EVENT_TIMESTAMP DBUSERNAME ACTION_NAME
> OBJECT_SCHEMA OBJECT_NAME
>
> ------------------------------ --------------- -------------------- --------------- -------------------- 15-OCT-17 10.21.40.319000 AM SYS EXECUTE
> SYS DBMS_AUDIT_MGMT
> 15-OCT-17 10.22.05.256000 AM SCHEMER CREATE TABLE
> SCHEMER IMWATCHINGYOU
> 15-OCT-17 10.22.05.287000 AM SCHEMER CREATE TABLE
> SCHEMER FODDER_TABLE
> 15-OCT-17 10.22.05.335000 AM SYS CREATE AUDIT POLICY
> SYS CREATE_TABLE_POLICY
> 15-OCT-17 10.22.05.350000 AM SYS AUDIT
> SYS CREATE_TABLE_POLICY
> 15-OCT-17 10.22.05.365000 AM SYS CREATE AUDIT POLICY
> SYS DROP_TABLE_POLICY
> 15-OCT-17 10.22.05.381000 AM SYS AUDIT
> SYS DROP_TABLE_POLICY
> 15-OCT-17 10.22.05.397000 AM SYS CREATE AUDIT POLICY
> SYS CREATE_USER_POLICY
> 15-OCT-17 10.22.05.412000 AM SYS AUDIT
> SYS CREATE_USER_POLICY
> 15-OCT-17 10.22.05.428000 AM SYS CREATE AUDIT POLICY
> SYS DROP_USER_POLICY
> 15-OCT-17 10.22.05.443000 AM SYS AUDIT
> SYS DROP_USER_POLICY
>
>
> EVENT_TIMESTAMP DBUSERNAME ACTION_NAME
> OBJECT_SCHEMA OBJECT_NAME
>
> ------------------------------ --------------- -------------------- --------------- -------------------- 15-OCT-17 10.22.05.475000 AM SYS CREATE AUDIT POLICY
> SYS UPDATE_TABLE_POLICY
> 15-OCT-17 10.22.05.490000 AM SYS AUDIT
> SYS UPDATE_TABLE_POLICY
> 15-OCT-17 10.22.05.522000 AM SYS CREATE AUDIT POLICY
> SYS UPDATE_TABLE_POLICY_
>
> 2
>
> 15-OCT-17 10.22.05.538000 AM SYS AUDIT
> SYS UPDATE_TABLE_POLICY_
>
> 2
>
> 15-OCT-17 10.22.05.615000 AM SDEV350USER CREATE TABLE
> SDEV350USER GONEGO
> 15-OCT-17 10.22.05.662000 AM SDEV350USER DROP TABLE
> SCHEMER FODDER_TABLE
> 15-OCT-17 10.22.05.693000 AM SDEV350USER CREATE USER
> FODDER
>
>
> EVENT_TIMESTAMP DBUSERNAME ACTION_NAME
> OBJECT_SCHEMA OBJECT_NAME
>
> ------------------------------ --------------- -------------------- --------------- -------------------- 15-OCT-17 10.22.05.787000 AM SDEV350USER DROP USER
> FODDER
> 15-OCT-17 10.22.05.850000 AM SYS EXECUTE
> SYS DBMS_AUDIT_MGMT
>
>
> 20 rows selected.
>
> SQL> spool out
xygenyx
(3 rep)
Oct 15, 2017, 05:27 PM
• Last activity: Oct 15, 2017, 05:46 PM
Showing page 1 of 20 total questions