exec sp_help tablename
MySQL:
Describe tablename;
SELECT COUNT( * ) FROM information_schema.tables WHERE table_schema = 'MyDBName' AND table_name = 'MyTableName';
SELECT count( * ) FROM information_schema.columns WHERE table_schema = 'MyDBName' AND Table_Name = 'MyTableName' AND column_Name = 'MyColumnName';
CREATE TABLE IF NOT EXISTS tablename ( ... );
DROP TABLE IF EXISTS tablename;
delimiter '//' ;
create procedure DropColumnIfExists(
IN dbName tinytext,
IN tableName tinytext,
IN fieldName tinytext)
begin
IF EXISTS (
SELECT * FROM information_schema.COLUMNS
WHERE column_name=fieldName
and table_name=tableName
and table_schema=dbName
)
THEN
set @ddl=CONCAT('ALTER TABLE ',dbName,'.',tableName,
' DROP ',fieldName);
prepare stmt from @ddl;
execute stmt;
END IF;
end;
//
delimiter ';' ;
Have a question about something in this article? You can receive help directly from the article author. Sign up for a free trial to get started.
Comments (0)