[英]How to add column value in SQL Server 2008 r2?
I created a table called Dummy
with 4 columns: Date, Year, Student_Names, Subject
. 我创建了一个名为
Dummy
的表,其中包含4列: Date, Year, Student_Names, Subject
。
After a few days I need to add one more column name called Marks
. 几天后,我需要再添加一个名为
Marks
列名。
I know how to add column Marks
by using the SQL query, I am using the query below: 我知道如何使用SQL查询添加列
Marks
,我使用下面的查询:
Alter Table Dummy
add Mark varchar(30)
After I add the column, all values are NULL, I need some value in the place of NULL. 添加列后,所有值都为NULL,我需要一些值代替NULL。
How do I add those values? 如何添加这些值? Values are mentioned in an Excel file.
值在Excel文件中提到。
Try, 尝试,
Alter Table Dummy ADD Mark varchar(30) DEFAULT ''
or 要么
UPDATE Dummy
SET [MArk] = 'new value'
your code is update Dummy set Marks = 10 where Student_Names = name you want to add marks to
你的代码是
update Dummy set Marks = 10 where Student_Names = name you want to add marks to
like this you can add marks to all the students 像这样你可以给所有学生添加标记
good luck 祝好运
You can update NULL values: 您可以更新NULL值:
UPDATE Dummy
SET Mark = "none"
WHERE Mark is NULL
Will set all the marks to "none". 将所有标记设置为“无”。
Also, when adding the column, you can specify a default value: 此外,添加列时,您可以指定默认值:
ADD Mark varchar(30) NOT NULL DEFAULT 'none'
要更新Excel工作表中的值,您需要在Excel文件中编写Query(使用CONCATENATE函数)并在表上运行它。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.