You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
47 lines
1.1 KiB
47 lines
1.1 KiB
|
|
|
|
IF EXISTS(SELECT 1 FROM MASTER..SYSOBJECTS WHERE NAME = 'PDropColumn' AND TYPE = 'P')
|
|
BEGIN
|
|
DROP PROC dbo.PDropColumn
|
|
END
|
|
GO
|
|
CREATE PROC dbo.PDropColumn
|
|
(
|
|
@table varchar(100),
|
|
@column varchar(100)
|
|
)
|
|
AS
|
|
BEGIN
|
|
|
|
DECLARE @Sql VARCHAR(2000)
|
|
-- DECLARE @Table VARCHAR(200)
|
|
-- DECLARE @Column VARCHAR(200)
|
|
|
|
-- SELECT @Table = 'TEmployee'
|
|
-- SELECT @Column = 'FGender'
|
|
|
|
SELECT @sql = ' ALTER TABLE ' + @Table + ' DROP CONSTRAINT ' + OBJECT_NAME(A.constid) + ''
|
|
FROM SYSCONSTRAINTS AS A ,syscolumns AS C
|
|
WHERE A.id = OBJECT_ID(@Table)
|
|
AND A.id = C.id
|
|
AND A.colid = C.colid
|
|
AND A.id = OBJECT_ID(@Table)
|
|
AND C.name = @Column
|
|
|
|
IF @@ROWCOUNT > 0
|
|
BEGIN
|
|
EXEC (@Sql)
|
|
PRINT @sql
|
|
END
|
|
|
|
SELECT @Sql = ' ALTER TABLE ' + @Table + ' DROP COLUMN ' + @Column
|
|
EXEC (@Sql)
|
|
END
|
|
GO
|
|
|
|
select 'EXEC PDropColumn ' + object_name(id) + ' , ' + name FROM syscolumns
|
|
WHERE Name IN( 'FMasterId','FId','FNo','FFromChild','FCourseId','FPayTypeId','FItemId','FMemId','FPayTypeId','FEmpId','FCardId','FCardTypeId','FGoodsId','FUnitId')
|
|
|
|
|
|
DROP TABLE TInventory
|
|
|
|
|