I am porting a database from SQL Server to PostgreSQL. Is there any alternative to sysobjects in PostgreSQL? If so, then what is it and how can be it used?
My view:
create view int_objects_v as
select
io.*, soae."REQ_TYPE_NAME", soae."REQ_TABLE_NAME",
stc1."CODE_DESC" int_type_name, stc2."CODE_DESC" operation_type_name,
s."NAME" target_obj_name
from
int_objects io
left join
req_request_types_v soae on soae."ID" = io."SOURCE_OBJ_ID"
left join
std_type_codes_v stc1 on (stc1."CODE" = io."INT_TYPE"
and stc1."TYPE" = 'intr_type')
left join
std_type_codes_v stc2 on (stc2."CODE" = io."OPERATION_TYPE"
and stc2."TYPE" = 'opr_type')
left join
sysobjects s on (s."ID" = io."TARGET_OBJ_ID")
where
io."ACTIVE_FLAG" = '1';
PostgreSQL supports the SQL-standard information_schema.
So does MSSQL, but it also supports sysobjects which is older equivalent for information_schema.
If you find a way to rewrite your query using information_schema terms, then you're all set.
Also look here INFORMATION_SCHEMA vs sysobjects
Related
Solution specified here, works as follows (I run from server1)
select * from server1.blahdbname.sys.columns c
where c.[object_id] = OBJECT_ID('blahdbname.dbo.blahtablename')
It is fine. Works as intended. But below query doesn't work (changed servername) (returns empty set)
select * from server2.blahdbname.sys.columns c
where c.[object_id] = OBJECT_ID('blahdbname.dbo.blahtablename')
What is the universal way if I want to query different servers too? Above queries generated dynamically, so I want them to work on any server and db
NOTE: blahdbname and blahtablename both exist in server1 and server2. server1 and server2 are linked
This is because you are using the function OBJECT_ID. This runs against the current database, not the remote database.
Instead you should use the system views on the remote server to make this happen.
select c.*
from server1.blahdbname.sys.columns c
join server1.blahdbname.sys.tables t on c.object_id = c.object_id
where t.name = 'blahtablename'
I want to make a dynamic join between sql and as400, of this type:
SELECT * FROM OPENQUERY(AS400_link,'SELECT
AS400.CAMPO1
,AS400.CAMPO2
,AS400.CAMPO3
,AS400.CAMPO4
FROM AS400_FILE AS AS400
INNERT JOIN #TAB_TEMP AS TEMP ON
TEMP.CAMPO1 = AS400.CAMPO1
')
DROP TABLE #TAB_TEMP
if I run it:
OLE DB provider "IBMDASQL" for linked server "AS400_link" returned message "SQL0113: Nome #TAB_TEMP non consentito.
Causa . . . : #TAB_TEMP...
some solution?
Thank you
I think what you're looking for is more like
SELECT * FROM OPENQUERY(AS400_link,'SELECT
AS400.CAMPO1
,AS400.CAMPO2
,AS400.CAMPO3
,AS400.CAMPO4
FROM AS400_FILE') AS AS400
INNER JOIN #TAB_TEMP AS TEMP ON
TEMP.CAMPO1 = AS400.CAMPO1
Don't expect it to perform well.
This query is working in mysql but is not working in microsoft sql server management studio 2008, can someone help me out?
SELECT DISTINCT C.firstname,C.lastname,QC.category_name,QR.cid,QR.catid,QR.rhid
FROM cms_question_report QR,
cms_clients C,
cms_questioncategory QC ,
cms_reporthistory RH
WHERE C.id=QR.cid
AND QR.rhid=RH.id
AND QR.catid='3'
AND QR.catid=QC.id
I am getting the error: Invalid object name cms_question_report
SELECT DISTINCT C.firstname,C.lastname,QC.category_name,QR.cid,QR.catid,QR.rhid
FROM cms_question_report QR
left join cms_clients C
on C.id=QR.cid
left join cms_questioncategory QC
on QR.catid=QC.id
and QR.catid='3'
left join cms_reporthistory RH
on QR.rhid=RH.id
I think this should do
specify Normally it happens when you have specific schema and you don't specify it for example:
Replace dbo. with your schema and/or type your database name
SELECT DISTINCT C.firstname,C.lastname,QC.category_name,QR.cid,QR.catid,QR.rhid
FROM databasename.dbo.cms_question_report QR,
databasename.dbo.cms_clients C,
databasename.dbo.cms_questioncategory QC ,
databasename.dbo.cms_reporthistory RH
WHERE C.id=QR.cid
AND QR.rhid=RH.id
AND QR.catid='3'
AND QR.catid=QC.id
...using SQL Server 2008 R2. I know how to find all objects a user has rights to, but how do I find all accounts that have execute rights on a particular object
Below query observed from How Can we find user have Execute Right on SP will help you get the required information (Not tested .. so minor tweak may be required).
SELECT
s.name AS SchemaName,
o.name AS ObjectName,
dp.name AS PrincipalName,
dperm.type AS PermissionType,
dperm.permission_name AS PermissionName,
dperm.state AS PermissionState,
dperm.state_desc AS PermissionStateDescription
FROM sys.objects o
INNER JOIN sys.schemas s on o.schema_id = s.schema_id
INNER JOIN sys.database_permissions dperm ON o.object_id = dperm.major_id
INNER JOIN sys.database_principals dp
ON dperm.grantee_principal_id = dp.principal_id
WHERE
dperm.class = 1 --object or column
AND
dperm.type = 'EX'
AND
dp.name = 'Specific_username'
AND
o.name = 'specific_object_name'
You did not specify whether you want it through T-SQL or Management Studio. For T-SQL you already have answer, for Management Studio just right-click the object (e.g. table, stored procedure), click Properties, and then select Permissions tab. Don't miss the blue links "View schema permissions", "View database permissions", "View server permissions".
How can i check with SQL query whether Database backup JOB is created or not ?
Thank You
This query will return all jobs that have the command BACKUP DATABASE in them:
SELECT SV.name,
SV.description,
S.step_id
FROM msdb.dbo.sysjobs_view SV
INNER JOIN msdb.dbo.sysjobsteps S ON SV.job_id = S.job_id
WHERE s.command LIKE '%BACKUP DATABASE%'
If you setup the job categories properly to have a category called 'Database Backup' the following would also work:
SELECT SV.name,
SV.description
FROM msdb.dbo.sysjobs_view SV
INNER JOIN msdb.dbo.syscategories SC ON SV.category_id = SC.category_id
WHERE SC.Name = 'Database Backup'