被遗忘的数据库! [英] forgotten database !
问题描述
大家好!
我的桌子有问题!
我忘记了选择它时的主键!
我保存了表格,几分钟后,我记得我没有选择主键!
那我该怎么办?我不想再做桌子了!它是一张大桌子!请帮忙!
tnx ...
hey guys !
i have a problem with my tables!
i forgot to select my primary key when i was making it !
i saved the table and after several minutes, i remember that i didnt choose primary key !
well what can i do? i dont want make table again ! its a big table! please help !
tnx...
推荐答案
尝试以下操作:
Try this:
ALTER TABLE Production.TransactionHistoryArchive
ADD CONSTRAINT PK_TransactionHistoryArchive_TransactionID PRIMARY KEY CLUSTERED (TransactionID);
来自: http://msdn.microsoft.com/en-us/library/ms189039.aspx [ ^ ] 小>
注意:在使用ALTER TABLE
命令添加主键之前,您需要确保将该字段定义为''NOT NULL''
–在其他字段中单词,NULL
不能是该字段的可接受值.
将PRIMARY KEY
约束添加到表中的现有列或列时,Microsoft SQL Server
检查列中的现有数据以确保现有数据遵循主键规则:
-无空值
-没有重复的值
如果将PRIMARY KEY
约束添加到具有重复值或空值的列 ,则SQL Server
返回错误并且不添加约束.
另外看一下:
ALTER TABLE(Transact-SQL) [
From: http://msdn.microsoft.com/en-us/library/ms189039.aspx[^]
Note: Before using the ALTER TABLE
command to add a primary key, you''ll need to make sure that the field is defined as ''NOT NULL''
-- in other words, NULL
cannot be an accepted value for that field.
When a PRIMARY KEY
constraint is added to an existing column or columns in the table, Microsoft SQL Server
checks the existing data in the columns to ensure that the existing data follows the rules for primary keys:
-No null values
-No duplicate values
If a PRIMARY KEY
constraint is added to a column that has duplicate or null values, SQL Server
returns an error and does not add the constraint.
In addition have a look on:
ALTER TABLE (Transact-SQL)[^]
To know how to change the length, precision, or scale of a column by specifying a new size for the column data type in the ALTER COLUMN
clause
您可以使用alter命令更改表如下.
You can alter your table using alter command as follows.
ALTER TABLE table_name
ADD PRIMARY KEY (column_name)
希望这能解决您的问题.
Hope this will solve your problem.
我用Google搜索了 [ ^ ](您不说什么SQL风格)
您可能想在Google上搜索"SQL Backup命令"
I googled for ''SQL Set Primary Key''[^] (you don''t say what flavour of SQL)
You might want to google for ''SQL Backup Command''
这篇关于被遗忘的数据库!的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!