首页 > 代码库 > SQL SERVER 建库,表,索引,约束

SQL SERVER 建库,表,索引,约束

CREATE DATABASE Test
GO
USE Test
GO
CREATE TABLE UserInfo
(
	Id INT  IDENTITY PRIMARY KEY,
	Name VARCHAR(20),
	Age INT ,
	Sex BIT,
	Address VARCHAR(200)
)
GO
ALTER TABLE dbo.UserInfo ADD Phone VARCHAR(11)
ALTER TABLE dbo.UserInfo ADD CONSTRAINT age_c CHECK (Age>0 AND Age<200)
CREATE NONCLUSTERED INDEX name_index ON dbo.UserInfo(Name)
ALTER TABLE dbo.UserInfo ADD CONSTRAINT name_fk FOREIGN KEY(Name) REFERENCES CC(Name)

  

SQL SERVER 建库,表,索引,约束