当前位置:网站首页>SQL Server(2)

SQL Server(2)

2022-07-05 17:29:00 Game programming

1. Create modification table ( Do not delete the original table , Make changes )

Add new column :alter table tb_student add Gender bit null
Delete old columns :alter table tb_student drop column Gender
Change column names :alter table tb_student alter column Gender bit null
Change column names : exec sp_rename 'tb_student.ClassNo','No','Column'

2. Create constraints

( Do not delete the original table , Create constraints )
alter table Table name add constraint PK_tb_student primary key ( Name )
alter table Table name add constraint FK_ Table name foreign key ( Name 1) references surface 2 name ( Name 2)
alter table Table name add constraint UK_ Table name _ Name unique( Name 1, Name 2)
alter table Table name add constraint CK_ Table name _ Name check( Conditional expression )
alter table Table name add constraint DK_ Table name default(0)for Name

3. insert data

A single piece of data is listed
insert (into) Table name ( Name 1, Name 2)values ( value 1, value 2,...)
insert (into) Table name ( Name 1, Name 2)select value 1, value 2....
union( be used for select Concatenation of insert statements )union all Allowing repetition is efficient
Multiple data listed
insert (into) Table name ( Name 1, Name 2)values ( value 1, value 2,...),( value 3, value 4,...),( value 5, value 6,...)
Clone data ( Copy data from one table to another )
1):insert Target table ( Name 1)select Name 2 from The original table
2):select Name 2 into surface 1 from surface 2

4. Update data

update Table name set Name 1= value where Name 2= value
( If not where Words , The data of the whole table has been modified )

5. Delete data

1):delete from Table name where Name = value
( Cause the value of the identification column to be discontinuous )
2):truncate table Table name ( Table data is cleared , Restore to initialization , The identity column is also restored )
truncate Efficient than delete high ,delete No data is deleted , Will be recorded in the log ,
,truncate No logging , Do not activate the trigger ,drop truncate It's instant operation
author : Late boat •

Game programming , A game development favorite ~

If the picture is not displayed for a long time , Please use Chrome Kernel browser .

原网站

版权声明
本文为[Game programming]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/186/202207051659471345.html