1. How to back up and restore SQL databases in ASP!
Answer: asp online backup SQL server database:
1. Backup
<%
SQL = "backup database name to disk = '" & Server. MapPath ("backup") & "\" & "backuptext. dat "&"'"
Set cnn = Server. createobject ("adodb. connection ")
Cnn. open "driver = {SQL Server}; Server = Server name; uid = sa; pwd ="
Cnn.exe cute SQL
On error resume next
If err <> 0 then
Response. write "error:" & err. Descripting
Else
Response. write "Data Backup successful! "
End if
%>
2. Recovery
<%
SQL = "Restore database name from disk = '" & Server. MapPath ("backup") & "\" & "backuptext. dat "&"'"
Set cnn = Server. createobject ("adodb. connection ")
Cnn. open "driver = {SQL Server}; Server = Server name; uid = sa; pwd ="
Cnn.exe cute SQL
On error resume next
If err <> 0 then
Response. write "error:" & err. Descripting
Else
Response. write "data recovery successful! "
End if
%>
Note: The preceding statement backs up data to the backup directory of the disk. The file name is backuptext. dat.
2. Can I modify the SQL database structure in ASP?
A: ALTER TABLE
Name
Alter table-Modify TABLE attributes
Syntax
Alter table table [*]
ADD [COLUMN] column type
Alter table table [*]
ALTER [COLUMN] column {set default value | drop default}
Alter table table [*]
RENAME [COLUMN] column TO newcolumn
Alter table table
Rename to newtable
Alter table table
ADD table constraint definition
Inputs
Table
Name of the existing table to be modified.
Column
Existing or new column names.
Type
The type of the new column.
Newcolumn
New name of the existing column.
Newtable
The new name of the table.
Table constraint definition
The new constraint definition of the table.
New table constraint for the table
Output
ALTER
Information returned from the renamed column or table.
ERROR
Information returned if a column or table does not exist.
Description
Alter table changes the definition of an existing TABLE. add column to ADD a new COLUMN/field to the TABLE using the same syntax as create table. Alter column allows you to set or delete the default value from the COLUMN/field ). Note that the default value is only valid for newly inserted rows. The RENAME clause can change the name of a table or column/field without affecting any data in the relevant table. Therefore, the table or column/field will be of the same size and type after this command is executed. The ADD table constraint definition clause adds a new constraint to the TABLE using the same syntax as CREATE table.
To change the attributes of a table, you must be the table owner.
Note:
The COLUMN keyword is redundant and can be omitted.
If "*" is followed by a table name, this command is used to operate the table and all tables with lower inheritance levels than the table. If this command is missing, this attribute (changed) does not add any sub-tables or modify the names of any sub-tables. This is always the case when you add or modify the attributes of a parent table (: a table with a higher inheritance level. Otherwise, the following queries are performed at the inheritance level.
SELECT NewColumn FROM SuperClass *
It will not work, because the sub-table will have one attribute less than the upper-level table.
In the current implementation, the default (value) and constraint clause of the new column/field are ignored. You can then SET the DEFAULT value in the set default form of alter table ). (You have to use UPDATE to UPDATE existing rows to the default value .)
In the current implementation, only the foreign key constraint can be added to the table. to CREATE or delete a unique constraint, you can CREATE a unique INDEX (see create index ). to add check constraints, you need to recreate and reload the TABLE. The parameters used are other parameters of the create table command.
To modify the table structure, you must be the owner of the table. You cannot change any part of the system table structure. The PostgreSQL User Manual contains more information about inheritance.
Please refer to the create table section for more valid parameter descriptions.
Usage
Add a VARCHAR column to the table:
Alter table distributors add column address VARCHAR (30 );
Rename existing columns:
Alter table distributors rename column address TO city;
Rename an existing table:
Alter table distributors rename to suppliers;
Add a foreign key constraint to the table:
Alter table distributors add constraint distfk foreign key (address) REFERENCES addresses (address) MATCH FULL
Compatibility
The SQL92ADD COLUMN format is compatible, except the default values and constraints mentioned above. The alter column format is fully compatible.
SQL92 declares some additional features not directly supported by S for alter table:
Alter table table drop constraint constraint {RESTRICT | CASCADE}
Add or delete table constraints (such as check constraints, unique constraints, or foreign key constraints ). To CREATE or delete a unique constraint, CREATE or delete a unique index. To modify other types of constraints, you need to recreate and reload the TABLE and use other parameters of the create table command.
For example, to delete any constraints of the distributors table:
Create table temp as select * FROM distributors;
Drop table distributors;
Create table distributors as select * FROM temp;
Drop table temp;
Alter table table DROP [COLUMN] column {RESTRICT | CASCADE}
To delete an existing column, the table must be re-created and reloaded:
Create table temp as select did, city FROM distributors;
Drop table distributors;
Create table distributors (
Did DECIMAL (3) DEFAULT 1,
Name VARCHAR (40) not null,
);
Insert into distributors SELECT * FROM temp;
Drop table temp;
The rename column/field and table name are PostgreSQL extensions. SQL92 does not provide these.