I am trying to running the following command to copy a table to another database and it is saying incorrect syntax near "tbl_SecurityNamespace". Any ideas? TIA
select * into ForMSDB tbl_SecurityNamespace
from Tfs_configuration
go
If it's another database in the same environment:
select * into ForMSDB..tbl_SecurityNamespace
from Tfs_configuration
This should be as
select * into ForMSDB..tbl_SecurityNamespace
from Tfs_configuration;
Related
I am using MS SQL Server Version 2008 and MariaDB 10.5.
My table and data :
Following is the query i am running on both the databases.
select distinct distributor from market order by city
Found this query is failing in MS SQL Server database with error
SQL Error [145] [S0001]: ORDER BY items must appear in the select list if SELECT DISTINCT is specified.
Understood the reason why it failing
Reason for - ORDER BY items must appear in the select list if SELECT DISTINCT is specified
when i ran the same query run with MariaDB it ran successful without any error and gave me below output.
So i have doubt why MariaDB is behave different here? ideally it should fail right?
Thanks in advance.
Please try this query
Select distinct col from (
Select col from table order by col
)
I want to be able to create new tables based on any SQL select statement. I have tried the following which I got the format from another question and it does not work (there are similar questions but not one that I found actually works). I keep getting an error on the SQL statement.
Msg 156, Level 15, State 1, Line 2
Incorrect syntax near the keyword 'AS'.
This is the CREATE TABLE statement:
CREATE TABLE MyNewTable
AS
SELECT *
FROM dbo.Bat
This will copy the entire table including rows
SELECT *
INTO newTableName
FROM dbo.Bat
Add WHERE 1 = 0 to copy just the table structure
If it is SQL Server (the dbo schema, default in SQL Server indicates it is SQL Server), you can do following.
select * into MyNewTable from dbo.Bat;
The SELECT INTO statement does not copy your table constraints.
You statement is a valid Oracle and MySQL statement though.
CREATE TABLE ... AS SELECT is simple (by deliberately ignoring for example the concepts of storage)
To create a table with all its lines
code:
CREATE TABLE XX AS SELECT * FROM YY ;
the result of command in mysql
Right, so when I run:
Select * from Consultants
I get:
ORA-00942: table or view does not exist
The table clearly exists in the object browser.
However, when I run:
select * from Customers#xe.m512Finn
I get the data requested.
Please don't tell me that the table in the local database doesn't exist because it does; I created it and it's there in the object browser.
Is there something wrong with my syntax? Please help me with any suggestions.
Here you're selecting from the Consultants table
Select * from Consultants
And here you're selecting from the Customers table
select * from Customers#xe.m512Finn
The table does exists in m512Finn user that's why it returns the values for
select * from Customers#xe.m512Finn
You might be running that query in a different schema or the query u might be looking for must be
Select * from consultants#xe.m512Finn
Okay i've resolved the issue, it's that when you query local tables, you need double quotation marks around the table name.
select * from "Consultants"
Firstly, I'm new to SQL - not so new to Java anymore.
Secondly, I'm using NetBeans 7.2.1 with JavaDB and when I'm trying to run a SQL query, such as:
SELECT * FROM mydatabase ORDER BY colname DESC LIMIT 0,1
and try to execute the commend, the console displays an error, namely:
Error code -1, SQL state 42X01: Syntax error: Encountered "limit" at line 1, column 55.
Any ideas on what I can do? Do you see something wrong with my query code?
Please consult the Derby FAQ at http://db.apache.org/derby/faq.html#limit
You can easily do it like this.
SELECT *
FROM mydatabase
ORDER BY colname DESC
FETCH FIRST 10 ROWS ONLY;
Reference
I'm very confused - I opened up my database in Squirrel SQL to do some SQL and I type this in my SQL entry window:
select * from *
And for whatever reason it gives me this output:
Error: Incorrect syntax near '*'.
SQLState: 42000
ErrorCode: 102
Does anyone know what this means? It's hard to do a google search because Google treats the asterisk as a special character.
I think that second * is invalid, that should be a table name:
SELECT * FROM MyTable
You need to specify the table name.
SELECT * FROM myTable
If however you knew that and you are actually looking for a way to SELECT from all your tables i'm afraid you'll have to type them one by one like this :
SELECT * FROM myTable1
UNION ALL
SELECT * FROM myTable2
UNION ALL
SELECT * FROM myTable3
...
Also remember that if you have to Select like I did on the second example, there is a problem with the way your data is organized in you database. If it's the case, you should take a look at this article on Data Normalization.