Error message from simple SELECT statement with practice database [closed] - sql

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I use the AdventureWorks practice database attached to SQL Server 2012.
A simple statement like:
SELECT * FROM HumanResources.Shift;
gives me this error:
Msg 208, Level 16, State 1, Line 1
Invalid object name 'AdventureWorks2012'.
I also tried:
USE master
GO
SELECT * FROM HumanResources.Shift;
Received same error message. Any idea to why this is happening?

Is AdventureWorks2012 the name of a database or a table?
USE <database name>
means use the specified database to run the query against.
SELECT * FROM <table name>
means select all the rows from the specified table.
--Edit because of change in question--
You don't want to use Master, you want to use the name of your DB. Next, using the object explorer, I would make sure the table actually exists in the Database you created.

Related

SQL Insert Query With Condition Exception [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 12 months ago.
Improve this question
I have this query:
String requete = "INSERT INTO reduction(newPrix) VALUES (?) "
+ "WHERE id_prom=? AND id_prod=?";
I am getting an exception:
You have an error in your SQL syntax; check the manual that
corresponds to your MariaDB server version for the right syntax to use
near 'WHERE id_prom=2 AND id_prod=6' at line 1
I'm wondering why the INSERT query was failing. Any advise appreciated.
You insert a row into your table.
This means that you need to specify all mandatory values (i.e. values for the columns that are not nullable and don't have a default value).
You can't use a where clause in this kind of insert statement. What would it mean? And in your program you can verify the validity of the data you'd like to add to your table and decide to insert or not.

How to use sp_depends for other database [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 7 years ago.
Improve this question
Using SQL Server 2010
For updating the tables i am using following line
update database1_ab..table1
For sp_depends i am getting error as "Incorrect syntax near '.'"
sp_depends database1_ab..table1
How to use sp_depends for referring other database tables in current database
regardless, you need to put it in single quotes... ie
sp_depends 'database1_ab..table1'
or
sp_depends '[database1_ab]..[table1]'
You can call all the sp_ -procedures also in different database like this:
database1_ab..sp_depends table1

Alter script not working on server [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I have an alter script to change datatype from nvarchar to float which works fine in my local machine but fails to work on 2012 server.
Can anybody tell me what's wrong with my script or any changes need to be done on server?
My alter script is as follows:
ALTER TABLE mytable
ALTER COLUMN mycolumn FLOAT
and I get this error:
Msg 8114, level 16,state 5, line 6
Error converting datatype nvarchar to float
If it is throwing an error 'Error converting data type varchar to float.' then it is obvious that there are some values in the varchar field which cannot be converted to float. If you can tell us more about the error being thrown, it will be easier to understand the issue.

display information from sql server view [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
New to views with sql server, not sure how to view the information it has gathered with vbscript. I know it is not as simple as:
select * from EXAMPLE_VIEW
I want to get the information from my example view loop through it and display it, however when i try to do that sql query i get invalid object name.
My question is how do you sql query a view
You should probably be doing this:
SELECT column1, column2 FROM dbo.EXAMPLE_VIEW;
This is because if your user has a different default schema than dbo, it might be checking for some other view with the same name under a different schema. (You also know not to use SELECT *, right?)
So you should also make sure your user account has select permissions on the view and/or the table(s) behind it.
Bad habits to kick : using SELECT * / omitting the column list
Bad habits to kick : avoiding the schema prefix
select * from EXAMPLE_VIEW
...is the correct way to query a SQL Server view.
If it's not working for you, you have a different kind of problem: maybe no permissions, maybe no server connection, maybe a view called EXAMPLE_VIEW doesn't exist, maybe something else.
Whatever it is - we need the exact error message and as much example code as possible to help you.
But the SQL itself is correct.
Is your current database set correctly after establishing connection? It can be set using connnection string (http://www.connectionstrings.com/) or by specyfying it witin query itself:
SELECT * FROM MYDB.dbo.EXAMPLE_VIEW;

Recover Updated Data - SQL Server 2005 [closed]

Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 9 years ago.
Improve this question
I have an issue that, while using sql server 2005 i have executed update query without where clause (by mistake) and all the original values of the column get lost.
How can I get old values??
Any suggestion/tips/solution is welcome and will be highly appreciated.
Hi AngelIII,
SQL server keeps log for every transation.So you can recover your modified data from the log as well without backup.
Select [PAGE ID],[Slot ID],[AllocUnitId],[Transaction ID] ,[RowLog Contents 0]
, [RowLog Contents 1],[RowLog Contents 3],[RowLog Contents 4] ,[Log Record]
FROM sys.fn_dblog(NULL, NULL)
WHERE AllocUnitId IN
(Select [Allocation_unit_id] from sys.allocation_units allocunits
INNER JOIN sys.partitions partitions ON (allocunits.type IN (1, 3)
AND partitions.hobt_id = allocunits.container_id)
OR (allocunits.type = 2 AND partitions.partition_id = allocunits.container_id)
Where object_id=object_ID('' + 'dbo.student' + ''))
AND Operation in ('LOP_MODIFY_ROW','LOP_MODIFY_COLUMNS')
And [Context] IN ('LCX_HEAP','LCX_CLUSTERED')
Here is the artcile, that explains step by step, how to do it. http://raresql.com/2012/02/01/how-to-recover-modified-records-from-sql-server-part-1/
Restore a backup taken before the update
Restore transaction logs to a point in time before the update
Restore a copy of the table you made before the update
Rollback the transaction that contains the update
It's difficult to offer a specific solution not knowing what precautions you have taken. These may not solve your problem, but may prevent this from happening in the future.
DON'T MESS AROUND WITH SQL THAT ALTERS PRODUCTION DATA UNTIL YOU HAVE ANSWERED THIS QUESTION.