SQL对数据库的操作(增删查改)

详情可以戳这里
<pre><code>se sales -------指定数据库
select*fromT_user -------查询表



drop tableT_user ---删除表

alter table T_user add pwd int null --为表添加一个pwd列

alter table T_user drop column pwd --删除表的pwd列

alter table T_user add pwd int default(123456) with values --为表添加一个pwd列,列的默认值为
--删除有默认值的列:先删除约束(默认值)alter table T_user DROP CONSTRAINT alter table T_userDROP


CONSTRAINT DF__T_user__pwd__2E1BDC42,然后在删除列alter table T_user DROP COLUMN pwd
alter table T_user DROP CONSTRAINT DF__T_user__pwd__2E1BDC42
alter table T_user DROP COLUMN pwd


alter table T_user alter column name nvarchar (10) --将name的数据类型修改为nvarchar类型

delete From T_user --------删除表的所有信息
delete T_user where name='张三' ----删除


update T_user set age= 24 where name = '王二小' ------更新

insert into T_user (name,age,pwd) values ('王五',20,1234566) ------插入


insert into T_user (name,age,pwd) output inserted.id values ('王五',20,1234566) --在values前面添加output inserted.id可以查询当前插入行的id

------添加主键
Alter table T_user add primarykey (id)

----??不会删除主键

exec sp_helpconstraint N't_user' ---查询主键,约束

select @@VERSION as SQLServer版本 --可以查询SQLServer版本


---为数据库sales添加文件xscjbak
alter databasesales add file (name=xscjbak, filename ='d:\sql\xscjbak.ndf',size=5MB,maxsize=50mb,filegrowth=5%)
--修改文件属性,将数据库sales中为xscj_data的文件名的maxsize属性修改为unlimited.注意每次只能修改这个文件名的一个属性
alter database sales modify file (name=xscj_data,maxsize=unlimited)
--修改文件属性,将数据库sales中为xscj_data的文件名的filegrowth属性修改为%
alter database sales modify file (name=xscj_data,filegrowth=5%)

alter database sales modify name=new_name ---将数据库sales改名为new_name

drop database sales----删除数据库</code></pre>
Here is an example of AppleScript: tell application "Foo" beep end tell
Here is an example of AppleScript: tell application "Foo" beep end tell

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容