您好,欢迎来到知库网。
搜索
您的当前位置:首页SQL对数据库的操作(增删查改)

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

来源:知库网


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

Copyright © 2019- zicool.com 版权所有 湘ICP备2023022495号-2

违法及侵权请联系:TEL:199 1889 7713 E-MAIL:2724546146@qq.com

本站由北京市万商天勤律师事务所王兴未律师提供法律服务