如何使用sql在现有表中添加列 [英] How to Add Column In existing Table using sql
本文介绍了如何使用sql在现有表中添加列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
大家好
我正在尝试向现有表添加新列但我收到错误,我尽可能地方式
我的代码是
Hi All
I am trying to add new column to existing table but i am getting error , i have in all possible ways
my code is
ALTER TABLE TRTemplate
ADD ( CreatedbyId bigint not null,
ModifiedId bigint not null,
CreatedDate date not null,
ModifiedDate date not null);
and tryed
ALTER TABLE TRTemplate
ADD column CreatedbyId bigint not null,
ADD column ModifiedId bigint not null,
ADD column CreatedDate date not null,
ADD column ModifiedDate date not null;
怎么样请任何人帮我.......
how to it please anybody help me.......
推荐答案
语法错误
syntax error
ALTER TABLE TRTemplate
ADD CreatedbyId bigint null,
ModifiedId bigint null,
CreatedDate date null,
ModifiedDate date null;
如果你想在列中添加not null,你必须截断表。
if you want to add not null to your column you have to truncate the table .
ALTER TABLE的SQL语法(http://www.w3schools.com/sql/sql_alter.asp [ ^ ])不允许多行。你必须逐行完成:
The SQL syntax for ALTER TABLE (http://www.w3schools.com/sql/sql_alter.asp[^]) doesn't allow for multiple lines. You have to do it line by line:
ALTER TABLE TRTemplate
ADD column CreatedbyId bigint not null;
ALTER TABLE TRTemplate
ADD column ModifiedId bigint not null;
ALTER TABLE TRTemplate
ADD column CreatedDate date not null;
ALTER TABLE TRTemplate
ADD column ModifiedDate date not null;
MS SQL Server的ALTER TABLE语法 [ ^ ]允许您使用单个语句添加多个列。你只需要正确的语法。 :)
你的第一个代码块是最接近的 - 你只需要删除列列表周围的括号:
The ALTER TABLE syntax for MS SQL Server[^] allows you to add multiple columns with a single statement. You just need to get the syntax right. :)
Your first code block is the closest - you just need to remove the parentheses from around the column list:
ALTER TABLE TRTemplate
ADD
CreatedbyId bigint not null,
ModifiedId bigint not null,
CreatedDate date not null,
ModifiedDate date not null
;
这篇关于如何使用sql在现有表中添加列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文