sql server modify error - sql

i m not able to modify table in SQL server. i m new to databases.
use work
go
alter table employee
modify id varchar(20)
error message is-
Msg 102, Level 15, State 1, Line 1
Incorrect syntax near 'modify'
here is an screenshot
thanks

You have the syntax for altering a table wrong. You need:
ALTER TABLE YourTable
ALTER COLUMN ExistingColumn VARCHAR(20)

The syntax should be
ALTER TABLE Employee ALTER COLUMN ID VarChar (20)
Here is the ALTER COLUMN syntax.
http://msdn.microsoft.com/en-us/library/ms190273.aspx
Now, having said all that, I have a question for you.. Why is your ID column a VarChar as opposed to an Identity Column?

Related

Unable to change column size

In my database table, I've column entryId with data type varchar and size=10. Now I want to change size to 100, when I hit following query -
ALTER TABLE ft ALTER COLUMN entryId TYPE varchar(100);
it results into following error -
Incorrect syntax near 'varchar'.
My query syntax looks correct. Help me to understand what I did wrong.
No "Type" is need here:
ALTER TABLE ft ALTER COLUMN entryId varchar(100);
I SQL Server, the keyword type is not needed
ALTER TABLE ft ALTER COLUMN entryId varchar(100);
Remove 'Type' from your query :
ALTER TABLE ft ALTER COLUMN entryId VARCHAR(100);
no need for 'TYPE' keyword
ALTER TABLE ft ALTER COLUMN entryId varchar(100);

error while trying to alter a column in a table

I am trying to alter the size of a column 'Login' which is a primary key in my table 'Utilisateurs' which is in my in 'ME' database. I tried this command:
ALTER TABLE ME.UTILISATEURS
ALTER COLUMN login VARCHAR (50) ;
but I get this error:
Error code -1, SQL state 42X01: syntax Erreur : Encountered "varchar" at line 2, column 21.
I am using netbeans IDE, the Derby Driver.
ALTER TABLE ME.UTILISATEURS
ALTER COLUMN login SET DATA TYPE VARCHAR(50)

Alter Field Type from nvarchar(255) to nvarchar(Max) in SQL Server 2005

I would like to alter column type in table stk020. So, I used this query..
ALTER TABLE [stk020]
ALTER COLUMN [t16] nvarchar(Max) not null
The original column type of [t16] is nvarchar(255). I get this error
Msg 5074, Level 16, State 1, Line 1
The object 'DF_STK020_t16__725CC34D' is dependent on column 't16'.
Msg 4922, Level 16, State 9, Line 1
ALTER TABLE ALTER COLUMN t16 failed because one or more objects access this column.
Any solution?
You must first drop what we presume is the Default constraint on the column before you alter its data type:
Alter Table stk020 Drop Constraint DF_STK020_t16__725CC34D
GO
Alter Table stk020 Alter Column t16 nvarchar(max) not null
GO
Alter Table stk020 Add Constraint DF_STK020_t16__725CC34D
Default ... For t16

ALTER TABLE syntax - missing DIRECTORY keyword

I am trying to alter a table in Oracle database by adding two new columns to it with SQL query as below:
ALTER TABLE Members
ADD annual_dues NUMBER(5,2) not null DEFAULT '52.50',
ADD payment_date DATE;
On executing it, I am getting an error as below:
SQL Error: ORA-30649: missing DIRECTORY keyword
I have played around it but it didn't help. What is wrong in the SQL query?
I think you need to put NOT NULL after the DEFAULT 52.50:
ALTER TABLE Members
ADD ( annual_dues NUMBER(5,2) DEFAULT 52.50 NOT NULL
, payment_date DATE );

Error while altering table in SQL Server

I'm just trying to add 2 columns to customer table
alter table CUSTOMER ADD ( CUSTOMERNAME VARCHAR(255) NULL
, CUSTOMERDESC VARCHAR(30) NULL )
but I get the following error when I try to run the script,
Msg 102, Level 15, State 1, Line 1 Incorrect syntax near '('.
Can someone tell me what is the mistake that I'm doing. Thanks in anticipation
You don't need the brackets for an alter statement so remove them. ie:
alter table CUSTOMER ADD CUSTOMERNAME VARCHAR(255) NULL,
CUSTOMERDESC VARCHAR(30) NULL
You don't need any ( before the column names - just use:
ALTER TABLE dbo.Customer
ADD CustomerName VARCHAR(255) NULL, CustomerDesc VARCHAR(30) NULL
Does that work?