增删改查,功能合集
ALTER TABLE [EPortal].[dbo].[dt_article_comment] ADD CATEGORY_TITLE nvarchar(100); //在sql server2012中 给创建的数据表,新增一个字段
参考:https://zhidao.baidu.com/question/617283599665857132.html
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
修改已经存在记录的表的字段的类型
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
delete from EPortal.dbo.dt_comment_fivestarsore where sore_level = 11; //在sql server2012中 删除一条记录
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
SQL server使用ALTER 语句修改字段名 不能直接修改 ①如果有数据,建议按下面方法执行 a.先建一个新的符号要求的字段 ALTER TABLE [EPortal].[dbo].[dt_article_comment] ADD category_title2 nvarchar(100); 公式:alter table table_name add new_field_name int; b.把老字段的值复制过来 update [EPortal].[dbo].[dt_article_comment] set category_title2 = CATEGORY_TITLE; 公式:update table_name set new_field_name = old_field_name; c.老字段删掉 alter table [EPortal].[dbo].[dt_article_comment] drop column CATEGORY_TITLE; 公式:alter table table_name drop column old_field_name;
参考:https://zhidao.baidu.com/question/1925197111996121187.html?qbl=relate_question_1&word=sql%20server%20%D0%DE%B8%C4%D7%D6%B6%CE%C3%FB%B3%C6%2Crename%BB%AE%BA%EC%CF%DF%2C%CC%E1%CA%BE%B8%BD%BD%FC%B4%ED%CE%F3
--------------------------------------------------------------------------------------------------------------------------------------
alter table [EPortal].[dbo].[dt_comment_fivestarsore] alter column sore_level nvarchar(500);//在sql server2012中 修改某个字段的类型
参考:https://www.cnblogs.com/xbq8080/p/6118207.html
-------------------------------------------------------------------------------------------------------------------------------------
INSERT INTO [EPortal].[dbo].[dt_fivestarsore] VALUES ('颜值', 0,1,getdate(),getdate()); //插入一条数据,获得当前时间 getdate() 日期类型 datetime
--------------------------------------------------------------------------------------------------------------------------------------
查看数据表中字段的类型,右键选中数据表,点击设计 即可
--------------------------------------------------------------------------------------------------------------------------------------
create table dt_fivestarsore( id int not null identity(1,1) primary key, --设置为主键和自增长列,起始值为1,每次自增1 kinds nvarchar(100) not null, status int )
在SQL server中创建数据表
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
SQL Server2012 列名显示无效
在SQLServer2012中,当设计(修改)表结构之后,再用SQL语句时,列名会显示无效,但执行可以通过
原因是SQL Server的intellisense(智能感知功能)需要重新整理一下,用快捷键Ctrl+Shift+R即可
参考:https://blog.csdn.net/bigheadsheep/article/details/7872299