Sybase column rename error - sybase-ase

Could not rename a column in a Sybase 15 table. I am getting the below error. Please help. What am I missing?
Incorrect syntax near 'NAME1'.
CREATE TABLE TEST1 (NAME1 VARCHAR(20) NULL, NAME2 VARCHAR(20) NULL)
GO
ALTER TABLE TEST1 RENAME NAME1 TO FIRST_NAME
GO
Referring http://infocenter.sybase.com/help/index.jsp?topic=/com.sybase.infocenter.dc38151.1270/html/iqref/BABCGFHG.htm

You have tagged Sybase ASE but your link points to Sybase IQ
Here is how you do in ASE
sp_rename 'TEST1.NAME1', 'FIRST_NAME'

Related

What is wrong with this SQL query? (or perhaps why doesn't MySQL like the sixth field?)

Here is my table:
id int(11)
name varchar(255)
description text
highest_bidder int(11)
value varchar(255)
group int(11)
I originally didn't have the group field in there but added it later.
Anyway, I go to insert into the database using the following snippet:
INSERT INTO name_of_table_removed
(id,name,description,highest_bidder,group,value)
VALUES
(2,"...","...",0,3,"$45.99")
And I get an error:
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'group,value) VALUES (2,"...","...",0,3,"$45.99")' at line 1
What am I missing?
Group is a reserved word. Escape the field as :
`group`
..Or rename the field.

What is wrong with my SQL syntax here?

New to SQL. I'm looking to create a IT asset database. Here is one of the tables created with php:
mysql_query("CREATE TABLE software(
id VARCHAR(30),
PRIMARY KEY(id),
software VARCHAR(30),
key VARCHAR(30))")
or die(mysql_error());
echo "Software Table Created.</br />";
This is the output from the browser when I run the script:
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'VARCHAR(30))' at line 5
I am running a standard LAMP stack on Ubuntu Server 10.04.
Thank you.
key is a reserved word. If you really need this name, you should use quotes :
... `key` varchar(30)
KEY is a reserved word in MySQL. Trying picking a different name for that field, or enclose it in backtick characters.
try sw_key instead of key. Maybe key is a reserved word.
I would also change the lines
id VARCHAR(30),
PRIMARY KEY(id),
To
id VARCHAR(30) PRIMARY KEY,
to make the syntax more standard

PostgreSQL create table with PK, NOT NULL, varchar

Trying to use a Postgres db from Heroku that is connected to git for a php app. When I commit, I am getting errors already in the sql syntax.
I am not sure if it is me, or if there is missing required libraries.
Either would help greatly.
Here is the error that is coming up:
PHP Warning: pg_query(): Query failed: ERROR: syntax error at or near "NOT
: LINE 2: UserID NOT NULL PRIMARY KEY varchar(255),
^ in /app/index.php on line 69
And the corresponding code:
$raterTable = pg_query($conn,
"CREATE TABLE Rater (
UserID NOT NULL PRIMARY KEY varchar(255),
email varchar(255),
name varchar(255),
joindate DATE,
type varchar(255) CHECK (type IN ('blog', 'online', 'food critic')),
reputation int CHECK (reputation >= 1 AND reputation =< 5) DEFAULT 1
");
Thank you in advance!!
Stupid mistake.
Its varchar(255) NOT NULL..
I had them in reversed order.
Maybe this will help somebody one day :)

MySQL CREATE TABLE syntax error

I am trying to create an sql table but don't know What's wrong here? My SQL syntax is as follows:
CREATE TABLE '__admin'('id' int NOT NULL AUTO_INCREMENT PRIMARY KEY, 'name' VARCHAR(32) NOT NULL, 'password' VARCHAR(32) NOT NULL)ENGINE=MYISAM;
I get an error message saying:
You have an error in your SQL syntax; check the manual that corresponds to your
MySQL server version for the right syntax to use near
''id' int NOT NULL AUTO_INCREMENT PRIMARY KEY, 'name' VARCHAR(32) NOT NULL, 'pass'
at line 1
Need a quick help please? Thanks
Need to learn SQL syntax first?
Identifiers have to be put in backticks, not single quotes
CREATE TABLE `__admin`(`id`
and so on
as stated in one of the comments, backticks are not a necessity.
CREATE TABLE _admin (table attributes) would work just fine.. also some software may need you to specify the db engine when creating the table such as sequal pro for mac.. if you are linking your tables using foreign keys then add ENGINE=INNODB at the end of your statement
so it will be
CREATE TABLE _admin(id INT PRIMARY KEY, etc.)ENGINE=INNODB;
hope this helps

what is the mysql error in following? [closed]

This is to create a new table with name as users id
$tablename=$_SESSION['lgn-id'];
mysql_query("CREATE TABLE $tablename(
qtno INT NOT NULL AUTO_INCREMENT,
PRIMARY KEY(qtno),
qt VARCHAR())")
or die(mysql_error());
echo " so I created one!";
It's showing the following error table name being text36.txt#gmail.com
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '#gmail.com( qtno INT NOT NULL AUTO_INCREMENT, PRIMARY KEY(qtno), qt V' at line 1
Your create statement should be
CREATE TABLE `$tablename`(
qtno INT(10) NOT NULL AUTO_INCREMENT,
qt VARCHAR(100),
PRIMARY KEY(qtno))
And Creating separate table for each user is bad idea, lets say you have 1000+ users, do you want to create 1000+ tables? create table for post like UserId, Post and store userid from user table and post
You can create Posts table like
CREATE TABLE UserPosts
(
id INT(10) NOT NULL AUTO_INCREMENT,
UserId Varchar(100),
UserPost varchar(1024),
InserDate DateTime,
PRIMARY KEY(id)
)
Then you can do
select UserId, UserPost FROM UserPosts Where UserId = 'text36.txt#gmail.com'
The problem is with the unquoted table name as well as VARCHAR(). It has to have a length e.g. VARCHAR(100).
The issue is pretty obvious from the error, you can't have an # character in your table name.
You can wrap it in backticks to fix that. You also need to specify a length for varchar()
Refrences: 9.2. Schema Object Names, 11.1.6.1. The CHAR and VARCHAR Types

Resources