sql drop default
Removes a default value for a column.
Example (MySQL): Removes the default value from the ‘name’ column in
the ‘products’ table.
ALTER TABLE products
ALTER COLUMN name DROP DEFAULT;
sql drop default
Removes a default value for a column.
Example (MySQL): Removes the default value from the ‘name’ column in
the ‘products’ table.
ALTER TABLE products
ALTER COLUMN name DROP DEFAULT;
sql script to remove default from column
DECLARE @tableName VARCHAR(MAX) = '<MYTABLENAME>'
DECLARE @columnName VARCHAR(MAX) = '<MYCOLUMNAME>'
DECLARE @ConstraintName nvarchar(200)
SELECT @ConstraintName = Name
FROM SYS.DEFAULT_CONSTRAINTS
WHERE PARENT_OBJECT_ID = OBJECT_ID(@tableName)
AND PARENT_COLUMN_ID = (
SELECT column_id FROM sys.columns
WHERE NAME = @columnName AND object_id = OBJECT_ID(@tableName))
IF @ConstraintName IS NOT NULL
EXEC('ALTER TABLE '+@tableName+' DROP CONSTRAINT ' + @ConstraintName)
-- Just replace <MYTABLENAME> and <MYCOLUMNNAME>
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us