pg_restore sql file code example

Example 1: mysql import sql file

mysql -u username -p database_name < file.sql

Example 2: restore postgres database from sql file

psql -d database_name -f backup.sql

Example 3: sql server rename mdf file

USE [master];
GO

ALTER DATABASE QuestelServicesDirectValidation_ORIG SET SINGLE_USER WITH ROLLBACK IMMEDIATE
GO

ALTER DATABASE QuestelServicesDirectValidation_ORIG SET OFFLINE
GO

ALTER DATABASE QuestelServicesDirectValidation_ORIG MODIFY FILE (Name='QuestelServicesDirectValidation_ORIG', FILENAME='C:\Program Files\Microsoft SQL Server\MSSQL13.MSSQLSERVER\MSSQL\DATA\QuestelServicesDirectValidation_ORIG.mdf')
GO

ALTER DATABASE QuestelServicesDirectValidation_ORIG MODIFY FILE (Name='QuestelServicesDirectValidation_ORIG_log', FILENAME='C:\Program Files\Microsoft SQL Server\MSSQL13.MSSQLSERVER\MSSQL\DATA\QuestelServicesDirectValidation_ORIG_log.ldf')
GO

ALTER DATABASE QuestelServicesDirectValidation_ORIG SET ONLINE
GO

ALTER DATABASE QuestelServicesDirectValidation_ORIG SET MULTI_USER
GO

Tags:

Sql Example