search
HomeDatabaseMysql TutorialBasics of SQL Data Operations (Elementary) 5

Create a new table using SQL Transaction Manager

You can create a new table using the methods described in the previous sections. However, it is easier to create new tables using a transaction manager. This section describes how to use this program to create new tables.

SQL from taskbar Select SQL EnterPRise in the Sever program group Manager, start the program and you will see the window shown in Figure 10.4. Browse the tree structure in the Service Manager window and select the folder named Database. After opening the folder Database, select the database you created in Chapter 3.

Note:

If you haven’t created your own database yet, go back to Chapter 3 to create it. You should never add data to master, tempdb or any other system database.

After selecting the database, you will see a folder named Group/users and a folder named objects. Open the folder objects and you will see many folders, one of which is named Tables. Right click on the folder Tables and select New table, the window shown in Figure 10.5 will appear.

You can use the Manager Tables window to create a new table. Manager The Tables window has 7 columns: Key, Column, Name, Datatype, Size, Nulls and Default. Manager Each row in the Tables window identifies information about a field in the table.

Figure 10.4

10.5

To create a new table, you must enter at least one row of information. In the column named Type mycolumn under the Name column. Next, select the Datatype column and select CHAR from the drop-down list. After you enter information in these two columns, the window will look like Figure 10.6.

Figure 10.6

You have created a simple table with only one field. Click the Save button to save this new table. When you are asked to enter a name for the new table, enter mytable and click OK. The table is now saved to your database.

If you open the Tables folder in the Service Manager window, you will see the new tables you created listed. You can double-click the table's chart to edit it, and the Manager The Tables window will reappear and you can add new fields and save again.

Any work that can be done with the SQL transaction manager can be done with SQL statements. However, the transaction manager makes the table creation process much simpler.

Add data to a table

The next chapter will discuss how to insert data into a table using SQL. However, if you need to add many records to a table, it is very inconvenient to use SQL statements to enter data. Fortunately, Microsoft SQL Server comes with a client application called Microsoft Query that makes it easy to add data to tables.

Start SQL located on the taskbar Microsoft Query program in the Sever program group. Select File|New Query from the menu at the top of the window. A Select Data will be displayed. Source dialog box (see Figure 10.7). Select your data source name and click Use.

Figure 10. 7

After entering your login account and password, the program asks you to select a table and a database. Select the table you created in the previous section (mytable ), click the button Add and then click the button Close to close the dialog box.

A dialog box will appear in the upper left corner of the window. In the box is a column of field names taken from the table mytable. You can double-click any field to add it to the main window. If you double-click the asterisk (*) character, all fields will be added to the main window.

If you have records in your table, they now appear under the field headings in the main window. However, because you just created the table, the table is still empty. To add a new record, select Records|Allow Editing, a new record will appear in the main window. Entering a row of data to complete the record adds a new record to the table.

Figure 10. 8

When you go to the next new record, the value you entered in the previous record will be automatically saved. If you need, you can use Microsoft Query Enter a few hundred records into the table.

Deleting and Modifying Tables

You should design tables carefully before creating them, because you will be severely limited in changing an existing table. For example, once you have created a table, you cannot delete fields in the table or change the data type of the fields. All you can do in this situation is drop the table and start over (see the "Creating Records and Tables Using SQL" section in Chapter 11, "Intermediate SQL").

To delete a table, you can use the SQL statement DROP TABLE. For example, to completely delete the table mytable from the database, you would use the following statement:

DROP TABLE mytable

WARNING:

USE DROP Be careful when using the TABLE command. Once a table is deleted, you cannot restore it.

When you build a site, you will most likely need to enter test data into the database. And when you're ready to make your site available to the world, you'll want to clear the table of this testing information. If you want to clear all data in a table without deleting the table, you can use TRUNCATE TABLE statement. For example, the following SQL statement deletes all data from the table mytable:

TRUNCATE TABLE mytable

Although you cannot delete or modify existing fields, you can add new fields. The easiest way to achieve this is to use the Manager in SQL Transaction Manager Tables window. You can also use the SQL statement ALTER TABLE. Here is an example of how to use this statement:

ALTER TABLE mytable ADD mynewcolumnINT NULL

This statement adds a new field mynewcolumn to the table mytable. When you add a new field, you must allow it to accept null values ​​because there may already be many records in the table.

Summary

This chapter introduced you to SQL. Using SQL, you can operate Microsoft SQL Server database. You have learned to use the SELECT statement to retrieve data from the database, and you have also learned how to use CREATE TABLE statement and SQL transaction manager to create new tables. Finally, you learned how to specify a series of important field properties.

The next chapter will introduce how to use indexes to enhance the operation of SQL queries. Your SQL knowledge will be further expanded through many other SQL statements and functions.


The above is the content of SQL Data Operation Basics (Elementary) 5. For more related articles, please pay attention to the PHP Chinese website (www.php.cn)!


Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
What Are the Limitations of Using Views in MySQL?What Are the Limitations of Using Views in MySQL?May 14, 2025 am 12:10 AM

MySQLviewshavelimitations:1)Theydon'tsupportallSQLoperations,restrictingdatamanipulationthroughviewswithjoinsorsubqueries.2)Theycanimpactperformance,especiallywithcomplexqueriesorlargedatasets.3)Viewsdon'tstoredata,potentiallyleadingtooutdatedinforma

Securing Your MySQL Database: Adding Users and Granting PrivilegesSecuring Your MySQL Database: Adding Users and Granting PrivilegesMay 14, 2025 am 12:09 AM

ProperusermanagementinMySQLiscrucialforenhancingsecurityandensuringefficientdatabaseoperation.1)UseCREATEUSERtoaddusers,specifyingconnectionsourcewith@'localhost'or@'%'.2)GrantspecificprivilegeswithGRANT,usingleastprivilegeprincipletominimizerisks.3)

What Factors Influence the Number of Triggers I Can Use in MySQL?What Factors Influence the Number of Triggers I Can Use in MySQL?May 14, 2025 am 12:08 AM

MySQLdoesn'timposeahardlimitontriggers,butpracticalfactorsdeterminetheireffectiveuse:1)Serverconfigurationimpactstriggermanagement;2)Complextriggersincreasesystemload;3)Largertablesslowtriggerperformance;4)Highconcurrencycancausetriggercontention;5)M

MySQL: Is it safe to store BLOB?MySQL: Is it safe to store BLOB?May 14, 2025 am 12:07 AM

Yes,it'ssafetostoreBLOBdatainMySQL,butconsiderthesefactors:1)StorageSpace:BLOBscanconsumesignificantspace,potentiallyincreasingcostsandslowingperformance.2)Performance:LargerrowsizesduetoBLOBsmayslowdownqueries.3)BackupandRecovery:Theseprocessescanbe

MySQL: Adding a user through a PHP web interfaceMySQL: Adding a user through a PHP web interfaceMay 14, 2025 am 12:04 AM

Adding MySQL users through the PHP web interface can use MySQLi extensions. The steps are as follows: 1. Connect to the MySQL database and use the MySQLi extension. 2. Create a user, use the CREATEUSER statement, and use the PASSWORD() function to encrypt the password. 3. Prevent SQL injection and use the mysqli_real_escape_string() function to process user input. 4. Assign permissions to new users and use the GRANT statement.

MySQL: BLOB and other no-sql storage, what are the differences?MySQL: BLOB and other no-sql storage, what are the differences?May 13, 2025 am 12:14 AM

MySQL'sBLOBissuitableforstoringbinarydatawithinarelationaldatabase,whileNoSQLoptionslikeMongoDB,Redis,andCassandraofferflexible,scalablesolutionsforunstructureddata.BLOBissimplerbutcanslowdownperformancewithlargedata;NoSQLprovidesbetterscalabilityand

MySQL Add User: Syntax, Options, and Security Best PracticesMySQL Add User: Syntax, Options, and Security Best PracticesMay 13, 2025 am 12:12 AM

ToaddauserinMySQL,use:CREATEUSER'username'@'host'IDENTIFIEDBY'password';Here'showtodoitsecurely:1)Choosethehostcarefullytocontrolaccess.2)SetresourcelimitswithoptionslikeMAX_QUERIES_PER_HOUR.3)Usestrong,uniquepasswords.4)EnforceSSL/TLSconnectionswith

MySQL: How to avoid String Data Types common mistakes?MySQL: How to avoid String Data Types common mistakes?May 13, 2025 am 12:09 AM

ToavoidcommonmistakeswithstringdatatypesinMySQL,understandstringtypenuances,choosetherighttype,andmanageencodingandcollationsettingseffectively.1)UseCHARforfixed-lengthstrings,VARCHARforvariable-length,andTEXT/BLOBforlargerdata.2)Setcorrectcharacters

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Safe Exam Browser

Safe Exam Browser

Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

DVWA

DVWA

Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software