Oracle and SQL Server reserved keywords - sql-server

I need a list of Oracle Database 10g and SQL Server 2008 reserved key words. My application performs DDL statements, thus I need to validate the entered table-, column names, etc. against the reserved words. I know that I can copy and paste the words from the websites:
Oracle 10g and SQL Server 2008
But I would prefer a SQL command so that the keywords can be loaded dynamically. For oracle there exists the command:
SELECT KEYWORD FROM V$RESERVED_WORDS
ORDER BY KEYWORD ASC
;
It's just strange that this command retrieves 1146 words, but the online list just contains about 456! Are there reasons for? Is there also a command available for SQL Server databases?

By this you can get all keywords for MS SQL Server -
SELECT t.keyword
FROM (
VALUES
('ABSOLUTE'),('ACTION'),('ADA'),('ADD'),
('ADMIN'),('AFTER'),('AGGREGATE'),('ALIAS'),
('ALL'),('ALLOCATE'),('ALTER'),('AND'),
('ANY'),('ARE'),('ARRAY'),('AS'),
('ASC'),('ASENSITIVE'),('ASSERTION'),('ASYMMETRIC'),
('AT'),('ATOMIC'),('AUTHORIZATION'),('AVG'),
('BACKUP'),('BEFORE'),('BEGIN'),('BETWEEN'),
('BINARY'),('BIT'),('BIT_LENGTH'),('BLOB'),
('BOOLEAN'),('BOTH'),('BREADTH'),('BREAK'),
('BROWSE'),('BULK'),('BY'),('CALL'),
('CALLED'),('CARDINALITY'),('CASCADE'),('CASCADED'),
('CASE'),('CAST'),('CATALOG'),('CHAR'),
('CHAR_LENGTH'),('CHARACTER'),('CHARACTER_LENGTH'),
('CHECK'),('CHECKPOINT'),('CLASS'),('CLOB'),('CLOSE'),
('CLUSTERED'),('COALESCE'),('COLLATE'),('COLLATION'),('COLLECT'),('COLUMN'),('COMMIT'),
('COMPLETION'),('COMPUTE'),('CONDITION'),('CONNECT'),
('CONNECTION'),('CONSTRAINT'),('CONSTRAINTS'),('CONSTRUCTOR'),
('CONTAINS'),('CONTAINSTABLE'),('CONTINUE'),('CONVERT'),('CORR'),
('CORRESPONDING'),('COUNT'),('COVAR_POP'),('COVAR_SAMP'),('CREATE'),
('CROSS'),('CUBE'),('CUME_DIST'),('CURRENT'),('CURRENT_CATALOG'),
('CURRENT_DATE'),('CURRENT_DEFAULT_TRANSFORM_GROUP'),('CURRENT_PATH'),('CURRENT_ROLE'),('CURRENT_SCHEMA'),
('CURRENT_TIME'),('CURRENT_TIMESTAMP'),('CURRENT_TRANSFORM_GROUP_FOR_TYPE'),('CURRENT_USER'),('CURSOR'),('CYCLE'),
('DATA'),('DATABASE'),('DATE'),('DAY'),('DBCC'),('DEALLOCATE'),('DEC'),('DECIMAL'),('DECLARE'),
('DEFAULT'),('DEFERRABLE'),('DEFERRED'),('DELETE'),('DENY'),('DEPTH'),('DEREF'),('DESC'),('DESCRIBE'),
('DESCRIPTOR'),('DESTROY'),('DESTRUCTOR'),('DETERMINISTIC'),('DIAGNOSTICS'),('DICTIONARY'),('DISCONNECT'),('DISK'),
('DISTINCT'),('DISTRIBUTED'),('DOMAIN'),('DOUBLE'),('DROP'),('DUMP'),('DYNAMIC'),('EACH'),('ELEMENT'),
('ELSE'),('END'),('END-EXEC'),('EQUALS'),('ERRLVL'),('ESCAPE'),('EVERY'),('EXCEPT'),
('EXCEPTION'),('EXEC'),('EXECUTE'),('EXISTS'),('EXIT'),('EXTERNAL'),
('EXTRACT'),('FALSE'),('FETCH'),('FILE'),('FILLFACTOR'),('FILTER'),('FIRST'),('FLOAT'),('FOR'),
('FOREIGN'),('FORTRAN'),('FOUND'),('FREE'),('FREETEXT'),('FREETEXTTABLE'),('FROM'),('FULL'),('FULLTEXTTABLE'),('FUNCTION'),
('FUSION'),('GENERAL'),('GET'),('GLOBAL'),('GO'),('GOTO'),('GRANT'),('GROUP'),('GROUPING'),('HAVING'),
('HOLD'),('HOLDLOCK'),('HOST'),('HOUR'),('IDENTITY'),('IDENTITY_INSERT'),('IDENTITYCOL'),('IF'),
('IGNORE'),('IMMEDIATE'),('IN'),('INCLUDE'),('INDEX'),('INDICATOR'),('INITIALIZE'),('INITIALLY'),('INNER'),('INOUT'),
('INPUT'),('INSENSITIVE'),('INSERT'),('INT'),('INTEGER'),('INTERSECT'),('INTERSECTION'),
('INTERVAL'),('INTO'),('IS'),('ISOLATION'),('ITERATE'),('JOIN'),('KEY'),('KILL'),('LANGUAGE'),
('LARGE'),('LAST'),('LATERAL'),('LEADING'),('LEFT'),('LESS'),('LEVEL'),('LIKE'),('LIKE_REGEX'),('LIMIT'),('LINENO'),('LN'),
('LOAD'),('LOCAL'),('LOCALTIME'),('LOCALTIMESTAMP'),('LOCATOR'),('LOWER'),
('MAP'),('MATCH'),('MAX'),('MEMBER'),('MERGE'),('METHOD'),('MIN'),('MINUTE'),('MOD'),('MODIFIES'),('MODIFY'),('MODULE'),
('MONTH'),('MULTISET'),('NAMES'),('NATIONAL'),('NATURAL'),('NCHAR'),('NCLOB'),('NEW'),('NEXT'),('NO'),('NOCHECK'),
('NONCLUSTERED'),('NONE'),('NORMALIZE'),('NOT'),('NULL'),('NULLIF'),
('NUMERIC'),('OBJECT'),('OCCURRENCES_REGEX'),('OCTET_LENGTH'),('OF'),('OFF'),('OFFSETS'),('OLD'),('ON'),('ONLY'),('OPEN'),
('OPENDATASOURCE'),('OPENQUERY'),('OPENROWSET'),('OPENXML'),('OPERATION'),('OPTION'),('OR'),
('ORDER'),('ORDINALITY'),('OUT'),('OUTER'),('OUTPUT'),
('OVER'),('OVERLAPS'),('OVERLAY'),('PAD'),('PARAMETER'),
('PARAMETERS'),('PARTIAL'),('PARTITION'),('PASCAL'),('PATH'),
('PERCENT'),('PERCENT_RANK'),('PERCENTILE_CONT'),('PERCENTILE_DISC'),('PIVOT'),('PLAN'),('POSITION'),
('POSITION_REGEX'),('POSTFIX'),('PRECISION'),('PREFIX'),('PREORDER'),('PREPARE'),('PRESERVE'),
('PRIMARY'),('PRINT'),('PRIOR'),
('PRIVILEGES'),('PROC'),('PROCEDURE'),('PUBLIC'),('RAISERROR'),
('RANGE'),('READ'),('READS'),('READTEXT'),
('REAL'),('RECONFIGURE'),('RECURSIVE'),('REF'),('REFERENCES'),('REFERENCING'),('REGR_AVGX'),('REGR_AVGY'),('REGR_COUNT'),
('REGR_INTERCEPT'),('REGR_R2'),('REGR_SLOPE'),('REGR_SXX'),('REGR_SXY'),('REGR_SYY'),('RELATIVE'),
('RELEASE'),('REPLICATION'),('RESTORE'),('RESTRICT'),
('RESULT'),('RETURN'),('RETURNS'),('REVERT'),
('REVOKE'),('RIGHT'),('ROLE'),('ROLLBACK'),('ROLLUP'),('ROUTINE'),
('ROW'),('ROWCOUNT'),('ROWGUIDCOL'),('ROWS'),('RULE'),('SAVE'),('SAVEPOINT'),('SCHEMA'),('SCOPE'),
('SCROLL'),('SEARCH'),('SECOND'),('SECTION'),('SECURITYAUDIT'),('SELECT'),('SENSITIVE'),
('SEQUENCE'),('SESSION'),('SESSION_USER'),
('SET'),('SETS'),('SETUSER'),('SHUTDOWN'),('SIMILAR'),('SIZE'),('SMALLINT'),('SOME'),
('SPACE'),('SPECIFIC'),('SPECIFICTYPE'),('SQL'),('SQLCA'),('SQLCODE'),('SQLERROR'),
('SQLEXCEPTION'),('SQLSTATE'),('SQLWARNING'),('START'),('STATE'),('STATEMENT'),
('STATIC'),('STATISTICS'),('STDDEV_POP'),('STDDEV_SAMP'),('STRUCTURE'),('SUBMULTISET'),
('SUBSTRING'),('SUBSTRING_REGEX'),('SUM'),('SYMMETRIC'),('SYSTEM'),('SYSTEM_USER'),
('TABLE'),('TABLESAMPLE'),('TEMPORARY'),('TERMINATE'),('TEXTSIZE'),('THAN'),('THEN'),('TIME'),
('TIMESTAMP'),('TIMEZONE_HOUR'),('TIMEZONE_MINUTE'),('TO'),('TOP'),
('TRAILING'),('TRAN'),('TRANSACTION'),('TRANSLATE'),('TRANSLATE_REGEX'),('TRANSLATION'),
('TREAT'),('TRIGGER'),('TRIM'),('TRUE'),('TRUNCATE'),('TSEQUAL'),
('UESCAPE'),('UNDER'),('UNION'),('UNIQUE'),('UNKNOWN'),('UNNEST'),('UNPIVOT'),('UPDATE'),('UPDATETEXT'),
('UPPER'),('USAGE'),('USE'),('USER'),('USING'),('VALUE'),
('VALUES'),('VAR_POP'),('VAR_SAMP'),('VARCHAR'),('VARIABLE'),
('VARYING'),('VIEW'),('WAITFOR'),('WHEN'),('WHENEVER'),
('WHERE'),('WHILE'),('WIDTH_BUCKET'),('WINDOW'),('WITH'),('WITHIN'),('WITHOUT'),('WORK'),
('WRITE'),('WRITETEXT'),('XMLAGG'),('XMLATTRIBUTES'),
('XMLBINARY'),('XMLCAST'),('XMLCOMMENT'),('XMLCONCAT'),('XMLDOCUMENT'),
('XMLELEMENT'),('XMLEXISTS'),('XMLFOREST'),('XMLITERATE'),('XMLNAMESPACES'),
('XMLPARSE'),('XMLPI'),('XMLQUERY'),('XMLSERIALIZE'),('XMLTABLE'),
('XMLTEXT'),('XMLVALIDATE'),('YEAR'),('ZONE')
) AS t(keyword)

I can't vouch for its credibility nor completeness, but I have appreciated for years Pete Freitag's 'SQL Reserved Words Checker' as a quick and handy reference (and keeping in mind cross-compatibility issues):
http://www.petefreitag.com/tools/sql_reserved_words_checker/

Related

Bypassing an SQL Error 264 - column name is specified more than once in the SET clause

I've been instaling one of our products on a new test server and it's not working due to an error 264 - the column name 'kod_novy' is specified more than once in the SET clause.
I know where the problem is and reported it to the development for a fix. But we have the same application deployed and it works just fine.
In the code you can see the 'kod_novy' is used twice in the insert. My question is - does anyone know, how did our customer manage to ignore this error and successfully complete the T-SQL? Is that a server setting?
Thanks,
Z
insert into [server].db.dbo.prenos_c_banky (
id_prenos,
kod,
kod_novy,
ext_kod,
iud_job,
kod_banky,
kod_novy,
nazev,
znacka)
select
cast('2B06FB0A-2664-4714-91F6-A6D39BDE5B5F' as UNIQUEIDENTIFIER),
kod,
kod_novy,
ext_kod,
iud_job,
kod_banky,
kod_novy,
nazev,
znacka
from #c_banky

SQL Server Distributed queries with Teradata

I am trying to get distributed queries to run on SQL Server 2012 with a linked server to Teradata.
Connection works fine and query returns quickly if I pass the where clause into the remote SQL using openquery e.g.
select *
from openquery(td, 'select * from lib.purchases where z_PO = ''123456''')
However the below does not run as expected: SQL Server loads the entire table and performs a local filter:
select *
from openquery(td, 'select * from lib.purchases') where z_PO = '123456'
The source table has 100M records.
Obviously index play no role here as query runs just fine on TD side.
What I have tried:
sp_configure 'Ad Hoc Distributed Queries', 1
set Collation Compatible" = True on the linked server properties
Instead of 2, set Collation Name = Latin1_BIN to match (closely?) TD character set (ASCII).
Not sure collation is the issue as I get same result when filtering on numeric fields.
Somehow the so-called query optimizer in SQL Server does not push simple filtering down to the remote server.
Is this the ODBC driver's fault (using 16.10) - a setting, a bug? SQL Server 2012 (v11.0.6248.0) setting I am missing (or path req'd)?
Below is the OLEDB for ODBC properties that I capture in SQL Profiler:
<ProviderInformation>
<Provider>MSDASQL</Provider>
<LinkedServer>td</LinkedServer>
<ProviderCapabilitiesAndSettings>
<Ansi92EntrySupport>0</Ansi92EntrySupport>
<ODBCCoreSupport>1</ODBCCoreSupport>
<ODBCMinimumSupport>1</ODBCMinimumSupport>
<SimpleGrammarSupport>0</SimpleGrammarSupport>
<AnsiLikeSupport>0</AnsiLikeSupport>
<SQLLikeSupport>1</SQLLikeSupport>
<DateLiteralsSupport>0</DateLiteralsSupport>
<GroupBySupport>0</GroupBySupport>
<InnerJoinSupport>0</InnerJoinSupport>
<SubqueriesSupport>0</SubqueriesSupport>
<SimpleUpdatesSupport>0</SimpleUpdatesSupport>
<HistogramsSupport>0</HistogramsSupport>
<ColumnLevelCollationSupport>0</ColumnLevelCollationSupport>
<ConnectionSharingSupport>0</ConnectionSharingSupport>
<MultipleActiveRowsetsSupport>0</MultipleActiveRowsetsSupport>
<MultipleResultsSupport>1</MultipleResultsSupport>
<AllowLimitingRowsReturned>1</AllowLimitingRowsReturned>
<NullConcatenationYieldsNull>0</NullConcatenationYieldsNull>
<StructuredStorageAccessToLargeObjects>1</StructuredStorageAccessToLargeObjects>
<MultipleConcurrentLargeObjectSupport>0</MultipleConcurrentLargeObjectSupport>
<DynamicParametersSupport>1</DynamicParametersSupport>
<NestedQueriesSupport>1</NestedQueriesSupport>
<IndicesAvailableAsAccessPath>0</IndicesAvailableAsAccessPath>
<AllowDataAccessByReference>1</AllowDataAccessByReference>
<RowsetChangesAreVisible>0</RowsetChangesAreVisible>
<RowsetSupportsAppendOnly>0</RowsetSupportsAppendOnly>
<UseLevelZeroOledbInterfacesOnly>0</UseLevelZeroOledbInterfacesOnly>
<RowsetUpdatability>1</RowsetUpdatability>
<AsynchronousRowsetProcessingSupport>0</AsynchronousRowsetProcessingSupport>
<DataSourceUnicodeLocaleId>0</DataSourceUnicodeLocaleId>
<DataSourceUnicodeComparisonStyle>0</DataSourceUnicodeComparisonStyle>
<DataSourceCollationComparisonFlags>0</DataSourceCollationComparisonFlags>
<DataSourceCharacterset></DataSourceCharacterset>
<DataSourceSortOrder></DataSourceSortOrder>
<DataSourceNullCollationOrder>4</DataSourceNullCollationOrder>
<CurrentDbCollationSameAsDefaultRemoteDbCollation>0</CurrentDbCollationSameAsDefaultRemoteDbCollation>
<UnicodeLiteralSupport>0</UnicodeLiteralSupport>
<UnicodeLiteralPrefix></UnicodeLiteralPrefix>
<UnicodeLiteralSuffix></UnicodeLiteralSuffix>
<DateLiteralPrefix></DateLiteralPrefix>
<DateLiteralSuffix></DateLiteralSuffix>
<ObjectNameConstructionFlags>54</ObjectNameConstructionFlags>
<SchemaSeparator>.</SchemaSeparator>
<CatalogSeparator>.</CatalogSeparator>
<QuoteSeparator>"</QuoteSeparator>
<BitRemoting>0</BitRemoting>
<UnicodeLiterals>0</UnicodeLiterals>
<ProviderOledbVersion>131072</ProviderOledbVersion>
<HalloweenProtectionNeeded>1</HalloweenProtectionNeeded>
<RowsetUsableAcrossThreads>0</RowsetUsableAcrossThreads>
<ObjectNameIsSinglePart>0</ObjectNameIsSinglePart>
<Cardinality>-1</Cardinality>
<BookmarkSupport>0</BookmarkSupport>
<BookmarksReusable>0</BookmarksReusable>
<TableFlags>0</TableFlags>
</ProviderCapabilitiesAndSettings>
and here the details of the column in the filter:
DBCOLUMNINFO>
<pwszName>z_PO</pwszName>
<pTypeInfo>0x0000000000000000</pTypeInfo>
<iOrdinal>53</iOrdinal>
<dwFlags>120</dwFlags>
<ulColumnSize>10</ulColumnSize>
<wType>129</wType>
<bPrecision>255</bPrecision>
<bScale>255</bScale>
<DBID>
<eKind>DBKIND_NAME</eKind>
<uName.pwszName>z_PO</uName.pwszName>
</DBID>
</DBCOLUMNINFO>
As a FYI, the context is wrapping the openquery, joined with local data, into a SQL Server view, which is the only thing users would see - from there, they can apply any filter (WHERE) within PowerQuery (XL) or PowerBI. A way to circumvent the lack of DirectQuery support through ODBC.

Is it possible to list all users in a TFS group from SQL Server

I am trying to recover some group membership information from an old TFS 2010 server for which the application tier is no longer available (but the SQL back-end has not yet been deleted). I know there are command line programs to get security information but I am wondering if it is possible to get security information (specifically group membership) given only the database tables/views.
Here's a query I use to list all users and memberships within a TFS Collection.
Select Object1.DisplayName as Name,
Object2.DisplayName as Membership
From ADObjectMemberships Member1,
ADObjects Object1,
ADObjects Object2
Where Object1.ObjectSID = Member1.MemberObjectSID and
Object2.ObjectSID = Member1.ObjectSID
Order By Membership, Name
After poking around and some trial-and-error, I found that the following SQL seems to work
USE MyCollection;
SELECT
--grp.[SamAccountName] 'group_name',
member.SamAccountName 'member_name'
FROM
[ADObjects] grp
JOIN ADObjectMemberships om ON om.ObjectSID = grp.ObjectSID
JOIN ADObjects member ON om.MemberObjectSID = member.ObjectSID
WHERE
grp.SamAccountName = 'MyGroup'

Returning MSSQL data using plperl function in PostgreSQL

I have a PostgreSQL database in use for a complex php web site (And VB.Net/C# management applications) which require access to execute stored procedures on a Microsoft SQL Server 2008 database. The method chosen to perform this interaction is to use plperl functions within the PostgreSQL database to wrap access to the MSSQL stored procedures.
We are using the perl DBI module to handle the data retrieval from MSSQL database.
I am a neophyte when it comes to perl in general and specifically when using it with PostgreSQL. I have created the function shown below to return a set of composite type
CREATE TYPE "public"."permissions_return" AS (
"rolename" TEXT,
"roledescription" TEXT,
"permissionname" TEXT,
"permissiondescription" TEXT
);
The stored proc called from within the function works fine and returns data when run through a slightly different perl script run from the command-line, or directly from the MSSQL Server. I have not been able to figure out how to return data from my function when using:
SELECT * FROM fn_perltest(153);
The result is always an empty set.
CREATE FUNCTION fn_perltest(integer) RETURNS SETOF permissions_return AS $$
use strict;
use DBI;
my $data_source = q/dbi:ODBC:Production/;
my $user = q/afunkyusername/;
my $password = q/afunkierpassword/;
my $dbh = DBI->connect($data_source, $user, $password);
my $sth = $dbh->prepare(q/up_DCORsel_getUserPermissionByUserID $1 ;/);
$sth->execute();
while ( defined ( my $row = $sth->fetchrow_array() )) {
return next ({
rolename => $row->{RoleName},
roledescription => $row->{RoleDescription},
permissionname => $row->{PermissionName},
permissiondescription => $row->{PermissionDescription}
});
}
return;
$$ LANGUAGE 'plperlu'
If this helps, Postgres is running on a Fedora 13 server. Access to MSSQL Server is configured using unixODBC with the freetds driver. Access to the MSSQL server has been tested and works fine using the isql command-line tool and a simple perl script.
Any ideas would be greatly appreciated. I'm concerned I may run out of hair to pull out.
Regards
Shane
This doesn't answer your question directly, but I have used dblink when attempting to have one database query data in another database. It seemed to work well. Obvious plperlu has a lot more power than dblink, but I don't have any experience with it (just perl and postgresql :-)
dblink can be found in postgresql's contrib directory.

PowerBuilder DSN Creation

I am new to PowerBuilder.
I want to retrieve the data from MSAccess tables and update it to corresponding SQL tables. I am not able to create a permanent DSN for MSAccess because I have to select different MSAccess files with same table information. I can create a permanent DSN for SQL server.
Please help me to create DSN dynamically when selecting the MSAccess file and push all the tables data to SQL using PowerBuilder.
Also give the full PowerBuilder code to complete the problem if its possible.
In Access we strongly suggest not using DSNs at all as it is one less thing for someone to have to configure and one less thing for the users to screw up. Using DSN-Less Connections You should see if PowerBuilder has a similar option.
Create the DSN manually in the ODBC administrator
Locate the entry in the registry
Export the registry syntax into a .reg file
Read and edit the .reg file dynamically in PB
Write it back to the registry using PB's RegistrySet ( key, valuename, valuetype, value )
Once you've got your DSN set up, there are many options to push data from one database to the other.
You'll need two transaction objects in PB, each pointing to its own database. Then, you could use a Data Pipeline object to manage the actual data transfer.
You want to do the DSNLess connection referenced by Tony. I show an example of doing it at PBDJ and have a code sample over at Sybase's CodeXchange.
I am using this code, try it!
//// Profile access databases accdb format
SQLCA.DBMS = "OLE DB"
SQLCA.AutoCommit = False
SQLCA.DBParm = "PROVIDER='Microsoft.ACE.OLEDB.12.0',DATASOURCE='C:\databasename.accdb',DelimitIdentifier='No',CommitOnDisconnect='No'"
Connect using SQLCA;
If SQLCA.SQLCode = 0 Then
Open ( w_rsre_frame )
else
MessageBox ("Cannot Connect to Database", SQLCA.SQLErrText )
End If
or
//// Profile access databases mdb format
transaction aTrx
long resu
string database
database = "C:\databasename.mdb"
aTrx = create transaction
aTrx.DBMS = "OLE DB"
aTrx.AutoCommit = True
aTrx.DBParm = "PROVIDER='Microsoft.Jet.OLEDB.4.0',DATASOURCE='"+database+"',PBMaxBlobSize=100000,StaticBind='No',PBNoCatalog='YES'"
connect using aTrx ;
if atrx.sqldbcode = 0 then
messagebox("","Connection success to database")
else
messagebox("Error code: "+string(atrx.sqlcode),atrx.sqlerrtext+ " DB Code Error: "+string(atrx.sqldbcode))
end if
// do stuff...
destroy atrx

Resources