Drop databases, tables and constraints

   Drop databases, tables, constraints.
To delete a database, you must first query whether there is a database you want to delete.
  Example:
if(exists(select * from sysdatabases where name='deleted database name'))
drop database database name To

delete tables and constraints, you should first (use database name), and then change sysdatabases to

sysobjectsExample : Delete the student table
MySchool in the MySchool database MySchool use MySchool
  if (select * from sysobjects where name='student')
    drop table student
Delete constraints: You must first ALTER TABLE table name, and then you can delete constraints.
   Example: delete the pk_studentNo constraint in the student table
if(exists(select * from sysobjects where name='pk_studentNo'))
ALTER TABLE student
drop constraint pk_studentNo

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326655300&siteId=291194637