zoukankan      html  css  js  c++  java
  • sql server2000创建表和修改表

    USE ClassNorthwind

    IF OBJECT_ID('dbo.Employees'IS NOT NULL
        
    DROP TABLE dbo.Employees
    **检验是否已存在该表
    GO

    CREATE TABLE dbo.Employees (
     EmployeeID 
    int IDENTITY (11NOT NULL ,
     LastName 
    nvarchar (20NOT NULL ,
     FirstName 
    nvarchar (10NOT NULL ,
     Title 
    nvarchar (30NULL ,
     TitleOfCourtesy 
    nvarchar (25NULL ,
     BirthDate 
    datetime NULL ,
     HireDate 
    datetime NULL ,
     Address 
    nvarchar (60NULL ,
     City city ,
    **用户自定义数据类型
     Region region ,
     PostalCode postalcode ,
     Country country ,
     HomePhone 
    nvarchar (24NULL ,
     Extension 
    nvarchar (4NULL ,
     Photo 
    image NULL ,
     Notes 
    ntext NULL ,
     ReportsTo 
    int NULL ,
     PhotoPath 
    nvarchar (255NULL 
    ON [PRIMARY]
    GO

    /* Display results */

    SELECT table_name
      
    FROM information_schema.tables
      
    WHERE table_name = 'Employees'
    GO

    修改表:

    /*添加列
     Add a column called Age to the Employees table in the ClassNorthwind database.
    */


    USE ClassNorthwind

    ALTER TABLE Employees
      
    ADD Age tinyint NULL
    go

    /* Display results */

    exec sp_help Employees

    GO
    /*修改
    Creates user defined data types.
    Drop existing versions first.
    */


    USE ClassNorthwind

    IF EXISTS (SELECT domain_name FROM information_schema.domains
               
    WHERE domain_schema = 'dbo' AND domain_name = 'city')
        
    EXEC  sp_droptype  city

    IF EXISTS (SELECT domain_name FROM information_schema.domains
               
    WHERE domain_schema = 'dbo' AND domain_name = 'region')
        
    EXEC  sp_droptype  region

    IF EXISTS (SELECT domain_name FROM information_schema.domains
               
    WHERE domain_schema = 'dbo' AND domain_name = 'country')
        
    EXEC  sp_droptype  country
    GO

    EXEC  sp_addtype  city, 'nvarchar(15)'NULL
    EXEC  sp_addtype  region, 'nvarchar(15)'NULL
    EXEC  sp_addtype  country, 'nvarchar(15)'NULL
    GO

    /* Display results */

    SELECT domain_name
       
    FROM information_schema.domains
       
    ORDER BY domain_name
    GO
    /*删除列
    Drop column called Age from the Employees table in the 
    ClassNorthwind database.
    */


    USE ClassNorthwind

    ALTER TABLE Employees
      
    DROP COLUMN age
    go

    /* Display results */

    EXEC sp_help Employees

    GO


  • 相关阅读:
    如何将jar包加入到Maven本地仓库
    dubbo 常见错误
    关于spring”通配符的匹配很全面, 但无法找到元素 'context:component-scan' 的声明“的错误
    Maven类包冲突终极三大解决技巧 mvn dependency:tree
    springMVC传对象参数
    scp 对拷文件夹 和 文件夹下的所有文件 对拷文件并重命名
    CATALINA_BASE与CATALINA_HOME的区别
    有return的情况下try catch finally的执行顺序(最有说服力的总结)
    Slf4j MDC 使用和 基于 Logback 的实现分析
    Docker 系列01: Centos7.3 上安装docker
  • 原文地址:https://www.cnblogs.com/heimirror/p/1223196.html
Copyright © 2011-2022 走看看