Home SQL Alter Table
E-mail Print PDF

Синтаксис SQL

ALTER TABLE table_name
ADD column_name datatype

ALTER TABLE table_name
DROP COLUMN column_name

ALTER TABLE table_name
ALTER COLUMN column_name datatype

Example 1

There is a table "Persons":

P_IdLastNameFirstNameAddressCity
1 Hansen Ola Timoteivn 10 Sandnes
2 Svendson Tove Borgvn 23 Sandnes
3 Pettersen Kari Storgt 20 Stavanger

1
2
ALTER TABLE Persons
ADD DateOfBirth 

Query Result:

P_IdLastNameFirstNameAddressCityDateOfBirth
1 Hansen Ola Timoteivn 10 Sandnes
2 Svendson Tove Borgvn 23 Sandnes
3 Pettersen Kari Storgt 20 Stavanger

Example 2

1
2
ALTER TABLE Persons
ALTER COLUMN DateOfBirth year

Remove columns

1
2
ALTER TABLE Persons
DROP COLUMN DateOfBirth

Query Result:

P_IdLastNameFirstNameAddressCity
1 Hansen Ola Timoteivn 10 Sandnes
2 Svendson Tove Borgvn 23 Sandnes
3 Pettersen Kari Storgt 20 Stavanger

Comments

 
+3 #1 Denis 2010-07-13 12:06 And if you want to specify a nickname in the title, ie for example instead of writing Adress Address. What to do? Quote
 
 
0 #2 Rufflet 2011-04-27 05:29 Dennis, you're confusing something.
What do you mean an alias?
Aliases are used in the selector (see section SQL Alias)
Quote
 
 
0 #3 Pavel 2011-10-20 09:32 And if I want to change the number of characters in the column, the data in this column is not removed?
Is it right to my query:

Persons
ALTER COLUMN Address nvarchar (200)
Quote
 
 
0 #4 снег 2011-12-27 19:47
And if you want to specify a nickname in the title, ie for example instead of writing Adress Address. What to do?

Quote
 

Authorization

Nice Ajax Poll

Which one of my extensions is the best?

Statistics

Translate

русскийitalianoDeutschEnglishLATVIANукраїнськаfrançaispolski
1

Advertisement