Danh mục

Mysql your visual blueprint for creating open source databases- P6

Số trang: 20      Loại file: pdf      Dung lượng: 630.86 KB      Lượt xem: 12      Lượt tải: 0    
Thư viện của tui

Xem trước 2 trang đầu tiên của tài liệu này:

Thông tin tài liệu:

Mysql your visual blueprint for creating open source databases- P6:The show tables command displays a list of tables available in the currently selected database. You can use this command when you are unsure of the exact name of a table within the database.
Nội dung trích xuất từ tài liệu:
Mysql your visual blueprint for creating open source databases- P6 ADD AND DELETE DATA 4 The mail table was created in Chapter 2 and modified in Chapter 3. If you have not created this table and its primary key, you can simply use this CREATE TABLE statement to create the table: Example: CREATE TABLE mail ( name VARCHAR(80) PRIMARY KEY, address VARCHAR(120), city VARCHAR(50), state CHAR(2), postal VARCHAR(5) ); This command creates the mail table and specifies its five columns. The name column is defined as the primary key. Because the primary key always requires unique values, the REPLACE command will replace any existing row with the same value in the name field as the row you are adding. If you use REPLACE on a table that does not include a primary key or unique index, no rows are ever replaced because the table allows duplicate values for any of its columns. In this case, the REPLACE command is equivalent to INSERT.› Type REPLACE INTO mail s This completes the Á Type SELECT * FROM mail; s The rows of the table are(name, address) and press REPLACE query. and press Enter. displayed. Because the rowEnter. was replaced, only one row Note: Because the row you added is present.ˇ Type VALUES (Samuel with REPLACE has the same nameJohnson, 3394 Willow Ave.); as the previous one, it replaces theand press Enter. other row you added. 87 MySQLINSERT ROWS FROM ANOTHER TABLE With this syntax, all of the columns will be copied if thereO ften, the data you want to add to a table is already listed in another table. You can use the SELECT is a column with the same name in the destination table. If keyword with INSERT to copy one or more rows a column does not exist in the destination table, the otherfrom one table to another. For example, the following query columns are still copied and a warning message is displayed.copies data from the address table to the mail table: If the source and destination tables have a column ofINSERT INTO mail (name, address) different types, MySQL will convert the data wherever SELECT name, address FROM address; possible. Some column values may be truncated when you copy them to a column with a smaller field length.In this example, all of the rows of the address table arecopied. The name and address fields are copied to their If any of the selected rows in the source table have thecorresponding fields for each row. In this case the field same value for a primary key or unique index as an existingnames are the same, but any fields can be used. If the field row in the destination table, MySQL will return an error.names for two tables are the same, you can use a wildcard You can specify the IGNORE option to ignore this error andto copy all of the fields: continue copying. In this case, only the rows that are not present in the destination table are copied.INSERT INTO mail SELECT * FROM address; INSERT ROWS FROM ANOTHER TABLENote: This example uses the mail ⁄ From the MySQL monitor, ¤ Type INSERT INTO mail s The MySQL monitorand address tables in the testdb type USE testdb; and press (name, address) and press prompts for the next line.database. Enter. Enter. ...

Tài liệu được xem nhiều: