Insert fields in all SQL data tables

Source: Internet
Author: User

DECLARE @tablename varchar (200)
DECLARE @sql varchar (2000)
DECLARE cur_t cursor FOR
Select name from sysobjects where xtype= ' U ' and status> =0 and name is not in (select name from sysobjects where ID in ( Select ID from syscolumns
where ID in (select id from sysobjects where type= ' U ')
and Name= ' Createtime '))
Open cur_t
FETCH NEXT from cur_t to @tablename
While @ @FETCH_STATUS = 0
Begin
Set @sql = ' ALTER TABLE ' + @tablename + ' Add createtime datetime '
EXEC (@sql)
FETCH NEXT from cur_t to @tablename
End
Close cur_t
Deallocate cur_t

Above is the Insert Createtime field in all Tables without createtime field, add other fields to modify Createtime


Select name from sysobjects where ID in (SELECT ID from syscolumns
where ID in (select id from sysobjects where type= ' U ')
and Name= ' Createtime ')

Querying for table names with createtime fields in all tables in the database

Select id from sysobjects where type= ' U '

Query all table IDs change the ID to name to find out all the table names

Insert fields in all SQL data tables

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.