我建议学习必要的SQL更新相应的数据您可以使用SELECT语句和ORDER BY子句按照您希望查看它的顺序查看数据,然后构建一个查询来更新该数据。
您可以使用事务来确定您的更新(如果您仍在学习SQL并且不想搞乱数据库)
BEGIN TRANSACTION -- starts a transaction
ROLLBACK -- stops the transaction and rolls back all changes to the tables
COMMIT -- stops the transaction and commits all changes to the tables
你想完成/更新什么,也许我们可以帮助你呢?
编辑
你提到你想编辑存储在表内的一些产品名称。而且这将是一次性任务。我已经在下面设置了一个小型演示,希望能帮助您指导一个可能适合您情况的解决方案。将其复制并粘贴到SQL Management Studio会话中。
此外,如果你想,你可以导出你当前的数据来说excel,在excel中编辑数据,将它作为新的临时表导入并运行SQL更新脚本来更新原始表。
/*
Products Before Update Products After Update
=========================== =============================================
ID ProductName ID ProductName
--------------------------- ---------------------------------------------
1 MSFT 1 Microsoft Corp.
2 APPL 2 Apple Inc.
3 Cisco Systems, Inc. 3 Cisco Systems, Inc.
4 IBM 4 International Business Machines Corp.
5 JAVA 5 Sun Microsystems, Inc.
6 ORCL 6 Oracle Corp.
*/
-- Imagine that this table is a table in your database
DECLARE @products TABLE (
ID INT,
ProductName VARCHAR(255)
)
-- And this table has some product information
-- which you are trying to update with new information
INSERT @products
SELECT 1, 'MSFT' UNION ALL
SELECT 2, 'APPL' UNION ALL
SELECT 3, 'Cisco Systems, Inc.' UNION ALL
SELECT 4, 'IBM' UNION ALL
SELECT 5, 'JAVA' UNION ALL
SELECT 6, 'ORCL'
-- Either build an in-memory temporary table of the product names you wish to update
-- Or do a database task to import data from excel into a temporary table in the database
DECLARE @products_update TABLE (
ID INT,
ProductName VARCHAR(255)
)
INSERT @products_update
SELECT 1, 'Microsoft Corp.' UNION ALL
SELECT 2, 'Apple Inc.' UNION ALL
SELECT 4, 'International Business Machines Corp.' UNION ALL
SELECT 5, 'Sun Microsystems, Inc.' UNION ALL
SELECT 6, 'Oracle Corp.'
-- Update the table in the database with the in-memory table
-- for demo purposes, we use @products to represent the database table
UPDATE p1
SET ProductName = ISNULL(p2.ProductName, p1.ProductName)
FROM @products p1
LEFT JOIN @products_update p2
ON p1.ID = p2.ID
-- Now your products table has been updated
SELECT *
FROM @products
是否有与SQL Server任何集成? – 2009-05-22 20:06:30
是的。它给你一个灵活的表视图(重新排列列,排序等),但不影响表结构 – gbn 2009-05-23 06:36:47