How can we change the name and data type of a column of a table?

sp_rename

Changes the name of the user object in the current database. This object can be a table, index, column, and alias data type, or a user defined type of the CLR Microsoft.NET Framework.

sp_rename[ @objname = ] 'object_name', [ @newname = ] 'new_name'

[, [ @objtype = ] 'object_type' ]

[ @objname = ] 'object_name'
The current full or partial name of a custom object or data type. If the object, which should be renamed, represents a column in a table, the name of the object_name should be stated in the form of table.column or schema.table.column. If the object, which should be renamed, is an index, the name of the object_name should have the following form table.index or schema.table.index.
Quotation marks are necessary only if the specified object with the full name. If given the full name of the table, including the name of the database as of the last must be the name of the current database. The argument object_name is nvarchar(776) and has no default value.
[ @newname = ] 'new_name'
The new name for the specified object. Name new_name should be monopropellant and comply with the rules for identifiers. The argument newname is a type of RAS and has no default value.

 

 

What are the differences between drop a table and truncate a table?

Drop and Truncate are DDL, With Drop Command we can remove entire Table or columns from database. With Truncate we can remove the records in the table by keeping table structure.

DROP
1. DROP is a DDL statement.
2. Removes a table from the database. Table structures, indexes, privileges, constraints will
also be removed.
3. Cannot be rolled back
4. No Triggers will be fired.
SYNTAX: DROP TABLE table_name

TRUNCATE
1. TRUNCATE is a DDL Statement.
2. Removes all rows from a table, but the table structures and its columns, constraints, indexes
remains.
3. Cannot be rolled back
4. Resets the identity of the table
5. Truncate is faster and uses fewer system and transaction log than delete.
6. Cannot use TRUNCATE on a table referenced by a FOREIGN KEY constraint.
7. No Triggers will be fired.
8. Cannot use WHERE conditions

SYNTAX: TRUNCATE TABLE table_name

 

49)Explain MySQL optimization?
Optimization is a complicated task because it ultimately requires understanding of the whole system.
The most important part for getting a system fast is of course the basic design. You also need to know what kinds of things your system will be doing, and what your bottlenecks are.
The most common bottlenecks are:
Disk seeks. It takes time for the disk to find a piece of data. With modern disks in 1999, the mean time for this is usually lower than 10ms, so we can in theory do about 1000 seeks a second. This time improves slowly with new disks and is very hard to optimize for a single table. The way to optimize this is to spread the data on more than one disk. Disk reading/writing. When the disk is at the correct position we need to read the data. With modern disks in 1999, one disk delivers something like 10-20Mb/s. This is easier to optimize than seeks because you can read in parallel from multiple disks. CPU cycles. When we have the data in main memory (or if it already were there) we need to process it to get to our result. Having small tables compared to the memory is the most common limiting factor. But then, with small tables speed is usually not the problem.
Memory bandwidth. When the CPU needs more data than can fit in the CPU cache the main memory bandwidth becomes a bottleneck. This is an uncommon bottleneck for most systems, but one should be aware of it


Понравилась статья? Добавь ее в закладку (CTRL+D) и не забудь поделиться с друзьями:  



double arrow
Сейчас читают про: