And here comes something I was missing for years.
It appears that it's possible to execute additional SQLs during the Hibernates create/create-drop. It's very useful for the unit testing.
In short: Hibernate will run "import.sql" file from the classpath.
I found it here.
Showing posts with label sql. Show all posts
Showing posts with label sql. Show all posts
Thursday, March 17, 2011
Monday, March 14, 2011
Oracle: How to find last query executed
One more sql script to remember - How to find the last query executed:
Or may be in a bit more useful way:
And even more useful, show only queries that contain MY_TABLE:
Update: Pay attention that the solution is not quite correct if you use the prepared statements. For prepared statements there will be one row added to the table per statement's parsing. So if you reused the same statement (which is a good practice from performance point of view), you won't get a new record in a table.
2. Oracle PL/SQL Programming: Covers Versions Through Oracle Database 11g
3. Oracle SQL By Example (4th Edition)
select sql_text from v$sql where first_load_time=(select max(first_load_time) from v$sql)
Or may be in a bit more useful way:
select * from v$sql order by first_load_time desc
And even more useful, show only queries that contain MY_TABLE:
select * from v$sql where sql_text like '%MY_TABLE%' order by first_load_time desc
Update: Pay attention that the solution is not quite correct if you use the prepared statements. For prepared statements there will be one row added to the table per statement's parsing. So if you reused the same statement (which is a good practice from performance point of view), you won't get a new record in a table.
Recommended Reading
1. Oracle Essentials: Oracle Database 11g2. Oracle PL/SQL Programming: Covers Versions Through Oracle Database 11g
3. Oracle SQL By Example (4th Edition)
Thursday, February 24, 2011
DB Creation Scripts
Two scripts to remember:
MS-SQL Create Database
CREATE DATABASE ${dbName}
GO
DECLARE @size int
SELECT @size = size*8
FROM ${dbName}..sysfiles WHERE name = N'${dbName}'
IF @size < 5000
BEGIN
ALTER DATABASE [${dbName}] MODIFY FILE(NAME=N'${dbName}', SIZE=5MB)
END
ALTER DATABASE [${dbName}] MODIFY FILE(NAME=N'${dbName}', FILEGROWTH=5MB)
SELECT @size = size*8
FROM ${dbName}..sysfiles WHERE name = N'${dbName}_log'
IF @size < 10000
BEGIN
ALTER DATABASE [${dbName}] MODIFY FILE(NAME=N'${dbName}_log', SIZE=10MB)
END
ALTER DATABASE [${dbName}] MODIFY FILE(NAME=N'${dbName}_log', FILEGROWTH=50MB)
ALTER DATABASE [${dbName}] ADD FILEGROUP userdata001
DECLARE @FilePath nvarchar(250)
SELECT @FilePath = LEFT(filename, LEN(filename) - CHARINDEX(N'\', REVERSE(filename))) FROM master.dbo.sysdatabases WHERE name = N'${dbName}'
SET @FilePath = @FilePath+ '\${dbName}_data001.ndf'
EXEC ('ALTER DATABASE [${dbName}] ADD FILE (NAME = N''${dbName}_data001'',FILENAME = '''+@FilePath+''',SIZE = 200MB,FILEGROWTH = 50MB) TO FILEGROUP userdata001')
ALTER DATABASE [${dbName}] MODIFY FILEGROUP userdata001 DEFAULT
GO
Oracle - Create User
CREATE USER TEST_USER IDENTIFIED BY TEST_USER DEFAULT TABLESPACE USERS TEMPORARY TABLESPACE TEMP; GRANT "CONNECT" TO TEST_USER; GRANT CREATE SEQUENCE TO TEST_USER; GRANT CREATE TABLE TO TEST_USER; GRANT CREATE TRIGGER TO TEST_USER; GRANT UNLIMITED TABLESPACE TO TEST_USER; GRANT CREATE VIEW TO TEST_USER; GRANT CREATE PROCEDURE TO TEST_USER; ALTER USER TEST_USER DEFAULT ROLE ALL;
Subscribe to:
Posts (Atom)