SQL SERVER-??????????????
???????????? ???????[ 2016/3/25 10:42:12 ] ?????????????
????PRIMARY KEY ?????????????е??????????????????????????????в?????? NULL ????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????? ???????????????????????????????????????????????????SQL Server????????????ù????
??????????????????????
??????????????????????????????????????????????????primary key??????????????????????SQL??????£?
????create table ???? ( ?????1 int not null?? …………??
????[constraint ?????] primary key (?????1?? …)
????)
???????????????????????????????????????????????????????????????????????????????????
?????????б??????????????????????????????£?
????alter table ???? [add constraint ?????] primary key(?????1??… )
????????????????????????????????????
????SQL Server????????????MySQL?????????????????????????????SQL Server???????????????????£?
????ALTER TABLE ????DROP CONSTRAINT ?????
?????????????????????????????????????
???????δ???????????????
????????????????ж?????????????????????????????????????а????????????????λ?????е??????????????????????????????????????????洢????????е???????洢???????е????????SELECT * FROM SYS.OBJECTS ??俴????????????????????е???????????????name????PK?????????????????????????type_desc?????PRIMARY_KEY_CONSTRAINT????type????? PK????????????????????PK????????????????????????????????????????洢λ?????????????ι?????????????????????????????? ?????????????й????????????parent_object_id??????????????object_id????????????????object_id???????? ??????????????????????????е?????????????棬???????????????棬???????????object_id??
??????????????????????·??????????????ID???????ID??????????????????ü???????????????????????????????μ??????
????DECLARE @NAME SYSNAME
????DECLARE @TB_NAME SYSNAME
????SET @TB_NAME = '????'
????SELECT TOP 1 @NAME = NAME FROM SYS.OBJECTSWITH(NOLOCK)
????WHERE TYPE_DESC ='PRIMARY_KEY_CONSTRAINT'
????AND PARENT_OBJECT_ID = (SELECT OBJECT_ID
????FROM SYS.OBJECTS WITH(NOLOCK)
????WHERE NAME = @TB_NAME )
???????SELECT @NAME?????????????????????????????????????????????SQL?????п???????????SQL????:
????SELECT @NAME
????DECLARE @ALTERSQL NVARCHAR(MAX)
????SET @ALTERSQL=N'ALTER TABLE '+@TB_NAME+'
????DROP CONSTRAINT '+@NAME+"
????EXEC SP_EXECUTESQL @ALTERSQL
???????????SQL?????????????滻?±???????????????????????????????????????????????????????????????
?????????SQL???????TOP 1??????????????????????????????????????????????????????????????????????
??????????????п????????SQL Server 2000???????У?SQL Server 2000?е???????2005?????????????????????????
????????????????????????????????????
??????
???·???
??????????????????
2023/3/23 14:23:39???д?ò??????????
2023/3/22 16:17:39????????????????????Щ??
2022/6/14 16:14:27??????????????????????????
2021/10/18 15:37:44???????????????
2021/9/17 15:19:29???·???????·
2021/9/14 15:42:25?????????????
2021/5/28 17:25:47??????APP??????????
2021/5/8 17:01:11