微前端架构如何改变企业的开发模式与效率提升
206
2024-01-05
小编给大家分享一下sqlserver的表、视图、索引如何实现创建、修改、删除操作,相信大部分人都还不怎么了解,因此分享这篇文章给大家参考一下,希望大家阅读完这篇文章后大有收获,下面让我们一起去了解一下吧!
一、表相关
1、创建
USE [test] GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE TABLE [dbo].[Ceshi]( [id] [int] NOT NULL, [name] [varchar(30)] NULL, CONSTRAINT[PK_Ceshi] PRIMARYKEY CLUSTERED ( [id] ASC )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY =OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY] ) ON [PRIMARY] GO --添加字段注释 EXEC sys.sp_addextendedproperty @name=NMS_Description, @value=N主键一个 , @level0type=NSCHEMA,@level0name=Ndbo, @level1type=NTABLE,@level1name=NCeshi, @level2type=NCOLUMN,@level2name=Nid GO --修改字段注释EXEC sys.sp_updateextendedproperty @name=NMS_Description, @value=N主键一个 , @level0type=NSCHEMA,@level0name=Ndbo, @level1type=NTABLE,@level1name=NCeshi, @level2type=NCOLUMN,@level2name=Nid GO2、修改
(1)修改表名:
EXECsp_renametable_name, table_new_name(2)新增字段:
ALTER TABLE table_name ADD column_name datatype(3)修改字段名:
EXECsp_rename表名.column_name,new_column_name,column(4)修改字段类型:
ALTER TABLE table_name ALTER COLUMNcolumn_name datatype(5)删除字段:
ALTER TABLE table_name DROP COLUMN column_name3、删除
DROP TABLE `test`;二、视图相关
1、创建
USE [test] GO SETANSI_NULLSON GO SET QUOTED_IDENTIFIER ON GO --注释卸载这儿 CREATE VIEW view_name AS SELECT column_name(s) FROM table_name WHERE condition GO2、修改
ALTER VIEW view_name AS SELECT * FROM ceshi;3、删除
DROP VIEW view_name三、索引相关
1、创建
(1)在表上创建一个简单的索引
USE [test] GO CREATE NONCLUSTERED INDEX index_name ON table_name ( column_name ASC, column_name2DESC )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING =OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY] GO(2)在表上创建一个唯一的索引
USE [test] GO CREATE CLUSTERED INDEX index_name ON table_name ( column_name ASC )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE =OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS =ON) ON [PRIMARY] GO2、删除
USE [test] GO DROP INDEX index_name ON table_name WITH ( ONLINE = OFF ) GO以上是“sqlserver的表、视图、索引如何实现创建、修改、删除操作”这篇文章的所有内容,感谢各位的阅读!相信大家都有了一定的了解,希望分享的内容对大家有所帮助,如果还想学习更多知识,欢迎关注行业资讯频道!
版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。
发表评论
暂时没有评论,来抢沙发吧~