Showing posts with label SQL. Show all posts
Showing posts with label SQL. Show all posts

Monday, June 18, 2012

Dropping table that has many objects dependent on it

Dropping table automatically,
the program throws error:

Exception in thread "Thread-3" java.lang.NullPointerException
Changed the drop table query statement in Java from
stmt.execute(droptable);
          to
stmt.executeUpdate(droptable);

Still it displayed the same error.

While executing the query on pgadmin, it displayed the error:

ERROR: cannot drop table h*** because other objects depend on it
HINT: Use DROP ... CASCADE to drop the dependent objects too.

Too many triggers and views are dependent on the table

Changed the Drop table statement from

DROP TABLE TABLENAME
to
DROP TABLE TABLENAME CASCADE

Program works fine.

Tuesday, November 2, 2010

Execute SQL file using a batch file

My task was to run a batch file for executing a SQLfile (CreateTables.sql) containing queries to create database, some tables and their fields.


I’ve installed MYSQL Server in my PC.


Initially check whether MYSQL environment variables have been set. If not, set the path using,
Right click My Computer --> Properties --> Advanced --> Environment Variables --> System Variables --> Click on the PATH variable --> Click on Edit --> At the end of Variable Value, add the following
C:\Program Files\MySQL\MySQL Server 5.0\bin;
(The bin path of your MYSQL Server)



Initially create a batch file using the following steps.


Step 1: Open a notepad window.
Step 2: Type the following commands.


@echo off
echo please wait........


mysql --user=root --password=admin<CreateTables.sql



mysql --user=YourMYSQLUsername --password= YourMYSQLPassword <Your SQL filename
(In case your SQL file and batch files are in different folder, you have to specify the full path of SQL file.
Eg:- mysql --user=YourMYSQLUsername --password= YourMYSQLPassword <D:\Folder1\Your SQL filename )



Step 3: Save the filename as “filename.bat” (Include the filename within double quotes)
Step 4: Double click the batch file.



While executing the batch file, the following output will be displayed. 








Note: If you are using Windows XP, make sure that the batch file is not in your desktop.