I'm trying to run a simple SQL query on a LocalDb database in Visual Studio 2013.
Here's the query in a file GrabWords.sql:
SELECT * FROM Words
where Words is a table in the NextGen.mdf database. When I run this, I get the error:
Invalid object name 'Words'.
For more information, I actually have two databases in the project. In the Solution explorer one is called NextGen.mdf, and the other Cards.mdf. In server explorer, the first (that I am trying to query) is called AutoGenEntities and the other is CardsDBContext.
I just want to run this query to test queries and view the database - is there another tool I should be using to do this?
Try this:
USE [your Database name]
SELECT * FROM Words
This should ensure that you are targeting the correct database.
Related
I have a table TBLT_GLDET in my SQL Server 2008 database. When I open a new query window and select the right database and execute following query
select *
from TBLT_GLDET;
the data appears. But in the tables list the table does not appear.
Also when I try to open the table for a Crystal Report using database expert in Visual Studio, it says the table is missing in the database.
What is the reason for this?
I did following things. I double checked whether it's the right database.
I refreshed the database.
I am trying to run SQL through excel and I have the following SQL query within the data connection:
WITH TEST_DB as (select * from TEST_ADM.KPI_SAMPLE_TEST)
SELECT DISTINCT
BASE.YEAR_MONTH AS YEAR_MONTH
FROM TEST_DB BASE
If I try running this with SQL Developer, it will run successfully, no problems but when I try to run it in Excel, I get the message:
The query did not run, or the database table could not be opened.
Check the database server or contact your database administrator. Make sure the external database is available and hasn't been moved or reorganised, then try the operation again.
Is there some sort of limitation within Excel that prevents me from using WITH statements?
If I remove the statement and select from the table directly, it works but I need to use the WITH data table 6 times in my code and its rather long.
Oh, the database is an oracle database.
How can I create a new table from an existing one in SQL Server 2012 , with both its keys and its data ?
This :
select * into New_Table
from Old_Table
Does not create the dependencies .
And this :
In Sql Server Managment Studio, right-click your existing table and
select Script Table as > Create to > New Query Editor Window
Doesn't get the data .
Thanks
The following instructions work well if you want a GUI based solution and are dealing with a moderate amount of data.
In SSMS, right-click on the database that contains the table and select Generate Scripts
Select the specific table(s) to recreate
Select the Save to new query window radio button and click Advanced to set scripting options for the table
Set the Types of data to script property to Schema and data
Modify the table name in the resulting script as appropriate
One way is to use something like SQL Server Data Tools (SSDT). This is a free, Microsoft, add-on to Visual Studio 2012/2013 (which you don't need to own). This tool will do schema and data compares. So all dependencies and schema objects will be created for you, in the correct order.
So i imported the adventure works database in console project in visual studio 2012.
Now the problem is that whenever i have to write a query i have to write the whole path to get access to the table in database and it become something like.
SELECT * FROM [C:\USERS\USER\DOCUMENTS\VISUAL STUDIO 2012\PROJECTS\SQL_PRACTICE\SQL_PRACTICE\ADVENTUREWORKS2012_DATA.MDF].HumanResources.Employee;
I mean it become really long. Anyway i can avoid writing the full path in a query.
Try changing the name of the database.
USE master; GO ALTER DATABASE [C:\USERS\USER\DOCUMENTS\VISUAL STUDIO 2012\PROJECTS\SQL_PRACTICE\SQL_PRACTICE\ADVENTUREWORKS2012_DATA] Modify Name = NewDatabaseName; GO
I am new to SQL and I am facing problems. When I create any table, I can't view it. Also, is it possible to enter the data into the table via management studio?
Like Harry 1234 xyz?
If you entered the query right, and it shows that the commands have been successfully executed, you should be able to see the created table with no entries by using select * from table_name.
If you still cannot see the data, try refreshing the database. Now you should be able to see your data.
Many database engines support entering data directly without SQL statements (like Harry 1234 xyz) like Microsoft SQL Server, MySql, etc. How you do it will depend on which database engine you're using.
You have to refresh "Object Explorer" in Management Studio.
It doesn't know that you created an object via SQL script