在看SQL


创建表
create table test1 (
[id] [int] IDENTITY(1,1) NOT NULL, 
[name] [varchar](50) COLLATE Chinese_PRC_CI_AS NOT NULL
)

COLLATE Chinese_PRC_CI_AS(COLLATE对字符进行排序)

所以创建表也可以写成
create table test2 (
[id] [int] IDENTITY(1,1) NOT NULL, 
[name] [varchar](50)   NOT NULL
)

删除表
DROP TABLE test2

查询表
select * from test1

增加字段
alter table test1 add [content] [varchar](50)   default 0
alter table test1 add [cc] [varchar](50)   

删除字段
alter table [test1] drop column  cc



创建视图
方法一
CREATE VIEW test_View_1
AS
SELECT     id AS id_v, name AS name_v, content AS content_v
FROM         test1

方法二
CREATE VIEW test_View_2
AS
SELECT    dbo.test1.*
FROM         test1



为两个表创建视图
CREATE VIEW [dbo].[View_3]
AS
SELECT     dbo.test1.id, dbo.test2.id AS Expr1, dbo.test1.name, dbo.test1.content, dbo.test2.name AS Expr2
FROM         dbo.test1 INNER JOIN
                      dbo.test2 ON dbo.test1.id = dbo.test2.id

删除视图
DROP VIEW test_View_2

你可能感兴趣的:(sql)