sql server2000-建立表和修改表

來源:互聯網
上載者:User

 

USE ClassNorthwind

IF OBJECT_ID('dbo.Employees') IS NOT NULL
    DROP TABLE dbo.Employees
**檢驗是否已存在該表
GO

CREATE TABLE dbo.Employees (
 EmployeeID int IDENTITY (1, 1) NOT NULL ,
 LastName nvarchar (20) NOT NULL ,
 FirstName nvarchar (10) NOT NULL ,
 Title nvarchar (30) NULL ,
 TitleOfCourtesy nvarchar (25) NULL ,
 BirthDate datetime NULL ,
 HireDate datetime NULL ,
 Address nvarchar (60) NULL ,
 City city ,**使用者自訂資料類型
 Region region ,
 PostalCode postalcode ,
 Country country ,
 HomePhone nvarchar (24) NULL ,
 Extension nvarchar (4) NULL ,
 Photo image NULL ,
 Notes ntext NULL ,
 ReportsTo int NULL ,
 PhotoPath nvarchar (255) NULL 
) 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

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.