MSAccess linked tables SQL Server "is not a valid name" error - sql-server

I have a third-party database that i want to link to but many table names are illegal - so i'm looking for a workaround, possibly including just keeping a duplicate database with acceptable (legal) naming structure,
that anybody might have tried.
many thanks

Within a SQL database you can CREATE SYNONYM to alias an object/table name to something usable within Access. Create synonms for all of the tables and then use those as your linked table names.

Related

Structure of T-SQL tables

I am switching from MySQL to SQL Server for a new job and I have encountered something I don't quite understand as I haven't encountered something like this before.
I am using the WideWorldImporters Microsoft Sample DB for reference.
Looking at the table structures I can see that it is SCHEMA_NAME.X.TABLE_NAME
Example
[WideWorldImporters].[Application].[Cities]
In MySQL this would just be schema.tablename
Example
[WideWorldImporters].[Cities]
What is this middle part (the [Application] part in the example) exactly? I can't seem to find anything about it but that's likely because I don't know what it is to look for.
It's obviously important as a select query won't work if it's removed. Can anyone explain or even name this so I can research it?
Microsoft uses a three-part naming pattern of Database_Name.Schema_Name.Table_Name that differs from the MySQL convention. In general terms, a MySQL "schema" is roughly equivalent to a SQL Server "database."
In practice, one should avoid explicitly referencing the database name unless specifically needed.
Microsoft documentation: https://learn.microsoft.com/en-us/sql/t-sql/language-elements/transact-sql-syntax-conventions-transact-sql?view=sql-server-ver15#multipart-names
I would like to add some extra details on paneerakbari Accepted Answer
First: About SQL Server according to Microsoft Doc Transact-SQL has different formats to define Object name (Table name), Here are supported formats
Object reference format
Description
server.database.schema.object
Four-part name
server.database..object
Schema name is omitted.
server..schema.object
Database name is omitted
server...object
Database and schema name are omitted.
database.schema.object
Server name is omitted.
database..object
Server and schema name are omitted.
schema.object
Server and database name are omitted.
object
Server, database, and schema name are omitted.
For case you can use Two Formats, database.schema.object OR database..object Examples:
[WideWorldImporters].[Application].[Cities]
OR
[WideWorldImporters]..[Cities]
Second: About MySQL, the Schema name is Synonymous with the Database name So There is two SQL formats database.object OR object, Here are useful links describe Whats differents between Schema and Database in MySQL Stackoverflow Question And TutorialsPoint Question

Validate that referenced tables exist when creating a procedure

SQL Server only seems to validate that a procedure contains valid T-SQL and that all columns referenced for existing tables are valid. Meaning that I can create a procedure that references non-existent tables.
So, how might I verify that only existent tables are referenced?
Please note that I do not care about dynamic SQL in this case as I believe that would be out of scope.
You are correct that it does NOT validate if the tables, views or other objects exist. This is known as deferred name resolution. https://technet.microsoft.com/en-us/library/ms190686.aspx
The only way I know of to validate the objects actually exist is to execute the procedure.
Yes it will not check, but some of MVP's posted feature for this...
https://connect.microsoft.com/SQLServer/feedback/details/260762/add-optional-checks-for-more-robust-development
You can actually make use of SSDT tool in visual studio so that the once you create a procedure that actually refers a non existent table, then the Visual Studio gives a warning
Deferred name resolution is a SQL Server "feature" in there for convenience as it allows development to be done "out of order". But it does allow invalid objects to slip in there.
Redgate SQL Prompt (commercial tool) has a Find Invalid Objects feature that will list objects that reference objects that don't exist.
It has a 14-day trial so feel free to download it and give it a go. If it doesn't spot the objects you expect it to, do let us know!
Query the database system's "tables" table.
After connecting to the database, use this to view all tables in the database.
SELECT * FROM sys.tables
Use this to view a specific table.
SELECT * FROM sys.tables WHERE name='<YourTableName>'

Is it possible to create table/views under a package in the schema?

In MS SQL Server 2012/oracle, I need to create something like a.b.c
where c is the table/view name, b is the package name and a is the
schema name.
I wanted to create a table/view in two levels. I couldn't find any
proper document regarding this. Any suggestion to find the good document
will be helpful.
MS SQL Server and Oracle are very different. They're both relational DBs, but different vendors and don't function quite the same. There are similarities though.
At any rate, you don't create tables under a package. A table is an object much like a package is an object. A package is designed to hold a collection of procedures/functions within Oracle. SQL Server doesn't even implement packages.
So, as an Oracle example, the best you're going to get is Database > account (or schema..) > table.

SSMS how to find entity in database

I have been told an entity called table_loader in a database, database_1 in SSMS (version 2008 R2) exists and needs to be fixed. It is not obviously a stored proc. It's purpose is to convert an excel spreadsheet to table data. Is there any easy way to search a database for an entity name in SSMS.
The find function appears to work only with text SQL files as opened in SSMS.
Since originally posting I have found out from a colleague that this entity is a DTS package; however, I believe searching a database for a name is still a useful thing to be able to do, especially if you don't know what "layer" the entity is in with respect to the database folder structure.
Thanks.
A great, free, tool is Red-Gate SQL Search. It lets you search for just about any object from SSMS in a very user-friendly manner. http://www.red-gate.com/products/sql-development/sql-search/. You just type in the object name and it will search across databases and object types and display what it finds. I like it because it also searches within sproc text and such which can be very helpful, depending on what you're looking for.
If you open up a query window in SSMS you can use the below SQL to do a wildcard search:
USE [dbname]
SELECT * FROM sysobjects WHERE name like '%table_loader%'
This thread has got some good queries and lists the xtype meanings (sproc, table, key etc):
How do I get list of all tables in a database using TSQL?

Is it possible to switch to a database on a linked server using a 'USE' statement in SQL Server 2005?

I've tried the obvious:
USE linkedServerName.databaseName
Which gives me the error:
`Could not locate entry in sysdatabases for database 'linkedServerName'.
If something like this were possible, it'd save me a bunch of clicking around in management studio!
Linked server definitions are designed for use as part of the four-part naming convention:
[LinkedServerDefinition.][DatabaseName.][SchemaName.]DatabaseObject
for example, OtherServer.Database.dbo.MyTable
They might have other uses, but with the USE statement is not one of them.
Would
SELECT * from LinkedServerDefinition.master.sys.databases
help in identifying what databases are "over ther"?

Resources