简体   繁体   English

如何在SQL Server 2008 r2中添加列值?

[英]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.

相关问题 如何在SQL Server 2008 R2中添加具有其他列值作为默认值的列? - How to add a column which has another column value as default value in SQL Server 2008 R2? 如何在SQL Server 2008 R2中使单列成行? - How to make Single Column into Rows in Sql Server 2008 R2? SQL Server 2008 R2,为另一列的每个不同值选择一个列的一个值 - SQL server 2008 R2, select one value of a column for each distinct value of another column 不同列上的不同值的最大列值SQL Server 2008 R2 - MAX Column Value for Distinct Value on Different column SQL Server 2008 R2 计算列中值的出现并添加到SQL 2008 R2中的新列 - Count occurence of a value in a column and add to new column in SQL 2008 R2 SQL Server 2008 R2:查找column1中存在column2值的行 - SQL Server 2008 R2: Find rows where column2 value present in column1 SQL SERVER 2008 R2在另一列中查找列词 - SQL SERVER 2008 R2 find column words in another column 通过另一个表中的列更新SQL Server 2008 R2中的表,并且还需要求和值 - Update a table in SQL Server 2008 R2 by a column in another table and also need a sum value 在WHERE子句中使用CASE? SQL Server 2008 R2根据值按不同的列筛选查询 - CASE in WHERE clause? Filter query by different column depending a value SQL Server 2008 R2 根据另一列的最大值选择一个不同的行SQL Server 2008 R2 - Select a distinct row based on the max value of another column SQL Server 2008 R2
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM