Search
 
SCRIPT & CODE EXAMPLE
 

SQL

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>
Comment

PREVIOUS NEXT
Code Example
Sql :: mysql group concat 
Sql :: phone number regex sql 
Sql :: difference between normalization and denormalization 
Sql :: how to import mysql database command line 
Sql :: redo files log oracle 
Sql :: oracle privileges users 
Sql :: sql compiler online 
Sql :: execut sql python 
Sql :: add primary key to database sql 
Sql :: oracle lock user 
Sql :: 2nd highest value in sql 
Sql :: sql pivot without aggregate 
Sql :: php5-mysql has no installation candidate 
Sql :: what is relational database 
Sql :: how to open mysql in docker 
Sql :: rebuild index sql server 
Sql :: Mysql table variables 
Sql :: SQL Server run query on linked server 
Sql :: update row postgres 
Sql :: group_concat mysql 
Sql :: partition-by 
Sql :: sql vs nosql 
Sql :: mysql workbench format date 
Sql :: ORACLE CALL BACK TRACE 
Sql :: disable module odoo 
Sql :: how to limited number of rows in db2 select * from imglib FETCH FIRST 20 ROWS ONLY 
Sql :: alter in sql 
Sql :: mysql update from n to 100 
Sql :: triggers in mysql example 
Sql :: check constraint in ms sql 
ADD CONTENT
Topic
Content
Source link
Name
8+1 =