I have been trying to add columns to a table using some logic that produces this statement:
ALTER TABLE Master_List
ADD COLUMN Service VARCHAR(100) ,
Vendor VARCHAR(100) ,
Product VARCHAR(100) ,
Service_Description VARCHAR(100) ,
Level/Scale VARCHAR(100) ,
SunGard_Contract_Schedule_ID VARCHAR(100) ,
Application_Owner VARCHAR(100) ,
Application_Servers VARCHAR(100) ,
Required_Support/Dependencies VARCHAR(100);
whenever I have been trying to run it I continually get this error:
java.sql.SQLException: [Microsoft][ODBC Microsoft Access Driver] Syntax error in field definition.
at sun.jdbc.odbc.JdbcOdbc.createSQLException(JdbcOdbc.java:6957)
at sun.jdbc.odbc.JdbcOdbc.standardError(JdbcOdbc.java:7114)
at sun.jdbc.odbc.JdbcOdbc.SQLExecDirect(JdbcOdbc.java:3110)
at sun.jdbc.odbc.JdbcOdbcStatement.execute(JdbcOdbcStatement.java:338)
at sun.jdbc.odbc.JdbcOdbcStatement.executeUpdate(JdbcOdbcStatement.java:288)
at Testing.main(Testing.java:54)
I have been checking online for the proper format for the ALTER TABLE command, and the formatting seems to be correct, I have tried changing so many things I have run out of ideas of how to fix it....
The table name is Master_List, and none of those columns already exist inside it.
This is being used inside Java, incase that is relevant.
It could be the / in your column names that is giving you the problem
Your column names contain the "/" character, and that is not a valid character for column names.
Related
I have problem inserting values in my SQL server database on Azure, I am getting the following error:
Failed to execute query. Error: String or binary data would be truncated in table 'dummy_app.dbo.user_info', column 'uid'. Truncated value: 'u'.
The statement has been terminated.
I don't understand where I am wrong, I just created the server, and I am trying to experiment but cant fix this.
if not exists (select * from sysobjects where name='user_info' and xtype='U')
create table user_info (
uid varchar unique,
name varchar,
email varchar
)
go;
INSERT INTO dbo.user_info(uid, name, email) VALUES('uids', 'name', 'email') go;
Creating the table works fine, the only thing that doesn't work is the second command INSERT
I suspect that the reason is that you haven't defined a lenght for varchar and it defaults to 1 as length. Therefore your value gets truncated.
Set a varchar length to something like varchar(200) and you should be good to go.
This looks like the fact that the CREATE portion of your procedure for the table doesn't include a length of varchar, so you'd have to specify a length such as varchar(50) since the default is 1. Refer to the official MS docs in the link, in the remarks.
docs.miscrosoft.com
Also, here is the syntax for the CREATE TABLE in Azure which might be helpful as well.
Syntax of Azure CREATE TABLE
Forum.
I am working with IBM System i Version 7.1.
I am having issues in the source code with the following merge statement so I copied it over to the database client to utilize the "Run SQL Scripts" functionality.
Rather than replacing the coded in #Variables in the statement I wanted to declare local variables so that I could test the statement as is.
The added the following 'declare and set' lines and I get the following error:
declare #groupId smallint
set #groupId = 99
declare #groupName varchar(40)
set #groupName = 'Sam'
declare #groupId smallint
SQL State: 42601
Vendor Code: -104
Message: [SQL0104] Token SMALLINT was not valid. Valid tokens: DYNAMIC SENSITIVE ASENSITIVE INSENSITIVE. Cause . . . . . : A syntax
error was detected at token SMALLINT. Token SMALLINT is not a valid
token. A partial list of valid tokens is DYNAMIC SENSITIVE ASENSITIVE
INSENSITIVE. This list assumes that the statement is correct up to
the token. The error may be earlier in the statement, but the syntax
of the statement appears to be valid up to this point. Recovery . . .
: Do one or more of the following and try the request again: --
Verify the SQL statement in the area of the token SMALLINT. Correct
the statement. The error could be a missing comma or quotation mark,
it could be a misspelled word, or it could be related to the order of
clauses. -- If the error token is , correct the SQL
statement because it does not end with a valid clause.
Processing ended because the highlighted statement did not complete >successfully
I have tried adding semicolons to the end of each line and begin and end statements and still no success.
Below is the whole statement I am trying to execute:
declare #groupId smallint
set #groupId = 99
declare #groupName varchar(40)
set #groupName = 'Sam'
merge into database.table as t
using ( values( cast(#groupId as smallint)
,cast(#groupName as varchar(40))
))
as caz( group_id
, group_name
)
on t.group_id = caz.group_id
when matched then update
set t.group_name = caz.group_name
when not matched then
insert ( group_id
, group_name
)
values (caz.group_id
, caz.group_name
);
Any help is appreciated.
Please let me know if I may provide anymore information.
I may have found an answer here: https://stackoverflow.com/a/4451159/2272357
CREATE OR REPLACE VARIABLE variableName VARCHAR(50);
SET variableName = 'blah';
SELECT * FROM table WHERE column = variableName;
DROP VARIABLE variableName;
I have yet to verify it works successfully. I believe it may be a local issue though.
I get an error saying varchar or char is not a recognized in SQL Server. However I use the same software, SQL Server 2008 in college, so I do not want to go for a different version of SQL Server. Anyway I can fix this?
Major Error 0x80040E14, Minor Error 26302
create table abc
(
id int,
name varchar(15)
)
Error is:
The specified data type is not valid. [ Data type (if known) = varchar
]
varchar(n) is not supported in SQL Server Compact. Here is the full list of types supported.
Following are the types that you can use.
nvarchar(n)
nchar(n)
ntext
So you might need to change to nvarchar(10), nvarchar(5) and nchar(1) etc..
Really ? , i tried it, also i tried in creating temp table, it seems both are ok.
create table abc (id int, name varchar(15))
create table #tmp (id int, name varchar(15))
http://sqlfiddle.com/#!3/66b44
Attempting to bulk insert into a table and I am getting the error:
Bulk load data conversion error (type mismatch or invalid character for the specified codepage) for row 31, column 4 (Birthday).
Below is the code I am trying to use to insert the data:
Bulk Insert Dzt.dbo.Player
From 'A:\New Folder\Seed_Files\Player.csv'
With
(
FieldTerminator=',',
RowTerminator='\n',
FirstRow=2
)
Here is the code I used when making the table:
Use Dzt
Create Table Player
(
Player_ID int,
FirstName varchar(255),
LastName varchar(255),
Birthday date,
Email varchar(255),
L_Flag varchar(255)
);
This is my first attempt at making a table and inserting data so I am thinking it is likely a datatype error for the Birthday field but I have been unable to find anything online that I am able to grasp my head on at this time. I have also tried use the datatype datetime instead of date but I received the same error.
I am using SSMS 2012 to create and insert the data onto a 2012 SQL Server.
Let me know if there is anything else I can provide that might help.
As you suspect it could be a date format error, I would suggest importing the csv into a table with Birthday column set to varchar type. Then use this query to filter the erroneous records.
select birthday from temptable where isdate(birthday) = 0
You could then correct those records and then insert them into your old table.
I am using Apache derby database v 10.9.1.0. There is one existing table Country-having column LawID of type bigint. It contains records having integer data only. Due to some business reason, I need to alter its data type from 'bigint' to 'varchar' . I tried following two ways to alter existing table. But both ways did not work.
a. first way
ALTER TABLE Country ADD COLUMN LawID_NEW VARCHAR(50);
UPDATE Country SET LawID_NEW = LawID;
ALTER TABLE Country DROP COLUMN LawID;
RENAME COLUMN Country.LawID_NEW TO LawID;
It shows message like :Columns of type 'VARCHAR' cannot hold values of type 'BIGINT'.
b. second way
ALTER TABLE Country ALTER LawID SET DATA TYPE VARCHAR(50);
It shows error message like : Invalid type specified for column 'LawID'. The type of a column may not be changed.
Any help related to correct alter query is highly appreciated, Thanks
I think the first method would work with this change:
UPDATE Country SET LawID_NEW = TRIM(CHAR(LawID));
ALTER TABLE tablename MODIFY columnname VARCHAR(20);
This works in mysql. Give it a try.
Or
ALTER TABLE table CHANGE columnname columnname VARCHAR(20);