there a way to drop 'sysmessages' table from one database? - sql

unfortunately i create table call 'sysmessages' in SQL Server 2008. when i restore the DB to SQL Server 2012 i realize that i have two Tables call 'sysmessages'.
i don't want to change my table name because it using in the code.
can i remove only from specific database system table?

it is not a table, but a view
of course you cannot remove it, but you don't need to. It is in a different schema. You will not address it like select * from sys.sysmessages, you will address it like select * from dbo.sysmessages
"i don't want to change my table name because it is used in the code" - you can/should change the code as well :)
edit - no. 2. is not applicable in SQL 2012, however it is tested and working in SQL 2008R2

You cant drop system tables,your best bet is to change your code

Related

Ignoring schema name on sql select?

using SQL server 2014 I am able to select without specifying the schema name when it is NOT DBO.
We are now switching over to SQL 2016 and I am no longer able to select without adding the schema name?
Problem: Going back into each stored proc to add the schema name in would take a lot of time so I was wondering if it is possible to ignore the schema name somehow? I have been searching google but haven't found anything..
The procs are used in our SSRS reports, which there are over 100 and some are embedded into the reports so if there is a way to avoid having to change each one that would be great!
It seems the default schema is a property of the connecting user. Maybe you should check how the new "migrated" user has been defined.

SQL Server: Create a duplicate of a database without the data

I have a database called AQOA_Core with huge amount of data.
I have a newly created database called AQOA_Core1 which is basically empty. I want to write a query to duplicate AQOA_Core to AQOA_Core1 without the data. I guess to be precise I want to create a skeleton of the primary database into the secondary database.
PS: I use Toad for my database operations.
You can use SQL Server Script Wizard for scripting database objects. You can exclude data, and select the database object types you want to include in your script
Please check the SQL Server guide I referenced above,
I hope it helps you

SQL statement to find a table by its name

We have a lot of databases and a lot of tables within those databases. I'm searching for a specific one. I know the name of the table but it wouldn't be easy to search through every database manually. What SQL statement could I used to find the table by name?
Btw, we're using Microsoft SQL Server Management Studio. Maybe there's another way to search for tables by name within this program?
You said you did a search which should've led you to this article:
http://blog.sqlauthority.com/2008/04/29/sql-server-find-table-in-every-database-of-sql-server/
If not, follow that. Basically what he creates is a stored procedure which will search for every table name you specify in every database.
If you were to do this:
select * from sys.tables where name like '%tablename%'
You would need to change the database every single time and if you have a lot, well you see the problem.
Try this:
Select name from DBname.sys.tables where name like '%info'
Thought I would update with the solution I use now to find a table among many dBs. After some searching around I found this query:
/*Finds a table across multiple dBs and returns the dB(s) in which the table was found*/
SELECT DISTINCT DB_NAME(database_id)
FROM [sys].[dm_db_index_operational_stats](NULL,NULL,NULL,NULL)
WHERE OBJECT_NAME(object_id,database_id) = 'table name'
This query finds the dB which holds the table. Then, in Microsoft SQL Server Mgmt Studio, I go to Object Explorer Window, find the dB identified by the query, expand its contents, and click on the Tables folder. Then I use the Filter tool to find the table by name. It would be nice if the filter tool worked on the Databases folder but it does not. You must select the Tables folder before filtering.
This may not be the best solution, but it works for me.

Oracle Database Users in synced database

Ok so I have a little problem...
In my project we have a Oracle SQL Server. In the database I have access to some of an other users tables:
Tables:
|-bla
|-bla
Users:
|-otherUser (let's just call him that)
|-Tables:
|-aTable
In Oracle, to access the aTable table I use SELECT * FROM otherUser.aTable
Now, we also have a MS SQL CE database to which I sync the data from the OracleDB using the MS Sync f/w. And in the CE db - after sync - I get a table otherUser.aTable. This sounds good, so even though the CE doesn't have the User concept it just adds the same table.
BUT the problem is that when calling the same SQL query on CE as on Oracle I get a The table name is not valid error. Instead if I want to get the content of the table, the two ways that I have found to work is surrounding the otherUser.aTable with either [] or "".
However neither of them seem to work with Oracle. The [] seem to be an illegal name, and the "" seem to search for a table called just that (not an other user).
So why don't I just use the one way on Oracle and the other on CE? well I also use NHibernate as a ORM and it kind of needs the same table name for both the databases...
Is there a third way to encapsulate the table name that works with users in Oracle and just works in CE? or do you have any other ways to fix this issue?
I have no experience with MS SQL, but it seems like a problem that might be solved with synonyms on Oracle side.
Try to create synonym "otherUser.aTable" for otherUser.aTable in Oracle.

How to generate "Create Table" script, when I only have read only permission?

I have read only permission on a SQL Server 2005 database, and I'm looking to get a table schema locally to work with. With my current access it won't let me right click on the table and choose 'Create Table' to get the script for this.
Is there a way to generate the create table script from a select statement or by some other mechanism?
Thank you!
You could create a linked server on your local machine. Then, you can use select ... into to copy the table, including data:
select *
into NewTableName
from [LinkedServerName].[DatabaseName].dbo.TableName
This will not copy indexes or constraints. To exclude the data, use select top 0 *.
It's a bit long but the script in Script Table Definitions using TSQL could be addapted to work without needing to create the stored procedure mentioned.
I am assuming you are working with SQL Server 2005